changeset 27876:602add6ad9e5

copies: fix detection of divergent directory renames If we move all the files out of one directory, but into two different directories, we should not consider it a directory rename. The detection of this case was broken.
author Matt Mackall <mpm@selenic.com>
date Wed, 13 Jan 2016 10:10:05 -0600
parents add2ba16430e
children f6d1e92fdf8c
files mercurial/copies.py tests/test-rename-dir-merge.t
diffstat 2 files changed, 64 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/copies.py	Fri Jan 15 13:14:49 2016 -0800
+++ b/mercurial/copies.py	Wed Jan 13 10:10:05 2016 -0600
@@ -401,13 +401,13 @@
             continue
         elif dsrc in d1 and ddst in d1:
             # directory wasn't entirely moved locally
-            invalid.add(dsrc)
+            invalid.add(dsrc + "/")
         elif dsrc in d2 and ddst in d2:
             # directory wasn't entirely moved remotely
-            invalid.add(dsrc)
-        elif dsrc in dirmove and dirmove[dsrc] != ddst:
+            invalid.add(dsrc + "/")
+        elif dsrc + "/" in dirmove and dirmove[dsrc + "/"] != ddst + "/":
             # files from the same directory moved to two different places
-            invalid.add(dsrc)
+            invalid.add(dsrc + "/")
         else:
             # looks good so far
             dirmove[dsrc + "/"] = ddst + "/"
--- a/tests/test-rename-dir-merge.t	Fri Jan 15 13:14:49 2016 -0800
+++ b/tests/test-rename-dir-merge.t	Wed Jan 13 10:10:05 2016 -0600
@@ -231,3 +231,63 @@
   R a/f
 
   $ cd ..
+
+Test renames to separate directories
+
+  $ hg init a
+  $ cd a
+  $ mkdir a
+  $ touch a/s
+  $ touch a/t
+  $ hg ci -Am0
+  adding a/s
+  adding a/t
+
+Add more files
+
+  $ touch a/s2
+  $ touch a/t2
+  $ hg ci -Am1
+  adding a/s2
+  adding a/t2
+
+Do moves on a branch
+
+  $ hg up 0
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ mkdir s
+  $ mkdir t
+  $ hg mv a/s s
+  $ hg mv a/t t
+  $ hg ci -Am2
+  created new head
+  $ hg st --copies --change .
+  A s/s
+    a/s
+  A t/t
+    a/t
+  R a/s
+  R a/t
+
+Merge shouldn't move s2, t2
+
+  $ hg merge
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg st --copies
+  M a/s2
+  M a/t2
+
+Try the merge in the other direction. It may or may not be appropriate for
+status to list copies here.
+
+  $ hg up -C 1
+  4 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ hg merge
+  2 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg st --copies
+  M s/s
+  M t/t
+  R a/s
+  R a/t