tests: add more tests of copy tracing with removed and re-added files
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 21 Jun 2019 16:59:29 -0700
changeset 42590 ab416b5d9b91
parent 42589 67bf11597eb8
child 42591 bcb4b5c5964b
tests: add more tests of copy tracing with removed and re-added files We had a test where the destination of a copy was removed and then added back. This patch adds similar cases where the break in history instead happens to the source file. There are three versions of this: 1. The break happens before the rename. 2. The break happens on a branch parallel to the rename (where copy tracing is done via the merge base) 3. The source is added on each side of the merge base. The break in history is thus in the form of a deletion when going backwards to the merge base and the re-add happens on the other branch. I've also added calls to `hg graft` in these cases to show the breakage in issue 6163. Another factor in these cases is matching nodeid (checked in copies._tracefile()). I've made two copies each of the cases to show the impact of that. One of these is the same as a test in test-rename-merge1.t, so I also deleted that test from there. Some of these tests currently fail, where "fail" is based on my current thinking of how things should work. I had initially thought that we should be more strict about not tracing copies across commits where the file did not exist, but issue 6163 made me reconsider. The only test case here that behaved differently in 4.9 is the exact case reported in issue 6163. Differential Revision: https://phab.mercurial-scm.org/D6599
tests/test-copies-unrelated.t
tests/test-rename-merge1.t
--- a/tests/test-copies-unrelated.t	Mon Jul 01 14:24:51 2019 -0700
+++ b/tests/test-copies-unrelated.t	Fri Jun 21 16:59:29 2019 -0700
@@ -34,48 +34,336 @@
   $ newrepo
   $ echo x > x
   $ hg ci -Aqm 'add x'
+  $ echo x2 > x
+  $ hg ci -m 'modify x'
+  $ hg co -q 0
   $ hg cp x y
-  $ hg ci -m 'copy x to y'
+  $ hg ci -qm 'copy x to y'
   $ hg rm y
   $ hg ci -m 'remove y'
   $ hg cp -f x y
   $ hg ci -m 'copy x onto y (again)'
   $ hg l
-  @  3 copy x onto y (again)
+  @  4 copy x onto y (again)
+  |  y
+  o  3 remove y
   |  y
-  o  2 remove y
+  o  2 copy x to y
   |  y
-  o  1 copy x to y
-  |  y
+  | o  1 modify x
+  |/   x
   o  0 add x
      x
-  $ hg debugp1copies -r 3
+  $ hg debugp1copies -r 4
   x -> y
-  $ hg debugpathcopies 0 3
+  $ hg debugpathcopies 0 4
   x -> y
+  $ hg graft -r 1
+  grafting 1:* "modify x" (glob)
+  merging y and x to y
+  $ hg co -qC 1
+  $ hg graft -r 4
+  grafting 4:* "copy x onto y (again)" (glob)
+  merging x and y to y
 
-Copy x to y, then remove y, then add back y. With copy metadata in the changeset, this could easily
-end up reporting y as copied from x (if we don't unmark it as a copy when it's removed).
+Copy x to y, then remove y, then add back y. With copy metadata in the
+changeset, this could easily end up reporting y as copied from x (if we don't
+unmark it as a copy when it's removed). Despite x and y not being related, we
+want grafts to propagate across the rename.
   $ newrepo
   $ echo x > x
   $ hg ci -Aqm 'add x'
+  $ echo x2 > x
+  $ hg ci -m 'modify x'
+  $ hg co -q 0
   $ hg mv x y
-  $ hg ci -m 'rename x to y'
+  $ hg ci -qm 'rename x to y'
   $ hg rm y
   $ hg ci -qm 'remove y'
   $ echo x > y
   $ hg ci -Aqm 'add back y'
   $ hg l
-  @  3 add back y
+  @  4 add back y
+  |  y
+  o  3 remove y
   |  y
-  o  2 remove y
-  |  y
-  o  1 rename x to y
+  o  2 rename x to y
+  |  x y
+  | o  1 modify x
+  |/   x
+  o  0 add x
+     x
+  $ hg debugpathcopies 0 4
+BROKEN: This should succeed and merge the changes from x into y
+  $ hg graft -r 1
+  grafting 1:* "modify x" (glob)
+  file 'x' was deleted in local [local] but was modified in other [graft].
+  You can use (c)hanged version, leave (d)eleted, or leave (u)nresolved.
+  What do you want to do? u
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+Add x, remove it, then add it back, then rename x to y. Similar to the case
+above, but here the break in history is before the rename.
+  $ newrepo
+  $ echo x > x
+  $ hg ci -Aqm 'add x'
+  $ echo x2 > x
+  $ hg ci -m 'modify x'
+  $ hg co -q 0
+  $ hg rm x
+  $ hg ci -qm 'remove x'
+  $ echo x > x
+  $ hg ci -Aqm 'add x again'
+  $ hg mv x y
+  $ hg ci -m 'rename x to y'
+  $ hg l
+  @  4 rename x to y
   |  x y
+  o  3 add x again
+  |  x
+  o  2 remove x
+  |  x
+  | o  1 modify x
+  |/   x
+  o  0 add x
+     x
+  $ hg debugpathcopies 0 4
+  x -> y
+  $ hg graft -r 1
+  grafting 1:* "modify x" (glob)
+  merging y and x to y
+  $ hg co -qC 1
+  $ hg graft -r 4
+  grafting 4:* "rename x to y" (glob)
+  merging x and y to y
+
+Add x, modify it, remove it, then add it back, then rename x to y. Similar to
+the case above, but here the re-added file's nodeid is different from before
+the break.
+
+  $ newrepo
+  $ echo x > x
+  $ hg ci -Aqm 'add x'
+  $ echo x2 > x
+  $ hg ci -m 'modify x'
+  $ echo x3 > x
+  $ hg ci -qm 'modify x again'
+  $ hg co -q 1
+  $ hg rm x
+  $ hg ci -qm 'remove x'
+# Same content to avoid conflicts
+  $ hg revert -r 1 x
+  $ hg ci -Aqm 'add x again'
+  $ hg mv x y
+  $ hg ci -m 'rename x to y'
+  $ hg l
+  @  5 rename x to y
+  |  x y
+  o  4 add x again
+  |  x
+  o  3 remove x
+  |  x
+  | o  2 modify x again
+  |/   x
+  o  1 modify x
+  |  x
   o  0 add x
      x
-  $ hg debugp1copies -r 3
-  $ hg debugpathcopies 0 3
+  $ hg debugpathcopies 0 5
+  x -> y (no-filelog !)
+#if no-filelog
+  $ hg graft -r 2
+  grafting 2:* "modify x again" (glob)
+  merging y and x to y
+#else
+BROKEN: This should succeed and merge the changes from x into y
+  $ hg graft -r 2
+  grafting 2:* "modify x again" (glob)
+  file 'x' was deleted in local [local] but was modified in other [graft].
+  You can use (c)hanged version, leave (d)eleted, or leave (u)nresolved.
+  What do you want to do? u
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+#endif
+  $ hg co -qC 2
+BROKEN: This should succeed and merge the changes from x into y
+  $ hg graft -r 5
+  grafting 5:* "rename x to y"* (glob)
+  file 'x' was deleted in other [graft] but was modified in local [local].
+  You can use (c)hanged version, (d)elete, or leave (u)nresolved.
+  What do you want to do? u
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+Add x, remove it, then add it back, rename x to y from the first commit.
+Similar to the case above, but here the break in history is parallel to the
+rename.
+  $ newrepo
+  $ echo x > x
+  $ hg ci -Aqm 'add x'
+  $ hg rm x
+  $ hg ci -qm 'remove x'
+  $ echo x > x
+  $ hg ci -Aqm 'add x again'
+  $ echo x2 > x
+  $ hg ci -m 'modify x'
+  $ hg co -q 0
+  $ hg mv x y
+  $ hg ci -qm 'rename x to y'
+  $ hg l
+  @  4 rename x to y
+  |  x y
+  | o  3 modify x
+  | |  x
+  | o  2 add x again
+  | |  x
+  | o  1 remove x
+  |/   x
+  o  0 add x
+     x
+  $ hg debugpathcopies 2 4
+  x -> y
+  $ hg graft -r 3
+  grafting 3:* "modify x" (glob)
+  merging y and x to y
+  $ hg co -qC 3
+  $ hg graft -r 4
+  grafting 4:* "rename x to y" (glob)
+  merging x and y to y
+
+Add x, remove it, then add it back, rename x to y from the first commit.
+Similar to the case above, but here the re-added file's nodeid is different
+from the base.
+  $ newrepo
+  $ echo x > x
+  $ hg ci -Aqm 'add x'
+  $ hg rm x
+  $ hg ci -qm 'remove x'
+  $ echo x2 > x
+  $ hg ci -Aqm 'add x again with different content'
+  $ hg co -q 0
+  $ hg mv x y
+  $ hg ci -qm 'rename x to y'
+  $ hg l
+  @  3 rename x to y
+  |  x y
+  | o  2 add x again with different content
+  | |  x
+  | o  1 remove x
+  |/   x
+  o  0 add x
+     x
+  $ hg debugpathcopies 2 3
+  x -> y
+BROKEN: This should merge the changes from x into y
+  $ hg graft -r 2
+  grafting 2:* "add x again with different content" (glob)
+  $ hg co -qC 2
+BROKEN: This should succeed and merge the changes from x into y
+  $ hg graft -r 3
+  grafting 3:* "rename x to y" (glob)
+  file 'x' was deleted in other [graft] but was modified in local [local].
+  You can use (c)hanged version, (d)elete, or leave (u)nresolved.
+  What do you want to do? u
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+Add x on two branches, then rename x to y on one side. Similar to the case
+above, but here the break in history is via the base commit.
+  $ newrepo
+  $ echo a > a
+  $ hg ci -Aqm 'base'
+  $ echo x > x
+  $ hg ci -Aqm 'add x'
+  $ echo x2 > x
+  $ hg ci -m 'modify x'
+  $ hg co -q 0
+  $ echo x > x
+  $ hg ci -Aqm 'add x again'
+  $ hg mv x y
+  $ hg ci -qm 'rename x to y'
+  $ hg l
+  @  4 rename x to y
+  |  x y
+  o  3 add x again
+  |  x
+  | o  2 modify x
+  | |  x
+  | o  1 add x
+  |/   x
+  o  0 base
+     a
+  $ hg debugpathcopies 1 4
+BROKEN: This should succeed and merge the changes from x into y
+  $ hg graft -r 2
+  grafting 2:* "modify x" (glob)
+  file 'x' was deleted in local [local] but was modified in other [graft].
+  What do you want to do?
+  use (c)hanged version, leave (d)eleted, or leave (u)nresolved? u
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+  $ hg co -qC 2
+  $ hg graft -r 4
+  grafting 4:* "rename x to y"* (glob)
+  merging x and y to y
+
+Add x on two branches, with same content but different history, then rename x
+to y on one side. Similar to the case above, here the file's nodeid is
+different between the branches.
+  $ newrepo
+  $ echo a > a
+  $ hg ci -Aqm 'base'
+  $ echo x > x
+  $ hg ci -Aqm 'add x'
+  $ echo x2 > x
+  $ hg ci -m 'modify x'
+  $ hg co -q 0
+  $ touch x
+  $ hg ci -Aqm 'add empty x'
+# Same content to avoid conflicts
+  $ hg revert -r 1 x
+  $ hg ci -m 'modify x to match commit 1'
+  $ hg mv x y
+  $ hg ci -qm 'rename x to y'
+  $ hg l
+  @  5 rename x to y
+  |  x y
+  o  4 modify x to match commit 1
+  |  x
+  o  3 add empty x
+  |  x
+  | o  2 modify x
+  | |  x
+  | o  1 add x
+  |/   x
+  o  0 base
+     a
+  $ hg debugpathcopies 1 5
+BROKEN: This should succeed and merge the changes from x into y
+  $ hg graft -r 2
+  grafting 2:* "modify x" (glob)
+  file 'x' was deleted in local [local] but was modified in other [graft].
+  You can use (c)hanged version, leave (d)eleted, or leave (u)nresolved.
+  What do you want to do? u
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+  $ hg co -qC 2
+BROKEN: This should succeed and merge the changes from x into y
+  $ hg graft -r 5
+  grafting 5:* "rename x to y"* (glob)
+  file 'x' was deleted in other [graft] but was modified in local [local].
+  You can use (c)hanged version, (d)elete, or leave (u)nresolved.
+  What do you want to do? u
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
 
 Copies via null revision (there shouldn't be any)
   $ newrepo
@@ -95,3 +383,5 @@
      x
   $ hg debugpathcopies 1 2
   $ hg debugpathcopies 2 1
+  $ hg graft -r 1
+  grafting 1:* "copy x to y" (glob)
--- a/tests/test-rename-merge1.t	Mon Jul 01 14:24:51 2019 -0700
+++ b/tests/test-rename-merge1.t	Fri Jun 21 16:59:29 2019 -0700
@@ -184,52 +184,3 @@
   $ hg status
   M newfile
   $ cd ..
-
-Check that file is considered unrelated when deleted and recreated
-
-  $ hg init unrelated
-  $ cd unrelated
-  $ echo foo > file
-  $ hg add file
-  $ hg commit -m "added file"
-  $ hg cp file newfile
-  $ hg commit -m "copy file"
-  $ hg update 0
-  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
-  $ hg rm file
-  $ hg commit -m "deleted file"
-  created new head
-  $ echo bar > file
-  $ hg add file
-  $ hg ci -m 'recreate file'
-  $ hg log -G -T '{rev} {desc}\n'
-  @  3 recreate file
-  |
-  o  2 deleted file
-  |
-  | o  1 copy file
-  |/
-  o  0 added file
-  
-BROKEN: this is inconsistent with `hg merge` (below), which doesn't consider
-'file' renamed same since it was deleted for a while
-  $ hg st --copies --rev 3 --rev 1
-  M file
-  A newfile
-    file
-  $ hg merge --debug 1
-    unmatched files in other:
-     newfile
-    all copies found (* = to merge, ! = divergent, % = renamed and deleted):
-     src: 'file' -> dst: 'newfile' 
-    checking for directory renames
-  resolving manifests
-   branchmerge: True, force: False, partial: False
-   ancestor: 19d7f95df299, local: 4e4a42b1cbdf+, remote: 45b14aae7432
-   newfile: remote created -> g
-  getting newfile
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  (branch merge, don't forget to commit)
-  $ hg status
-  M newfile
-  $ cd ..