Use exceptions for finish_review

Add exceptions to errors that might
happend when closing a branch.

Allocate exit codes 67,68 for
for errors related to removing
the branch.

Change-Id: I9ba37ca5a69ded1421845a8d1a40bd6be22addca
This commit is contained in:
Marcin Cieslak
2012-10-30 17:43:58 +01:00
committed by Jeremy Stanley
parent 4511318b8d
commit 5e83096b8d
2 changed files with 22 additions and 14 deletions

View File

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

View File

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