diff --git a/mercurial/configitems.py b/mercurial/configitems.py --- a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -1601,6 +1601,14 @@ coreconfigitem( experimental=True, ) coreconfigitem( + b'partial-merge-tools', + br'.*\.args', + default=b"$local $base $other", + generic=True, + priority=-1, + experimental=True, +) +coreconfigitem( b'merge-tools', b'.*', default=None, diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py --- a/mercurial/filemerge.py +++ b/mercurial/filemerge.py @@ -1119,7 +1119,7 @@ def filemerge(repo, wctx, mynode, orig, def _run_partial_resolution_tools(repo, local, other, base): """Runs partial-resolution tools on the three inputs and updates them.""" ui = repo.ui - # Tuples of (order, name, executable path) + # Tuples of (order, name, executable path, args) tools = [] seen = set() section = b"partial-merge-tools" @@ -1135,7 +1135,8 @@ def _run_partial_resolution_tools(repo, if is_match: order = ui.configint(section, b'%s.order' % name, 0) executable = ui.config(section, b'%s.executable' % name, name) - tools.append((order, name, executable)) + args = ui.config(section, b'%s.args' % name) + tools.append((order, name, executable, args)) if not tools: return @@ -1151,11 +1152,21 @@ def _run_partial_resolution_tools(repo, with _maketempfiles(files) as temppaths: localpath, basepath, otherpath = temppaths - for order, name, executable in tools: + for order, name, executable, args in tools: cmd = procutil.shellquote(executable) - # TODO: Allow the user to configure the command line using - # $local, $base, $other. - cmd = b'%s %s %s %s' % (cmd, localpath, basepath, otherpath) + replace = { + b'local': localpath, + b'base': basepath, + b'other': otherpath, + } + args = util.interpolate( + br'\$', + replace, + args, + lambda s: procutil.shellquote(util.localpath(s)), + ) + + cmd = b'%s %s' % (cmd, args) r = ui.system(cmd, cwd=repo.root, blockedtag=b'partial-mergetool') if r: raise error.StateError( diff --git a/tests/test-merge-partial-tool.t b/tests/test-merge-partial-tool.t --- a/tests/test-merge-partial-tool.t +++ b/tests/test-merge-partial-tool.t @@ -207,3 +207,35 @@ merge the rest, then the regular merge t c d e3 + +Test that arguments get passed as expected. + + $ cat >> "$TESTTMP/log-args.sh" <<'EOF' + > #!/bin/sh + > echo "$@" > args.log + > EOF + $ chmod +x "$TESTTMP/log-args.sh" + $ cat >> "$HGRCPATH" < [partial-merge-tools] + > log-args.executable=$TESTTMP/log-args.sh + > EOF + $ hg up -C 2 + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg merge 1 + merging file + warning: conflicts while merging file! (edit, then use 'hg resolve --mark') + 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] + $ cat args.log + */hgmerge-*/file~local */hgmerge-*/file~base */hgmerge-*/file~other (glob) + $ hg up -C 2 + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg merge 1 --config partial-merge-tools.log-args.args='--other $other $base --foo --local $local --also-other $other' + merging file + warning: conflicts while merging file! (edit, then use 'hg resolve --mark') + 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] + $ cat args.log + --other */hgmerge-*/file~other */hgmerge-*/file~base --foo --local */hgmerge-*/file~local --also-other */hgmerge-*/file~other (glob)