rebase: run post-checkout hook on checkout
The scripted version of rebase used to run this hook on the initial checkout. The transition to built-in introduced a regression. Signed-off-by: Orgad Shaneh <orgads@gmail.com> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Orgad Shaneh committed
Dec 29, 2018 at 23:37 UTC
8581df65ec961aa59004f2d6342709b25d7b79c4
2 files changed
+30
-2
builtin/rebase.c
+10
-2
@@ -530,6 +530,7 @@ finished_rebase:
530
531
#define RESET_HEAD_DETACH (1<<0)
532
#define RESET_HEAD_HARD (1<<1)
533
+#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2)
534
535
static int reset_head(struct object_id *oid, const char *action,
536
const char *switch_to_branch, unsigned flags,
@@ -537,6 +538,7 @@ static int reset_head(struct object_id *oid, const char *action,
538
{
539
unsigned detach_head = flags & RESET_HEAD_DETACH;
540
unsigned reset_hard = flags & RESET_HEAD_HARD;
541
+ unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
542
struct object_id head_oid;
543
struct tree_desc desc[2] = { { NULL }, { NULL } };
544
struct lock_file lock = LOCK_INIT;
@@ -636,6 +638,10 @@ static int reset_head(struct object_id *oid, const char *action,
638
ret = update_ref(reflog_head, "HEAD", oid, NULL, 0,
639
UPDATE_REFS_MSG_ON_ERR);
640
}
641
+ if (run_hook)
642
+ run_hook_le(NULL, "post-checkout",
643
+ oid_to_hex(orig ? orig : &null_oid),
644
+ oid_to_hex(oid), "1", NULL);
645
646
leave_reset_head:
647
strbuf_release(&msg);
@@ -1465,7 +1471,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1471
getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
1472
options.switch_to);
1473
if (reset_head(&oid, "checkout",
1468
- options.head_name, 0,
1474
+ options.head_name,
1475
+ RESET_HEAD_RUN_POST_CHECKOUT_HOOK,
1476
NULL, buf.buf) < 0) {
1477
ret = !!error(_("could not switch to "
1478
"%s"),
@@ -1539,7 +1546,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1546
strbuf_addf(&msg, "%s: checkout %s",
1547
getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
1548
if (reset_head(&options.onto->object.oid, "checkout", NULL,
1542
- RESET_HEAD_DETACH, NULL, msg.buf))
1549
+ RESET_HEAD_DETACH | RESET_HEAD_RUN_POST_CHECKOUT_HOOK,
1550
+ NULL, msg.buf))
1551
die(_("Could not detach HEAD"));
1552
strbuf_release(&msg);
1553
t/t5403-post-checkout-hook.sh
+20
@@ -13,6 +13,8 @@ test_expect_success setup '
13
EOF
14
test_commit one &&
15
test_commit two &&
16
+ test_commit rebase-on-me &&
17
+ git reset --hard HEAD^ &&
18
test_commit three
19
'
20
@@ -44,6 +46,24 @@ test_expect_success 'post-checkout receives the right args when not switching br
46
test $old = $new && test $flag = 0
47
'
48
49
+test_expect_success 'post-checkout is triggered on rebase' '
50
+ test_when_finished "rm -f .git/post-checkout.args" &&
51
+ git checkout -b rebase-test master &&
52
+ rm -f .git/post-checkout.args &&
53
+ git rebase rebase-on-me &&
54
+ read old new flag <.git/post-checkout.args &&
55
+ test $old != $new && test $flag = 1
56
+'
57
+
58
+test_expect_success 'post-checkout is triggered on rebase with fast-forward' '
59
+ test_when_finished "rm -f .git/post-checkout.args" &&
60
+ git checkout -b ff-rebase-test rebase-on-me^ &&
61
+ rm -f .git/post-checkout.args &&
62
+ git rebase rebase-on-me &&
63
+ read old new flag <.git/post-checkout.args &&
64
+ test $old != $new && test $flag = 1
65
+'
66
+
67
test_expect_success 'post-checkout hook is triggered by clone' '
68
mkdir -p templates/hooks &&
69
write_script templates/hooks/post-checkout <<-\EOF &&