diff --git a/git-review b/git-review index ad286ff6..544263f9 100755 --- a/git-review +++ b/git-review @@ -720,24 +720,28 @@ def download_review(review, masterbranch, remote): print("Switched to branch '%s'" % branch_name) +class CheckoutBackExistingBranchFailed(CommandFailed): + "Cannot switch back to existing branch" + EXIT_CODE = 67 + + +class DeleteBranchFailed(CommandFailed): + "Failed to delete branch" + EXIT_CODE = 68 + + def finish_branch(target_branch): local_branch = get_branch_name(target_branch) if VERBOSE: - print("Switching back to %s and deleting %s" % (target_branch, - local_branch)) - checkout_cmd = "git checkout %s" % target_branch - (status, output) = run_command_status(checkout_cmd) - if status != 0: - print(output) - return status + print("Switching back to '%s' and deleting '%s'" % (target_branch, + local_branch)) + run_command_exc(CheckoutBackExistingBranchFailed, + "git", "checkout", target_branch) print("Switched to branch '%s'" % target_branch) - close_cmd = "git branch -D %s" % local_branch - (status, output) = run_command_status(close_cmd) - if status != 0: - print(output) - return status + + run_command_exc(DeleteBranchFailed, + "git", "branch", "-D", local_branch) print("Deleted branch '%s'" % local_branch) - return 0 def print_exit_message(status, needs_update): diff --git a/git-review.1 b/git-review.1 index dad0f7b9..711d7bdd 100644 --- a/git-review.1 +++ b/git-review.1 @@ -132,7 +132,11 @@ Cannot checkout downloaded patchset into the new branch. Cannot checkout downloaded patchset into existing branch. .It 66 Cannot hard reset working directory and git index after download. -.El +.It 67 +Cannot switch to some other branch when trying to finish +the current branch. +.It 68 +Cannot delete current branch. .El .Pp Exit status larger than 31 indicates problem with