git-p4: clean up after p4 submit failure

When "p4 submit" command fails in P4Submit.applyCommit, the
workspace is left with the changes.  We already have code to revert
the changes to the workspace when the user decides to cancel
submission by aborting the editor that edits the change description,
and we should treat the "p4 submit" failure the same way.

Clean the workspace if p4_write_pipe raised SystemExit, so that the
user don't have to do it themselves.

Signed-off-by: GIRARD Etienne <egirard@murex.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Luke Diamand <luke@diamand.org>
Signed-off-by: Jeff King <peff@peff.net>
This commit is contained in:
GIRARD Etienne 2015-11-24 07:43:59 +00:00 committed by Jeff King
parent b05c2f9ed4
commit b7638fed42
2 changed files with 36 additions and 33 deletions

View File

@ -1538,9 +1538,11 @@ class P4Submit(Command, P4UserMap):
#
# Let the user edit the change description, then submit it.
#
submitted = False
try:
if self.edit_template(fileName):
# read the edited message and submit
ret = True
tmpFile = open(fileName, "rb")
message = tmpFile.read()
tmpFile.close()
@ -1561,10 +1563,11 @@ class P4Submit(Command, P4UserMap):
# new file. This leaves it writable, which confuses p4.
for f in pureRenameCopy:
p4_sync(f, "-f")
submitted = True
else:
finally:
# skip this patch
ret = False
if not submitted:
print "Submission cancelled, undoing p4 changes."
for f in editedFiles:
p4_revert(f)
@ -1575,7 +1578,7 @@ class P4Submit(Command, P4UserMap):
p4_revert(f)
os.remove(fileName)
return ret
return submitted
# Export git tags as p4 labels. Create a p4 label and then tag
# with that.

View File

@ -389,7 +389,7 @@ test_expect_success 'description with Jobs section and bogus following text' '
(
cd "$cli" &&
p4 revert desc6 &&
rm desc6
rm -f desc6
)
'