# HG changeset patch # User FUJIWARA Katsunori # Date 2018-08-15 13:24:38 # Node ID 6618634e332532ea0241a3204d34520f17e2a160 # Parent 4d7b11877dd019df29323efc1ee1e0daf340aa75 filemerge: show warning if chosen tool has no binary files capability While matching patterns in "merge-patterns" configuration, Mercurial silently assumes that all merge tools have binary files capability. This implementation comes from 5af5f0f9d724 (or Mercurial 1.0). At failure of merging binary files with incorrect internal merge tool, there is no hint about this silent ignorance of binary files capability. This patch shows warning message, if chosen internal merge tool has no binary files capability. This will help users to investigate why a binary file isn't merged as expected. diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py --- a/mercurial/filemerge.py +++ b/mercurial/filemerge.py @@ -195,6 +195,12 @@ def _picktool(repo, ui, path, binary, sy for pat, tool in ui.configitems("merge-patterns"): mf = match.match(repo.root, '', [pat]) if mf(path) and check(tool, pat, symlink, False, changedelete): + if binary and not hascapability(tool, "binary", strict=True): + ui.warn(_("warning: check merge-patterns configurations," + " if %r for binary file %r is unintentional\n" + "(see 'hg help merge-tools'" + " for binary files capability)\n") + % (pycompat.bytestr(tool), pycompat.bytestr(path))) toolpath = _findtool(ui, tool) return (tool, _quotetoolpath(toolpath)) diff --git a/tests/test-merge-tools.t b/tests/test-merge-tools.t --- a/tests/test-merge-tools.t +++ b/tests/test-merge-tools.t @@ -1805,6 +1805,41 @@ Verify naming of temporary files and tha 0 files updated, 1 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) +Binary files capability checking + + $ hg update -q -C 0 + $ python < with open('b', 'wb') as fp: + > fp.write(b'\x00\x01\x02\x03') + > EOF + $ hg add b + $ hg commit -qm "add binary file (#1)" + + $ hg update -q -C 0 + $ python < with open('b', 'wb') as fp: + > fp.write(b'\x03\x02\x01\x00') + > EOF + $ hg add b + $ hg commit -qm "add binary file (#2)" + +By default, binary files capability of internal merge tools is not +checked strictly. + +(for merge-patterns, chosen unintentionally) + + $ hg merge 9 \ + > --config merge-patterns.b=:merge-other \ + > --config merge-patterns.re:[a-z]=:other + warning: check merge-patterns configurations, if ':merge-other' for binary file 'b' is unintentional + (see 'hg help merge-tools' for binary files capability) + merging b + warning: b looks like a binary file. + 0 files updated, 0 files merged, 0 files removed, 1 files unresolved + use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon + [1] + $ hg merge --abort -q + Check that debugpicktool examines which merge tool is chosen for specified file as expected @@ -1836,9 +1871,9 @@ specified file as expected (-r REV causes checking files in specified revision) - $ hg manifest -r tip + $ hg manifest -r 8 f.txt - $ hg debugpickmergetool -r tip + $ hg debugpickmergetool -r 8 f.txt = true #if symlink