]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rebase --apply: don't run post-checkout hook if there is an error
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Wed, 26 Jan 2022 13:05:40 +0000 (13:05 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 26 Jan 2022 20:08:53 +0000 (12:08 -0800)
The hook should only be run if the worktree and refs were successfully
updated. This primarily affects "rebase --apply" but also "rebase
--merge" when it fast-forwards.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reset.c
t/t5403-post-checkout-hook.sh

diff --git a/reset.c b/reset.c
index 3e7b9e2e1313947e627c6da6ae70151d83425645..3537de91f65c1e4817cfd31e6734819d351f0cb7 100644 (file)
--- a/reset.c
+++ b/reset.c
@@ -126,7 +126,7 @@ reset_head_refs:
                        ret = create_symref("HEAD", switch_to_branch,
                                            reflog_head);
        }
-       if (run_hook)
+       if (!ret && run_hook)
                run_hook_le(NULL, "post-checkout",
                            oid_to_hex(head ? head : null_oid()),
                            oid_to_hex(oid), "1", NULL);
index fd2817b4068c52908cc91b1e9fe4d3a336fe3a5e..d11818169067bb349c45cc42abb33826d99fe60c 100755 (executable)
@@ -88,12 +88,16 @@ test_rebase () {
 
        test_expect_success "rebase $args checkout does not remove untracked files" '
                test_when_finished "test_might_fail git rebase --abort" &&
+               test_when_finished "rm -f .git/post-checkout.args" &&
                git update-ref refs/heads/rebase-fast-forward three &&
                git checkout two &&
+               rm -f .git/post-checkout.args &&
                echo untracked >three.t &&
                test_when_finished "rm three.t" &&
                test_must_fail git rebase $args HEAD rebase-fast-forward 2>err &&
-               grep "untracked working tree files would be overwritten by checkout" err
+               grep "untracked working tree files would be overwritten by checkout" err &&
+               test_path_is_missing .git/post-checkout.args
+
 '
 }