Bug 4405 - Rename info lost after second amend
Summary: Rename info lost after second amend
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: 3.0-rc
Hardware: PC Linux
: normal bug
Assignee: Ryan McElroy
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-13 17:01 UTC by Pierre-Yves David
Modified: 2015-01-22 15:04 UTC (History)
3 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pierre-Yves David 2014-10-13 17:01 UTC
Initiallyt reported on bitbucket by Gerg Ward



Rename + commit works fine, as ever. Amending that commit: no problem. Redo the rename ("oops, I wanted to call that file a2, not a1") and amend: problem. Rename info is lost. Here's a test script:

  setup test repo
    $ hg init
    $ cat >> .hg/hgrc <<EOF
    > [extensions]
    > rebase =
    > evolve = ~/src/hg-evolve/hgext/evolve.py
    > EOF
    $ echo a > a
    $ hg ci -A -m init
    adding a
  
  initial rename
    $ hg mv a a1
    $ hg st -C
    A a1
      a
    R a
    $ hg ci -m'rename (v1)'
  
  amend the rename (new commit message, no change to filenames or content)
    $ hg amend -m'rename (v2)'
    $ hg st -C --ch .
    A a1
      a
    R a
  
  redo the rename: instead of moving into d1, move into d2
    $ hg mv a1 a2
    $ hg pdiff --git
    diff --git a/a b/a2
    rename from a
    rename to a2
    $ hg amend -m'rename (v3)'
    $ hg st -C --ch .
    A a2
      a
    R a
  
This fails as follows:

  ERROR: /home/greg/src/hg-evolve/tests/test-rename.t output changed
  --- /home/greg/src/hg-evolve/tests/test-rename.t
  +++ /home/greg/src/hg-evolve/tests/test-rename.t.err
  @@ -33,5 +33,4 @@
     $ hg amend -m'rename (v3)'
     $ hg st -C --ch .
     A a2
  -    a
     R a
  !
  Failed test-rename.t: output changed
  # Ran 1 tests, 0 skipped, 1 failed.

Same result with Mercurial 2.9.2 and 3.0-rc; and with tip of stable and default in mutable-history.
Comment 1 Pierre-Yves David 2014-10-14 20:21 UTC
Updated repro script for Mercurial core.


  Enable evolve to see the bug
  
    $ cat >> $HGRCPATH <<EOF
    > [extensions]
    > rebase =
    > EOF
    $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext/evolve.py" >> $HGRCPATH
  
  
  setup test repo
    $ hg init
    $ echo a > a
    $ hg ci -A -m init
    adding a
  
  initial rename
    $ hg mv a a1
    $ hg st -C
    A a1
      a
    R a
    $ hg ci -m'rename (v1)'
  
  amend the rename (new commit message, no change to filenames or content)
    $ hg commit --amend -m'rename (v2)'
    $ hg st -C --ch .
    A a1
      a
    R a
  
  redo the rename: instead of moving into d1, move into d2
    $ hg mv a1 a2
    $ hg diff --rev .^ --git
    diff --git a/a b/a2
    rename from a
    rename to a2
    $ hg commit --amend -m'rename (v3)'
    $ hg st -C --ch .
    A a2
      a
    R a
Comment 2 Pierre-Yves David 2014-10-14 20:30 UTC
The previous copy past has a buggy reference to evolve: lets do it again

  Enable evolve to see the bug
    $ cat > obs.py << EOF
    > import mercurial.obsolete
    > mercurial.obsolete._enabled = True
    > EOF
    $ echo '[extensions]' >> $HGRCPATH
    $ echo "obs=${TESTTMP}/obs.py" >> $HGRCPATH
  
  
  setup test repo
    $ hg init repo
    $ cd repo
    $ echo a > a
    $ hg ci -A -m init
    adding a
  
  initial rename
    $ hg mv a a1
    $ hg st -C
    A a1
      a
    R a
    $ hg ci -m'rename (v1)'
  
  amend the rename (new commit message, no change to filenames or content)
    $ hg commit --amend -m'rename (v2)'
    $ hg st -C --ch .
    A a1
      a
    R a
  
  redo the rename: instead of moving into d1, move into d2
    $ hg mv a1 a2
    $ hg diff --rev .^ --git
    diff --git a/a b/a2
    rename from a
    rename to a2
    $ hg commit --amend -m'rename (v3)'
    $ hg st -C --ch .
    A a2
      a
    R a
Comment 3 Pierre-Yves David 2014-10-14 20:38 UTC
Disturbing fact. The diff is correct. But the status is wrong.
Comment 4 HG Bot 2014-10-22 19:31 UTC
Fixed by http://selenic.com/repo/hg/rev/652ab726ba93
Ryan McElroy <rmcelroy@fb.com>
amend: fix amending rename commit with diverged topologies (issue4405)

This addresses the bug described in issue4405: when obsolescence markers are
enabled, amending a commit with a file move can lead to the copy information
being lost.

However, the bug is more general and can be reproduced without obsmarkers as
well, as demonstracted by Pierre-Yves and put into the updated test.
Specifically, graph topology divergences between the filelogs and the changelog
can cause copy information to be lost during amends.

(please test the fix)
Comment 5 Matt Mackall 2015-01-22 15:04 UTC
Bulk testing -> fixed