commit: don't let failed commit with --addremove update dirstate (
issue5645)
Differential Revision: https://phab.mercurial-scm.org/D204
--- a/mercurial/cmdutil.py Mon Jul 31 14:54:08 2017 -0700
+++ b/mercurial/cmdutil.py Mon Jul 31 14:54:57 2017 -0700
@@ -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():
--- a/tests/test-commit.t Mon Jul 31 14:54:08 2017 -0700
+++ b/tests/test-commit.t Mon Jul 31 14:54:57 2017 -0700
@@ -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)
--- a/tests/test-flagprocessor.t Mon Jul 31 14:54:08 2017 -0700
+++ b/tests/test-flagprocessor.t Mon Jul 31 14:54:57 2017 -0700
@@ -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
--- a/tests/test-username-newline.t Mon Jul 31 14:54:08 2017 -0700
+++ b/tests/test-username-newline.t Mon Jul 31 14:54:57 2017 -0700
@@ -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!