changeset 18197:153659e86a5f stable

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.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Sat, 29 Dec 2012 18:00:18 +0100
parents 18fef98618cd
children 9b4adaef0db9
files mercurial/cmdutil.py tests/test-commit-amend.t
diffstat 2 files changed, 29 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Thu Dec 20 16:36:45 2012 -0600
+++ b/mercurial/cmdutil.py	Sat Dec 29 18:00:18 2012 +0100
@@ -1619,7 +1619,7 @@
     ui.note(_('amending changeset %s\n') % old)
     base = old.p1()
 
-    wlock = lock = None
+    wlock = lock = newid = None
     try:
         wlock = repo.wlock()
         lock = repo.lock()
@@ -1782,6 +1782,8 @@
             ui.note(_('stripping amended changeset %s\n') % old)
             repair.strip(ui, repo, old.node(), topic='amend-backup')
     finally:
+        if newid is None:
+            repo.dirstate.invalidate()
         lockmod.release(wlock, lock)
     return newid
 
--- a/tests/test-commit-amend.t	Thu Dec 20 16:36:45 2012 -0600
+++ b/tests/test-commit-amend.t	Sat Dec 29 18:00:18 2012 +0100
@@ -58,11 +58,34 @@
   summary:     base
   
 
-Add new file:
+Check proper abort for empty message
 
+  $ cat > editor.sh << '__EOF__'
+  > #!/bin/sh
+  > echo "" > "$1"
+  > __EOF__
   $ echo b > b
-  $ hg ci --amend -Am 'amend base1 new file'
-  adding b
+  $ hg add b
+  $ hg summary
+  parent: 1:43f1ba15f28a tip
+   amend base1
+  branch: default
+  commit: 1 added, 1 unknown
+  update: (current)
+  $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend
+  transaction abort!
+  rollback completed
+  abort: empty commit message
+  [255]
+  $ hg summary
+  parent: 1:43f1ba15f28a tip
+   amend base1
+  branch: default
+  commit: 1 added, 1 unknown
+  update: (current)
+
+Add new file:
+  $ hg ci --amend -m 'amend base1 new file'
   saved backup bundle to $TESTTMP/.hg/strip-backup/43f1ba15f28a-amend-backup.hg (glob)
 
 Remove file that was added in amended commit: