From ba35c7f8ce4bc9ae93607109b89199d3d9e0af2d Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Sun, 24 Mar 2019 06:11:18 +0000 Subject: [PATCH] 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 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 Commit-Queue: Raul Tambre --- git_cl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git_cl.py b/git_cl.py index 136ba15e16..608a487ef0 100755 --- a/git_cl.py +++ b/git_cl.py @@ -2723,6 +2723,7 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): 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 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): # 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 '