3 # Copyright (c) 2006 Josh England
6 test_description
='Test the post-checkout hook.'
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12 test_expect_success setup
'
13 mkdir -p .git/hooks &&
14 write_script .git/hooks/post-checkout <<-\EOF &&
15 echo "$@" >.git/post-checkout.args
19 test_commit rebase-on-me &&
20 git reset --hard HEAD^ &&
24 test_expect_success
'post-checkout receives the right arguments with HEAD unchanged ' '
25 test_when_finished "rm -f .git/post-checkout.args" &&
27 read old new flag <.git/post-checkout.args &&
28 test $old = $new && test $flag = 1
31 test_expect_success
'post-checkout args are correct with git checkout -b ' '
32 test_when_finished "rm -f .git/post-checkout.args" &&
33 git checkout -b new1 &&
34 read old new flag <.git/post-checkout.args &&
35 test $old = $new && test $flag = 1
38 test_expect_success
'post-checkout receives the right args with HEAD changed ' '
39 test_when_finished "rm -f .git/post-checkout.args" &&
41 read old new flag <.git/post-checkout.args &&
42 test $old != $new && test $flag = 1
45 test_expect_success
'post-checkout receives the right args when not switching branches ' '
46 test_when_finished "rm -f .git/post-checkout.args" &&
47 git checkout main -- three.t &&
48 read old new flag <.git/post-checkout.args &&
49 test $old = $new && test $flag = 0
52 test_expect_success
'post-checkout is triggered on rebase' '
53 test_when_finished "rm -f .git/post-checkout.args" &&
54 git checkout -b rebase-test main &&
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
61 test_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
70 test_expect_success
'post-checkout hook is triggered by clone' '
71 mkdir -p templates/hooks &&
72 write_script templates/hooks/post-checkout <<-\EOF &&
73 echo "$@" >"$GIT_DIR/post-checkout.args"
75 git clone --template=templates . clone3 &&
76 test -f clone3/.git/post-checkout.args