[PATCH STABLE] amend: invalidate dirstate in case of failure (issue3670)

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sat Dec 29 11:10:49 CST 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1356800418 -3600
# Branch stable
# Node ID a51a5199a672e378924066cd5103afef8de26fb8
# Parent  52581d2b98ac5355c3b2ea304595f8cfee4cce59
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.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1617,11 +1617,11 @@ def commit(ui, repo, commitfunc, pats, o
 
 def amend(ui, repo, commitfunc, old, extra, pats, opts):
     ui.note(_('amending changeset %s\n') % old)
     base = old.p1()
 
-    wlock = lock = None
+    wlock = lock = newid = None
     try:
         wlock = repo.wlock()
         lock = repo.lock()
         tr = repo.transaction('amend')
         try:
@@ -1780,10 +1780,12 @@ def amend(ui, repo, commitfunc, old, ext
             if node:
                 ui.note(_('stripping intermediate changeset %s\n') % ctx)
             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
 
 def commiteditor(repo, ctx, subs):
     if ctx.description():
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
@@ -56,15 +56,38 @@ Amending changeset with changes in worki
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     base
   
 
+Check proper abort for empty message
+
+  $ cat > editor.sh << '__EOF__'
+  > #!/bin/sh
+  > echo "" > "$1"
+  > __EOF__
+  $ echo b > 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:
-
-  $ echo b > b
-  $ hg ci --amend -Am 'amend base1 new file'
-  adding b
+  $ 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:
 (and test logfile option)
 (and test that logfile option do not trigger an editor)


More information about the Mercurial-devel mailing list