From 3ba8322b80d8cb06c06dc79fb331fb8014556fcb Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 5 Jan 2015 11:56:34 +0000 Subject: 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 [...] -- [...]' Traceback (most recent call last): File "/home/philip/.local/bin/git-bz", line 2472, in 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 --- git-bz | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/git-bz b/git-bz index 7b0fe69..01f37d9 100755 --- a/git-bz +++ b/git-bz @@ -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" % -- cgit