From b28b39af59b04627aeb8cdb82c36595acaab8907 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 10 Feb 2020 13:39:24 +0000 Subject: Issue #4 - Exit with error on apply error, but catch in cascade apply. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a patch fails to apply we should exit with a proper exit status so that ansible can catch the issue in non-interactive operation for the sandboxes. Test plan You can use echo $? after executing any command in the shell to see the last commands exit code.. 0 for success, 1 for failure. To test this patch try doing a git bz apply using a bug you know will fail to apply, Call the echo statement above and note the exit code is 0.. after applying the patch do the same bz apply and echo and not the exit code now properly reflects the failure state with an exit code of 1. Bonus points is to test that the cascade apply still works as expected for both cases of a fully successful apply and for one where one of the dependancies fails to apply. More bonus points, check that passing multiple bug ids also still works --- git-bz | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/git-bz b/git-bz index 9f77f4a..2a1fbb3 100755 --- a/git-bz +++ b/git-bz @@ -1766,10 +1766,11 @@ def do_apply(*args): if opt == "n": continue else: - applied = do_apply(d_id, { 'do_not_add_url': 1} ) - if applied is None: + try: + applied = do_apply(d_id, { 'do_not_add_url': 1} ) + bugs_applied.extend(applied) + except BaseException: die("\nCannot apply cleanly patches from bug %s. Everything will be left dirty.\ngit bz apply --continue will not continue the process if patches from other bug reports need to be applied." % d_id) - bugs_applied.extend(applied) orig_head = git.rev_parse("HEAD") @@ -1862,8 +1863,7 @@ FIXME: need commit message. for i in range(patches.index(patch) + 1, len(patches)): f.write("%s\n" % patches[i].attach_id) f.close() - print "Patch left in %s" % filename - return None # Better would be to raise an exception + die("Patch left in %s" % filename); os.remove(filename) -- cgit