[PATCH] filemerge: use util.shellquote when calling merge program (issue3581)

Keegan Carruthers-Smith keegancsmith at fb.com
Tue Oct 30 16:20:00 CDT 2012


# HG changeset patch
# User Keegan Carruthers-Smith <keegancsmith at fb.com>
# Date 1351278178 25200
# Branch stable
# Node ID 6fd3a8ceb8efdb1780318c55a37504c6c2cecd06
# Parent  7b0b1da49f15c2aa20a8e7abe8fa1be26191e4fb
filemerge: use util.shellquote when calling merge program (issue3581)

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -72,7 +72,7 @@
     if force:
         toolpath = _findtool(ui, force)
         if toolpath:
-            return (force, '"' + toolpath + '"')
+            return (force, util.shellquote(toolpath))
         else:
             # mimic HGMERGE if given tool not found
             return (force, force)
@@ -87,7 +87,7 @@
         mf = match.match(repo.root, '', [pat])
         if mf(path) and check(tool, pat, symlink, False):
             toolpath = _findtool(ui, tool)
-            return (tool, '"' + toolpath + '"')
+            return (tool, util.shellquote(toolpath))
 
     # then merge tools
     tools = {}
@@ -106,7 +106,7 @@
     for p, t in tools:
         if check(t, None, symlink, binary):
             toolpath = _findtool(ui, t)
-            return (t, '"' + toolpath + '"')
+            return (t, util.shellquote(toolpath))
 
     # internal merge or prompt as last resort
     if symlink or binary:
@@ -255,7 +255,7 @@
             out, a = a, back # read input from backup, write to original
         replace = dict(local=a, base=b, other=c, output=out)
         args = util.interpolate(r'\$', replace, args,
-                                lambda s: '"%s"' % util.localpath(s))
+                                lambda s: util.shellquote(util.localpath(s)))
         r = util.system(toolpath + ' ' + args, cwd=repo.root, environ=env,
                         out=ui.fout)
         return True, r
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
@@ -773,6 +773,30 @@
   # hg stat
   M f
 
+Issue3581: Merging a filename that needs to be quoted
+
+  $ beforemerge
+  [merge-tools]
+  false.whatever=
+  true.priority=1
+  true.executable=cat
+  # hg update -C 1
+  $ echo "revision 4" > '"; exit 1; echo "'
+  $ hg commit -Am "revision 4"
+  adding "; exit 1; echo "
+  warning: filename contains '"', which is reserved on Windows: '"; exit 1; echo "'
+  $ hg update -C 1 > /dev/null
+  $ echo "revision 5" > '"; exit 1; echo "'
+  $ hg commit -Am "revision 5"
+  adding "; exit 1; echo "
+  warning: filename contains '"', which is reserved on Windows: '"; exit 1; echo "'
+  created new head
+  $ hg merge --config merge-tools.true.executable="true" -r 4
+  merging "; exit 1; echo "
+  0 files updated, 1 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg update -C 1 > /dev/null
+
 Merge post-processing
 
 cat is a bad merge-tool and doesn't change:


More information about the Mercurial-devel mailing list