D204: commit: don't let failed commit with --addremove update dirstate (issue5645)

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Mon Jul 31 23:59:06 UTC 2017


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D204

AFFECTED FILES
  mercurial/cmdutil.py
  tests/test-commit.t
  tests/test-flagprocessor.t
  tests/test-username-newline.t

CHANGE DETAILS

diff --git a/tests/test-username-newline.t b/tests/test-username-newline.t
--- a/tests/test-username-newline.t
+++ b/tests/test-username-newline.t
@@ -14,10 +14,12 @@
   $ rm .hg/hgrc
 
   $ HGUSER=`(echo foo; echo bar2)` hg ci -Am m
+  adding a
   abort: username 'foo\nbar2' contains a newline
   
   [255]
   $ hg ci -Am m -u "`(echo foo; echo bar3)`"
+  adding a
   transaction abort!
   rollback completed
   abort: username 'foo\nbar3' contains a newline!
diff --git a/tests/test-flagprocessor.t b/tests/test-flagprocessor.t
--- a/tests/test-flagprocessor.t
+++ b/tests/test-flagprocessor.t
@@ -152,7 +152,6 @@
   $ hg commit -Aqm 'fail+base64+gzip+noop'
   abort: missing processor for flag '0x1'!
   [255]
-  $ hg forget fail-base64-gzip-noop
   $ rm fail-base64-gzip-noop
 
 # TEST: ensure we cannot register several flag processors on the same flag
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -157,7 +157,7 @@
   abort: edit failed: false exited with status 1
   [255]
   $ hg status
-  A newfile
+  ? newfile
 
 Make sure we do not obscure unknown requires file entries (issue2649)
 
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -26,6 +26,7 @@
     changelog,
     copies,
     crecord as crecordmod,
+    dirstateguard,
     encoding,
     error,
     formatter,
@@ -2888,14 +2889,23 @@
     message = logmessage(ui, opts)
     matcher = scmutil.match(repo[None], pats, opts)
 
+    dsguard = None
     # extract addremove carefully -- this function can be called from a command
     # that doesn't support addremove
-    if opts.get('addremove'):
-        if scmutil.addremove(repo, matcher, "", opts) != 0:
-            raise error.Abort(
-                _("failed to mark all new/missing files as added/removed"))
-
-    return commitfunc(ui, repo, message, matcher, opts)
+    try:
+        if opts.get('addremove'):
+            dsguard = dirstateguard.dirstateguard(repo, 'commit')
+            if scmutil.addremove(repo, matcher, "", opts) != 0:
+                raise error.Abort(
+                    _("failed to mark all new/missing files as added/removed"))
+
+        r = commitfunc(ui, repo, message, matcher, opts)
+        if dsguard:
+            dsguard.close()
+        return r
+    finally:
+        if dsguard:
+            dsguard.release()
 
 def samefile(f, ctx1, ctx2):
     if f in ctx1.manifest():



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list