[PATCH stable] amend: check for directory renames for both merge parents (issue4516)

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Mar 2 19:24:50 UTC 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1425322860 0
#      Mon Mar 02 19:01:00 2015 +0000
# Branch stable
# Node ID 08f97fbae223ca1dec392861829cc3f4f4651c32
# Parent  aae338f9da70ffcbf9e19ac247339e9caf50f210
amend: check for directory renames for both merge parents (issue4516)

Before this change, amending a merge would loose the rename information for file
adding in the second parents and implicitly renamed into a new directory.

In case of the merge, we also look for directory rename data from the second
parents. This seems to fix the bug and does not show other issue from the test
suite.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2279,10 +2279,12 @@ def amend(ui, repo, commitfunc, old, ext
 
                 user = ctx.user()
                 date = ctx.date()
                 # Recompute copies (avoid recording a -> b -> a)
                 copied = copies.pathcopies(base, ctx)
+                if old.p2:
+                    copied.update(copies.pathcopies(old.p2(), ctx))
 
                 # Prune files which were reverted by the updates: if old
                 # introduced file X and our intermediate commit, node,
                 # renamed that file, then those two files are the same and
                 # we can discard X from our list of files. Likewise if X
diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
--- a/tests/test-commit-amend.t
+++ b/tests/test-commit-amend.t
@@ -1055,5 +1055,68 @@ which was not far enough back in this ca
 Before the fix, the copy information was lost.
   $ hg status --copies --rev 0
   A a2
     a0
   R a0
+  $ cd ..
+
+Check that amend properly preserve rename from directory rename (issue-4516)
+
+If a parent of the merge renames a full directory, any files added to the old
+directory in the other parent will be renamed to the new directory. For some
+reason, the rename metadata was when amending such merge. This test ensure we
+do not regress. We have a dedicated repo because it needs a setup with renamed
+directory)
+
+  $ hg init issue4516
+  $ cd issue4516
+  $ mkdir olddirname
+  $ echo line1 > olddirname/commonfile.py
+  $ hg add olddirname/commonfile.py
+  $ hg ci -m first
+
+  $ hg branch newdirname
+  marked working directory as branch newdirname
+  (branches are permanent and global, did you want a bookmark?)
+  $ hg mv olddirname newdirname
+  moving olddirname/commonfile.py to newdirname/commonfile.py (glob)
+  $ hg ci -m rename
+
+  $ hg update default
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo line1 > olddirname/newfile.py
+  $ hg add olddirname/newfile.py
+  $ hg ci -m log
+
+  $ hg up newdirname
+  1 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ # create newdirname/newfile.py
+  $ hg merge default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg ci -m add
+  $ 
+  $ hg debugrename newdirname/newfile.py
+  newdirname/newfile.py renamed from olddirname/newfile.py:690b295714aed510803d3020da9c70fca8336def
+  $ hg status -C --change .
+  A newdirname/newfile.py
+  $ hg status -C --rev 1
+  A newdirname/newfile.py
+  $ hg status -C --rev 2
+  A newdirname/commonfile.py
+    olddirname/commonfile.py
+  A newdirname/newfile.py
+    olddirname/newfile.py
+  R olddirname/commonfile.py
+  R olddirname/newfile.py
+  $ hg debugindex newdirname/newfile.py
+     rev    offset  length   base linkrev nodeid       p1           p2
+       0         0      88      0       3 34a4d536c0c0 000000000000 000000000000
+
+  $ echo a >> newdirname/commonfile.py
+  $ hg ci --amend -m bug
+  $ hg debugrename newdirname/newfile.py
+  newdirname/newfile.py renamed from olddirname/newfile.py:690b295714aed510803d3020da9c70fca8336def
+  $ hg debugindex newdirname/newfile.py
+     rev    offset  length   base linkrev nodeid       p1           p2
+       0         0      88      0       3 34a4d536c0c0 000000000000 000000000000
+


More information about the Mercurial-devel mailing list