[PATCH stable, v2] update: don't clobber untracked files with wrong casing

Mads Kiilerich mads at kiilerich.com
Wed Nov 16 19:25:25 CST 2011


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1321492545 -3600
# Branch stable
# Node ID 062afbb2ba6829bd6ba995da85774e52c51c0c7e
# Parent  6eff984d8e76811f1ce129a424236abf0afaa191
update: don't clobber untracked files with wrong casing

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -81,10 +81,18 @@
             self.mark(dfile, 'r')
         return r
 
-def _checkunknown(wctx, mctx):
+def _checkunknown(wctx, mctx, folding):
     "check for collisions between unknown files and files in mctx"
-    for f in wctx.unknown():
-        if f in mctx and mctx[f].cmp(wctx[f]):
+    if folding:
+        foldf = encoding.lower
+    else:
+        foldf = lambda fn: fn
+    folded = {}
+    for fn in mctx:
+        folded[foldf(fn)] = fn
+    for fn in wctx.unknown():
+        f = foldf(fn)
+        if f in folded and mctx[folded[f]].cmp(wctx[f]):
             raise util.Abort(_("untracked file in working directory differs"
                                " from file in requested revision: '%s'") % f)
 
@@ -537,9 +545,10 @@
         ### calculate phase
         action = []
         wc.status(unknown=True) # prime cache
+        folding = not util.checkcase(repo.path)
         if not force:
-            _checkunknown(wc, p2)
-        if not util.checkcase(repo.path):
+            _checkunknown(wc, p2, folding)
+        if folding:
             _checkcollision(p2)
         action += _forgetremoved(wc, p2, branchmerge)
         action += manifestmerge(repo, wc, p2, pa, overwrite, partial)
diff --git a/tests/test-casefolding.t b/tests/test-casefolding.t
--- a/tests/test-casefolding.t
+++ b/tests/test-casefolding.t
@@ -1,5 +1,8 @@
   $ "$TESTDIR/hghave" icasefs || exit 80
 
+  $ hg debugfs | grep 'case-sensitive:'
+  case-sensitive: no
+
 test file addition with bad case
 
   $ hg init repo1
@@ -56,4 +59,16 @@
   1 files updated, 0 files merged, 1 files removed, 0 files unresolved
   $ hg up -C
   1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+
+no clobbering of untracked files with wrong casing
+
+  $ hg up -r null
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo gold > a
+  $ hg up
+  abort: untracked file in working directory differs from file in requested revision: 'a'
+  [255]
+  $ cat a
+  gold
+
   $ cd ..


More information about the Mercurial-devel mailing list