Commit ba35c7f8 authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

Fix possible use of unassigned local variable in git_cl.py

When an exception occurs in CheckCallAndFilter the push_returncode variable is used in the finally block without being initialized.

Traceback (most recent call last):
  File "C:\Google\depot_tools\metrics.py", line 266, in print_notice_and_exit
    yield
  File "C:\Google\depot_tools\git_cl.py", line 5647, in <module>
    sys.exit(main(sys.argv[1:]))
  File "C:\Google\depot_tools\git_cl.py", line 5629, in main
    return dispatcher.execute(OptionParser(), argv)
  File "C:\Google\depot_tools\subcommand.py", line 252, in execute
    return command(parser, args[1:])
  File "C:\Google\depot_tools\git_cl.py", line 4641, in CMDupload
    return cl.CMDUpload(options, args, orig_args)
  File "C:\Google\depot_tools\git_cl.py", line 1623, in CMDUpload
    ret = self.CMDUploadChange(options, git_diff_args, custom_cl_base, change)
  File "C:\Google\depot_tools\git_cl.py", line 2746, in CMDUploadChange
    'exit_code': push_returncode,
UnboundLocalError: local variable 'push_returncode' referenced before assignment

Change-Id: Ife0e5226aa7e6127e8a508adb747f2c653ed8351
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1536033Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Raul Tambre <raul@tambre.ee>
parent e4e1dde6
...@@ -2723,6 +2723,7 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): ...@@ -2723,6 +2723,7 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
refspec = '%s:refs/for/%s%s' % (ref_to_push, branch, refspec_suffix) refspec = '%s:refs/for/%s%s' % (ref_to_push, branch, refspec_suffix)
try: try:
push_returncode = 0
before_push = time_time() before_push = time_time()
push_stdout = gclient_utils.CheckCallAndFilter( push_stdout = gclient_utils.CheckCallAndFilter(
['git', 'push', self.GetRemoteUrl(), refspec], ['git', 'push', self.GetRemoteUrl(), refspec],
...@@ -2730,7 +2731,6 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): ...@@ -2730,7 +2731,6 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
# Flush after every line: useful for seeing progress when running as # Flush after every line: useful for seeing progress when running as
# recipe. # recipe.
filter_fn=lambda _: sys.stdout.flush()) filter_fn=lambda _: sys.stdout.flush())
push_returncode = 0
except subprocess2.CalledProcessError as e: except subprocess2.CalledProcessError as e:
push_returncode = e.returncode push_returncode = e.returncode
DieWithError('Failed to create a change. Please examine output above ' DieWithError('Failed to create a change. Please examine output above '
......
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