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

Differential Revision: https://phab.mercurial-scm.org/D204
This commit is contained in:
Martin von Zweigbergk 2017-07-31 14:54:57 -07:00
parent ff40788359
commit 9ce4ef597c
4 changed files with 18 additions and 7 deletions

View File

@ -26,6 +26,7 @@ from . import (
changelog,
copies,
crecord as crecordmod,
dirstateguard,
encoding,
error,
formatter,
@ -2888,14 +2889,23 @@ def commit(ui, repo, commitfunc, pats, opts):
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"))
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"))
return commitfunc(ui, repo, message, matcher, opts)
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():

View File

@ -157,7 +157,7 @@ Failed commit with --addremove should not update dirstate
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)

View File

@ -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

View File

@ -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!