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) 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): def finish_branch(target_branch):
local_branch = get_branch_name(target_branch) local_branch = get_branch_name(target_branch)
if VERBOSE: if VERBOSE:
print("Switching back to %s and deleting %s" % (target_branch, print("Switching back to '%s' and deleting '%s'" % (target_branch,
local_branch)) local_branch))
checkout_cmd = "git checkout %s" % target_branch run_command_exc(CheckoutBackExistingBranchFailed,
(status, output) = run_command_status(checkout_cmd) "git", "checkout", target_branch)
if status != 0:
print(output)
return status
print("Switched to branch '%s'" % target_branch) print("Switched to branch '%s'" % target_branch)
close_cmd = "git branch -D %s" % local_branch
(status, output) = run_command_status(close_cmd) run_command_exc(DeleteBranchFailed,
if status != 0: "git", "branch", "-D", local_branch)
print(output)
return status
print("Deleted branch '%s'" % local_branch) print("Deleted branch '%s'" % local_branch)
return 0
def print_exit_message(status, needs_update): 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. Cannot checkout downloaded patchset into existing branch.
.It 66 .It 66
Cannot hard reset working directory and git index after download. 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 .El
.Pp .Pp
Exit status larger than 31 indicates problem with Exit status larger than 31 indicates problem with