Bug 3670 - hg commit --amend leads to wrong dirstate if commit message is empty
Summary: hg commit --amend leads to wrong dirstate if commit message is empty
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: earlier
Hardware: PC Linux
: normal bug
Assignee: Bugzilla
URL:
Keywords:
: 3725 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-10-21 15:35 UTC by David Soria Parra
Modified: 2017-11-01 18:05 UTC (History)
7 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 David Soria Parra 2012-10-21 15:35 UTC
The following script leads to a broken dirstate in case the commit message for hg ci --amend is empty.

$ hg init test
$ cd test
$ echo a > a
$ hg add a
$ hg commit -m'a'
$ echo b > b
$ hg add b
$ hg commit -m'b'
$ echo bb > b
$ hg commit --amend // REMOVE COMMIT MESSAGE
transaction abort!
rollback completed
abort: empty commit message
$ hg st
warning: ignoring unknown working parent bf09913437fb!
Comment 1 Idan Kamara 2012-10-21 16:59 UTC
Can't reproduce here.
Comment 2 Bryan O'Sullivan 2012-10-22 19:20 UTC
Can't reproduce either.
Comment 3 Bryan O'Sullivan 2012-10-22 20:07 UTC
Simpler repro:

hg init bug3670
cd bug3670
echo a>a
hg ci -Ama

# this sets up the bug for triggering
echo a>>a
# delete the commit message below
hg ci --amend
Comment 4 David Soria Parra 2012-10-22 20:14 UTC
it's caused by the temporary commit in cmdutil.amend()

opts['message'] = 'temporary amend commit for %s' % old          
node = commit(ui, repo, commitfunc, pats, opts) 

this creates a new commit and sets the repo parents. as the transaction is aborted it's not reset properly.
Comment 5 Idan Kamara 2012-10-23 06:29 UTC
(In reply to comment #3)

Still can't get this reproduce:

$ ./run-tests.py -l test-3670.t                                              

--- /home/idan/dev/hg/tests/test-3670.t
+++ /home/idan/dev/hg/tests/test-3670.t.err
@@ -6,4 +6,11 @@
 
   $ echo a>>a
   $ hg ci --amend
+  saved backup bundle to $TESTTMP/bug3670/.hg/strip-backup/cb9a9f314b8b-amend-backup.hg
   $ hg log
+  changeset:   0:bbb36c6acd42
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     a
+  

ERROR: /home/idan/dev/hg/tests/test-3670.t output changed
!
Failed test-3670.t: output changed
# Ran 1 tests, 0 skipped, 1 failed.

Even if I force it to raise the 'empty commit message' it cleans up fine.
Comment 6 Matt Mackall 2012-10-23 11:12 UTC
Ok, repros for me by setting editor to false

hg init a
cd a
echo a > a
hg ci -qAm0
echo a >> a
HGEDITOR=false hg ci --amend
hg id

---

transaction abort!
rollback completed
abort: edit failed: hgeditor exited with status 1
warning: ignoring unknown working parent 16f411eed2f6!
000000000000+
Comment 7 Idan Kamara 2012-10-23 12:49 UTC
Using Matt's script to bisect:

The first bad revision is:
changeset:   17473:9732473aa24b
user:        Pierre-Yves David <pierre-yves.david@logilab.fr>
date:        Sat Aug 25 16:20:41 2012 +0200
summary:     amend: use an explicit commit message for temporary amending commit
Comment 8 Pierre-Yves David 2012-12-07 04:57 UTC
*** Bug 3725 has been marked as a duplicate of this bug. ***
Comment 9 Pierre-Yves David 2012-12-07 05:00 UTC
After some investigation last week, I suspect transaction abortion to not restore journal file. leading the properly backuped dirstate file to be out of sync with the rollbacked repo.
Comment 10 HG Bot 2013-01-02 01:49 UTC
Fixed by http://selenic.com/repo/hg/rev/153659e86a5f
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
amend: invalidate dirstate in case of failure (issue3670)

The temporary commit created by amend update the dirstate. If the final commit
fails, we need to invalidate the change made to the dirstate, otherwise the
release of the wlock will write the dirstate created after the rollbacked
temporary commit.

This dirstate writing logic should probably be handled in the same object than
the transaction one. However such change are too big for stable.

(please test the fix)