# HG changeset patch # User Matt Mackall # Date 1332521247 18000 # Node ID 6c4dbe28dda39cc3866d4e0e22bb1af0d1d3e94a # Parent 50247a7a998394b2ef94f206caffb0adf5c5b2a2 rename: handle case-changing (issue1717) diff -r 50247a7a9983 -r 6c4dbe28dda3 mercurial/cmdutil.py --- 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])