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/+/1536033
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Commit-Queue: Raul Tambre <raul@tambre.ee>
diff --git a/git_cl.py b/git_cl.py
index 136ba15..608a487 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -2723,6 +2723,7 @@
refspec = '%s:refs/for/%s%s' % (ref_to_push, branch, refspec_suffix)
try:
+ push_returncode = 0
before_push = time_time()
push_stdout = gclient_utils.CheckCallAndFilter(
['git', 'push', self.GetRemoteUrl(), refspec],
@@ -2730,7 +2731,6 @@
# Flush after every line: useful for seeing progress when running as
# recipe.
filter_fn=lambda _: sys.stdout.flush())
- push_returncode = 0
except subprocess2.CalledProcessError as e:
push_returncode = e.returncode
DieWithError('Failed to create a change. Please examine output above '