Based on:
commit 58a23a938a5a7b1317b825bd5635fd72c8f1580d
Author: Sachi King <nakato@nakato.io>
Date: Tue Mar 29 10:51:32 2016 +1100
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
diff --git a/git_review/cmd.py b/git_review/cmd.py
index 9351242..affaf62 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():
track=convert_bool(config['track']),
remote=config['remote'])
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: