changeset 16283:6c4dbe28dda3 stable

rename: handle case-changing (issue1717)
author Matt Mackall <mpm@selenic.com>
date Fri, 23 Mar 2012 11:47:27 -0500
parents 50247a7a9983
children e53c0b2d7b60 38a36dc5a34e
files mercurial/cmdutil.py
diffstat 1 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Thu Mar 22 23:58:47 2012 +0900
+++ b/mercurial/cmdutil.py	Fri Mar 23 11:47:27 2012 -0500
@@ -285,6 +285,16 @@
 
         # check for overwrites
         exists = os.path.lexists(target)
+        samefile = False
+        if exists and abssrc != abstarget:
+            if (repo.dirstate.normalize(abssrc) ==
+                repo.dirstate.normalize(abstarget)):
+                if not rename:
+                    ui.warn(_("%s: can't copy - same file\n") % reltarget)
+                    return
+                exists = False
+                samefile = True
+
         if not after and exists or after and state in 'mn':
             if not opts['force']:
                 ui.warn(_('%s: not overwriting - file exists\n') %
@@ -307,7 +317,12 @@
                 targetdir = os.path.dirname(target) or '.'
                 if not os.path.isdir(targetdir):
                     os.makedirs(targetdir)
-                util.copyfile(src, target)
+                if samefile:
+                    tmp = target + "~hgrename"
+                    os.rename(src, tmp)
+                    os.rename(tmp, target)
+                else:
+                    util.copyfile(src, target)
                 srcexists = True
             except IOError, inst:
                 if inst.errno == errno.ENOENT:
@@ -330,7 +345,7 @@
         scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget,
                              dryrun=dryrun, cwd=cwd)
         if rename and not dryrun:
-            if not after and srcexists:
+            if not after and srcexists and not samefile:
                 util.unlinkpath(repo.wjoin(abssrc))
             wctx.forget([abssrc])