# HG changeset patch # User Pierre-Yves David # Date 1425322860 0 # Node ID ac41aa4a66ab21210fc538e9fb51c405a341b69e # Parent aae338f9da70ffcbf9e19ac247339e9caf50f210 amend: check for directory renames for both merge parents (issue4516) Before this change, amending a merge would lose 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 parent. This seems to fix the bug and does not show other issues from the test suite. diff -r aae338f9da70 -r ac41aa4a66ab mercurial/cmdutil.py --- a/mercurial/cmdutil.py Mon Mar 02 10:29:45 2015 -0600 +++ b/mercurial/cmdutil.py Mon Mar 02 19:01:00 2015 +0000 @@ -2281,6 +2281,8 @@ 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, diff -r aae338f9da70 -r ac41aa4a66ab tests/test-commit-amend.t --- a/tests/test-commit-amend.t Mon Mar 02 10:29:45 2015 -0600 +++ b/tests/test-commit-amend.t Mon Mar 02 19:01:00 2015 +0000 @@ -1057,3 +1057,66 @@ 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 +