[PATCH] rename: detect and prevent false file deletion on case mangling systems (issue910)

Adrian Buehlmann adrian at cadifra.com
Thu Apr 17 17:32:39 CDT 2008


(http://www.selenic.com/mercurial/bts/issue910)

I would propose to detect this case, warn the user and reject -- until
we get the ultimate case mangling solution (tm).

Can we do it with the patch below?

Tests ran on FreeBSD 6.2, Python 2.5.1:

Skipped test-convert-baz: missing feature: GNU Arch baz client
Skipped test-convert-darcs: missing feature: darcs client
Skipped test-convert-mtn: missing feature: monotone client (> 0.31)
Skipped test-highlight: missing feature: Pygments source highlighting library
Skipped test-imerge: not executable
Skipped test-no-symlinks: system supports symbolic links
Failed test-mq: output changed
# Ran 255 tests, 6 skipped, 1 failed.

(test-mq is just a minor unrelated problem with the test itself,
 occuring after 3182602fa1fb as noted on issue1087)

# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1208454571 -7200
# Node ID c4fe61d66a64d3d2eeb9d65f10e196f56dfaf4a6
# Parent  550c53d6694947b3ab205c93933d5dabca61c8ad
rename: detect and prevent false file deletion on case mangling systems (issue910)

Reject "rename --after a.txt A.txt" on case mangling systems (e.g. Windows).
The current implementation of hg rename is unable to handle this case.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -336,6 +336,15 @@
         target = repo.wjoin(abstarget)
         src = repo.wjoin(abssrc)
         state = repo.dirstate[abstarget]
+
+        if rename and after:
+            # reject "rename --after a.txt A.txt" on case mangling systems (issue910)
+            nsrc = os.path.normcase(src)
+            ntarget = os.path.normcase(target)
+            if ntarget == nsrc:
+                ui.warn(_('cannot record rename of %s to %s\n') %
+                       (repo.pathto(abssrc, cwd), repo.pathto(abstarget, cwd)))
+                return

         # check for collisions
         prevsrc = targets.get(abstarget)




More information about the Mercurial-devel mailing list