]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5403-post-checkout-hook.sh
Merge branch 'ah/rebase-no-fork-point-config'
[thirdparty/git.git] / t / t5403-post-checkout-hook.sh
CommitLineData
1abbe475
JE
1#!/bin/sh
2#
3# Copyright (c) 2006 Josh England
4#
5
6test_description='Test the post-checkout hook.'
966b4be2 7GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
8export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
1abbe475
JE
10. ./test-lib.sh
11
12test_expect_success setup '
10499a9d
OS
13 mkdir -p .git/hooks &&
14 write_script .git/hooks/post-checkout <<-\EOF &&
15 echo "$@" >.git/post-checkout.args
16 EOF
17 test_commit one &&
18 test_commit two &&
8581df65
OS
19 test_commit rebase-on-me &&
20 git reset --hard HEAD^ &&
10499a9d 21 test_commit three
1abbe475
JE
22'
23
24test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '
10499a9d 25 test_when_finished "rm -f .git/post-checkout.args" &&
966b4be2 26 git checkout main &&
10499a9d 27 read old new flag <.git/post-checkout.args &&
7281f366 28 test $old = $new && test $flag = 1
1abbe475
JE
29'
30
1abbe475 31test_expect_success 'post-checkout args are correct with git checkout -b ' '
10499a9d
OS
32 test_when_finished "rm -f .git/post-checkout.args" &&
33 git checkout -b new1 &&
34 read old new flag <.git/post-checkout.args &&
7281f366 35 test $old = $new && test $flag = 1
1abbe475
JE
36'
37
38test_expect_success 'post-checkout receives the right args with HEAD changed ' '
10499a9d
OS
39 test_when_finished "rm -f .git/post-checkout.args" &&
40 git checkout two &&
41 read old new flag <.git/post-checkout.args &&
7281f366 42 test $old != $new && test $flag = 1
1abbe475
JE
43'
44
45test_expect_success 'post-checkout receives the right args when not switching branches ' '
10499a9d 46 test_when_finished "rm -f .git/post-checkout.args" &&
966b4be2 47 git checkout main -- three.t &&
10499a9d 48 read old new flag <.git/post-checkout.args &&
7281f366 49 test $old = $new && test $flag = 0
1abbe475
JE
50'
51
8581df65
OS
52test_expect_success 'post-checkout is triggered on rebase' '
53 test_when_finished "rm -f .git/post-checkout.args" &&
966b4be2 54 git checkout -b rebase-test main &&
8581df65
OS
55 rm -f .git/post-checkout.args &&
56 git rebase rebase-on-me &&
57 read old new flag <.git/post-checkout.args &&
58 test $old != $new && test $flag = 1
59'
60
61test_expect_success 'post-checkout is triggered on rebase with fast-forward' '
62 test_when_finished "rm -f .git/post-checkout.args" &&
63 git checkout -b ff-rebase-test rebase-on-me^ &&
64 rm -f .git/post-checkout.args &&
65 git rebase rebase-on-me &&
66 read old new flag <.git/post-checkout.args &&
67 test $old != $new && test $flag = 1
68'
69
dfa7a6c5 70test_expect_success 'post-checkout hook is triggered by clone' '
10499a9d
OS
71 mkdir -p templates/hooks &&
72 write_script templates/hooks/post-checkout <<-\EOF &&
a250d418 73 echo "$@" >"$GIT_DIR/post-checkout.args"
10499a9d 74 EOF
dfa7a6c5
JK
75 git clone --template=templates . clone3 &&
76 test -f clone3/.git/post-checkout.args
77'
78
1abbe475 79test_done