diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2015-01-05 11:56:34 +0000 |
---|---|---|
committer | Owen W. Taylor <otaylor@fishsoup.net> | 2015-02-27 10:23:58 -0500 |
commit | 3ba8322b80d8cb06c06dc79fb331fb8014556fcb (patch) | |
tree | 2ca0f900a7a718f6a40b4248fb725a4271ffe5c4 | |
parent | 660a5ea29de7919d2bd62545b7f36a8b7bc216c3 (diff) | |
download | git-bz-3ba8322b80d8cb06c06dc79fb331fb8014556fcb.tar.gz |
Handle further git exceptions in do_attach()
This improves validation of attach arguments. Previously, the command:
git bz attach 741345
would result in the crash:
fatal: ambiguous argument '741345': unknown revision or path not in
the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Traceback (most recent call last):
File "/home/philip/.local/bin/git-bz", line 2472, in <module>
do_attach(*args)
File "/home/philip/.local/bin/git-bz", line 1830, in do_attach
commits = get_commits(commit_or_revision_range)
File "/home/philip/.local/bin/git-bz", line 233, in get_commits
commits = rev_list_commits(commit_or_revision_range)
File "/home/philip/.local/bin/git-bz", line 205, in
rev_list_commits
output = git.rev_list(*args, **kwargs_copy)
File "/home/philip/.local/bin/git-bz", line 192, in f
return git_run(command, *args, **kwargs)
File "/home/philip/.local/bin/git-bz", line 174, in git_run
raise CalledProcessError(process.returncode, " ".join(to_run))
subprocess.CalledProcessError: Command 'git rev-list
--pretty=format:%s 741345' returned non-zero exit status 128
Now it prints an error gracefully.
https://bugzilla.gnome.org/show_bug.cgi?id=742371
-rwxr-xr-x | git-bz | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -245,7 +245,12 @@ def get_commits(commit_or_revision_range): commits = rev_list_commits(rev, max_count='1') except CalledProcessError: # If not, assume the argument is a range - commits = rev_list_commits(commit_or_revision_range) + try: + commits = rev_list_commits(commit_or_revision_range) + except CalledProcessError: + # If not again, the argument must be invalid — perhaps the user has + # accidentally specified a bug number but not a revision. + commits = [] if len(commits) == 0: die("'%s' does not name any commits. Use HEAD to specify just the last commit" % |