From 58a23a938a5a7b1317b825bd5635fd72c8f1580d Mon Sep 17 00:00:00 2001 From: Sachi King Date: Tue, 29 Mar 2016 10:51:32 +1100 Subject: [PATCH] Fix no_git_dir UnboundLocalError in except block In Python 3, exception blocks clean their variables up, and we get a UnbloundLocalError when we try to reference the target outside of the except block. To pass the exception out we set a variable from the target. Also pull --license above raising the error, as it should work outside a git repo too. https://www.python.org/dev/peps/pep-3110/#semantic-changes Change-Id: I298ac3648068cd07c4cf232e32ab3daaaf8e549d --- git_review/cmd.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/git_review/cmd.py b/git_review/cmd.py index 93512427..affaf624 100755 --- a/git_review/cmd.py +++ b/git_review/cmd.py @@ -1418,8 +1418,8 @@ def _main(): yes=False) try: (top_dir, git_dir) = git_directories() - except GitDirectoriesException as no_git_dir: - pass + except GitDirectoriesException as _no_git_dir: + no_git_dir = _no_git_dir else: no_git_dir = False config = Config(os.path.join(top_dir, ".gitreview")) @@ -1428,13 +1428,14 @@ def _main(): remote=None, usepushurl=convert_bool(config['usepushurl'])) options = parser.parse_args() - if no_git_dir: - raise no_git_dir if options.license: print(COPYRIGHT) sys.exit(0) + if no_git_dir: + raise no_git_dir + if options.branch is None: branch = config['branch'] else: