Commit f732cd5c authored by Christopher Lam's avatar Christopher Lam Committed by Commit Bot

Add cl description backup to gerrit upload.

BUG=684261

Change-Id: I2716864526fcedf44e561be8512843e12810e3a9
Reviewed-on: https://chromium-review.googlesource.com/431459Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
parent cd091367
......@@ -92,11 +92,23 @@ settings = None
_IS_BEING_TESTED = False
def DieWithError(message):
def DieWithError(message, change_desc=None):
if change_desc:
SaveDescriptionBackup(change_desc)
print(message, file=sys.stderr)
sys.exit(1)
def SaveDescriptionBackup(change_desc):
backup_path = os.path.expanduser(DESCRIPTION_BACKUP_FILE)
print('\nError after CL description prompt -- saving description to %s\n' %
backup_path)
backup_file = open(backup_path, 'w')
backup_file.write(change_desc.description)
backup_file.close()
def GetNoGitPagerEnv():
env = os.environ.copy()
# 'cat' is a magical git string that disables pagers on all platforms.
......@@ -2161,7 +2173,7 @@ class _RietveldChangelistImpl(_ChangelistCodereviewBase):
change_desc.get_reviewers()))
if options.send_mail:
if not change_desc.get_reviewers():
DieWithError("Must specify reviewers to send email.")
DieWithError("Must specify reviewers to send email.", change_desc)
upload_args.append('--send_mail')
# We check this before applying rietveld.private assuming that in
......@@ -2248,12 +2260,7 @@ class _RietveldChangelistImpl(_ChangelistCodereviewBase):
# If we got an exception after the user typed a description for their
# change, back up the description before re-raising.
if change_desc:
backup_path = os.path.expanduser(DESCRIPTION_BACKUP_FILE)
print('\nGot exception while uploading -- saving description to %s\n' %
backup_path)
backup_file = open(backup_path, 'w')
backup_file.write(change_desc.description)
backup_file.close()
SaveDescriptionBackup(change_desc)
raise
if not self.GetIssue():
......@@ -2261,7 +2268,6 @@ class _RietveldChangelistImpl(_ChangelistCodereviewBase):
self.SetPatchset(patchset)
return 0
class _GerritChangelistImpl(_ChangelistCodereviewBase):
def __init__(self, changelist, auth_config=None):
# auth_config is Rietveld thing, kept here to preserve interface only.
......@@ -2787,7 +2793,7 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
'upload, so you just need to upload it again.\n'
'(If you uploaded it with --no-squash, then branch dependencies '
'are not supported, and you should reupload with --squash.)'
% upstream_branch_name)
% upstream_branch_name, change_desc)
else:
parent = self.GetCommonAncestorWithUpstream()
......@@ -2844,7 +2850,7 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
if options.send_mail:
if not change_desc.get_reviewers():
DieWithError('Must specify reviewers to send email.')
DieWithError('Must specify reviewers to send email.', change_desc)
refspec_opts.append('notify=ALL')
else:
refspec_opts.append('notify=NONE')
......@@ -2877,7 +2883,7 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
filter_fn=lambda _: sys.stdout.flush())
except subprocess2.CalledProcessError:
DieWithError('Failed to create a change. Please examine output above '
'for the reason of the failure. ')
'for the reason of the failure. ', change_desc)
if options.squash:
regex = re.compile(r'remote:\s+https?://[\w\-\.\/]*/(\d+)\s.*')
......@@ -2887,7 +2893,7 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
if len(change_numbers) != 1:
DieWithError(
('Created|Updated %d issues on Gerrit, but only 1 expected.\n'
'Change-Id: %s') % (len(change_numbers), change_id))
'Change-Id: %s') % (len(change_numbers), change_id), change_desc)
self.SetIssue(change_numbers[0])
self._GitSetBranchConfigValue('gerritsquashhash', ref_to_push)
......
......@@ -467,7 +467,7 @@ class TestGitCl(TestCase):
self.mock(git_cl.gerrit_util.GceAuthenticator, 'is_gce',
classmethod(lambda _: False))
self.mock(git_cl, 'DieWithError',
lambda msg: self._mocked_call(['DieWithError', msg]))
lambda msg, change=None: self._mocked_call(['DieWithError', msg]))
# It's important to reset settings to not have inter-tests interference.
git_cl.settings = None
......@@ -1912,7 +1912,7 @@ class TestGitCl(TestCase):
self.mock(git_cl.gerrit_util, 'CookiesAuthenticator',
CookiesAuthenticatorMockFactory(hosts_with_creds=auth))
self.mock(git_cl, 'DieWithError',
lambda msg: self._mocked_call(['DieWithError', msg]))
lambda msg, change=None: self._mocked_call(['DieWithError', msg]))
self.mock(git_cl, 'ask_for_data',
lambda msg: self._mocked_call(['ask_for_data', msg]))
self.calls = self._gerrit_ensure_auth_calls(skip_auth_check=skip_auth_check)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment