]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5403-post-checkout-hook.sh
Merge branch 'ah/rebase-no-fork-point-config'
[thirdparty/git.git] / t / t5403-post-checkout-hook.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Josh England
4 #
5
6 test_description='Test the post-checkout hook.'
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
10 . ./test-lib.sh
11
12 test_expect_success setup '
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 &&
19 test_commit rebase-on-me &&
20 git reset --hard HEAD^ &&
21 test_commit three
22 '
23
24 test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '
25 test_when_finished "rm -f .git/post-checkout.args" &&
26 git checkout main &&
27 read old new flag <.git/post-checkout.args &&
28 test $old = $new && test $flag = 1
29 '
30
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
36 '
37
38 test_expect_success 'post-checkout receives the right args with HEAD changed ' '
39 test_when_finished "rm -f .git/post-checkout.args" &&
40 git checkout two &&
41 read old new flag <.git/post-checkout.args &&
42 test $old != $new && test $flag = 1
43 '
44
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
50 '
51
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
59 '
60
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
68 '
69
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"
74 EOF
75 git clone --template=templates . clone3 &&
76 test -f clone3/.git/post-checkout.args
77 '
78
79 test_done