# HG changeset patch # User Robin Farine # Date 1131474913 28800 # Node ID faf46d810a85737b934fb5037388c74ecd1812e0 # Parent 5c3b93b244aa1938fbac3dfbe5d0ca5a077720cc avoid to copy more than one file to the same destination file diff -r 5c3b93b244aa -r faf46d810a85 mercurial/commands.py --- a/mercurial/commands.py Tue Nov 08 10:35:09 2005 -0800 +++ b/mercurial/commands.py Tue Nov 08 10:35:13 2005 -0800 @@ -790,6 +790,7 @@ cwd = repo.getcwd() errors = 0 copied = [] + targets = {} def okaytocopy(abs, rel, exact): reasons = {'?': _('is not managed'), @@ -803,7 +804,12 @@ def copy(abssrc, relsrc, target, exact): abstarget = util.canonpath(repo.root, cwd, target) reltarget = util.pathto(cwd, abstarget) - if os.path.exists(reltarget): + prevsrc = targets.get(abstarget) + if prevsrc is not None: + ui.warn(_('%s: not overwriting - %s collides with %s\n') % + (reltarget, abssrc, prevsrc)) + return + elif os.path.exists(reltarget): if opts['force']: os.unlink(reltarget) else: @@ -829,6 +835,7 @@ (relsrc, inst.strerror)) errors += 1 return + targets[abstarget] = abssrc repo.copy(abssrc, abstarget) copied.append((abssrc, relsrc, exact)) diff -r 5c3b93b244aa -r faf46d810a85 tests/test-rename --- a/tests/test-rename Tue Nov 08 10:35:09 2005 -0800 +++ b/tests/test-rename Tue Nov 08 10:35:13 2005 -0800 @@ -76,3 +76,9 @@ hg rename --force d1/ba d1/ca hg status hg update -C + +echo "# do not copy more than one source file to the same destination file" +mkdir d3 +hg rename d1/* d2/* d3 +hg status +hg update -C diff -r 5c3b93b244aa -r faf46d810a85 tests/test-rename.out --- a/tests/test-rename.out Tue Nov 08 10:35:09 2005 -0800 +++ b/tests/test-rename.out Tue Nov 08 10:35:13 2005 -0800 @@ -101,3 +101,15 @@ # replace a symlink with a file A d1/ca R d1/ba +# do not copy more than one source file to the same destination file +copying d1/d11/a1 to d3/d11/a1 +d3/b: not overwriting - d2/b collides with d1/b +removing d1/d11/a1 +A d3/a +A d3/b +A d3/ba +A d3/d11/a1 +R d1/a +R d1/b +R d1/ba +R d1/d11/a1