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
This commit is contained in:
Sachi King 2016-03-29 10:51:32 +11:00
parent aaa416e697
commit 58a23a938a
1 changed files with 5 additions and 4 deletions

View File

@ -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: