Clean up after failed gerrit cl description edits

If either the edit creation or edit publishing fail, we're left with
an unpublished edit hanging around. This can result in a follow-up
invocation of 'git cl desc' (e.g. if the user changes their mind, or
retries) will also fail. So, clean up after ourselves.

BUG=671091

Change-Id: Icfe53996acf2555b82be0695a3c86ebb8c50b936
Reviewed-on: https://chromium-review.googlesource.com/418449
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
changes/49/418449/5
Aaron Gable 8 years ago committed by Commit Bot
parent 2188fe944f
commit e9373d6e92

@ -602,6 +602,7 @@ def DeletePendingChangeEdit(host, change):
def SetCommitMessage(host, change, description, notify='ALL'): def SetCommitMessage(host, change, description, notify='ALL'):
"""Updates a commit message.""" """Updates a commit message."""
try:
assert notify in ('ALL', 'NONE') assert notify in ('ALL', 'NONE')
# First, edit the commit message in a draft. # First, edit the commit message in a draft.
path = 'changes/%s/edit:message' % change path = 'changes/%s/edit:message' % change
@ -631,6 +632,16 @@ def SetCommitMessage(host, change, description, notify='ALL'):
raise GerritError( raise GerritError(
'Unexpectedly received a 200 http status while publishing message ' 'Unexpectedly received a 200 http status while publishing message '
'change in %s' % change) 'change in %s' % change)
except (GerritError, KeyboardInterrupt) as e:
# Something went wrong with one of the two calls, so we want to clean up
# after ourselves before returning.
try:
DeletePendingChangeEdit(host, change)
except GerritError:
LOGGER.error('Encountered error while cleaning up after failed attempt '
'to set the CL description. You may have to delete the '
'pending change edit yourself in the web UI.')
raise e
def GetReviewers(host, change): def GetReviewers(host, change):

Loading…
Cancel
Save