[PATCH] merge: expand environment variables and ~/ in tool.executable

Greg Ward greg at gerg.ca
Wed Oct 12 20:56:23 CDT 2011


# HG changeset patch
# User Greg Ward <greg at gerg.ca>
# Date 1318470358 14400
# Node ID 72400acb2d76b81fd6f0f873054309b95a1a62b8
# Parent  af15a79d808dffe2d4e5804fe74dc87612021995
merge: expand environment variables and ~/ in tool.executable

hgrc(5) already implies that this works, so we might as well support it.

Another approach would be to implement this in util.findexe(): that
would benefit other callers of findexe(), e.g. convert and anyone
calling the user's editor. But findexe() is really implemented in
both posix.py and windows.py, so this would make both of those modules
depend on util.py: not good. So keep it narrow and only for merge
tools.

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -34,7 +34,8 @@
             p = util.findexe(p + _toolstr(ui, tool, "regappend"))
             if p:
                 return p
-    return util.findexe(_toolstr(ui, tool, "executable", tool))
+    exe = _toolstr(ui, tool, "executable", tool)
+    return util.findexe(util.expandpath(exe))
 
 def _picktool(repo, ui, path, binary, symlink):
     def check(tool, pat, symlink, binary):
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
@@ -261,6 +261,29 @@
   
   $ echo
   
+environment variables in true.executable are handled
+  $ cat > $HGTMP/merge.sh <<EOF
+  > #!/bin/sh
+  > echo 'custom merge tool'
+  > EOF
+  $ chmod +x $HGTMP/merge.sh
+  $ domerge -r 2 --config merge-tools.true.executable='$HGTMP/merge.sh'
+  [merge-tools]
+  false.whatever=
+  true.priority=1
+  true.executable=cat
+  # hg update -C 1
+  # hg merge -r 2 --config merge-tools.true.executable=$HGTMP/merge.sh
+  merging f
+  custom merge tool
+  0 files updated, 1 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  # cat f
+  revision 1
+  space
+  # hg stat
+  M f
+  
 
 Tool selection and merge-patterns
 


More information about the Mercurial-devel mailing list