t/README: add missing value for GIT_TEST_DEFAULT_REF_FORMAT
[git/gitster.git] / t / t5403-post-checkout-hook.sh
blobcfaae547398e0e54cfc5b8f6403d2502ac826782
1 #!/bin/sh
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
10 TEST_PASSES_SANITIZE_LEAK=true
11 . ./test-lib.sh
13 test_expect_success setup '
14 test_hook --setup 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
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
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" &&
40 git checkout two &&
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_rebase () {
53 args="$*" &&
54 test_expect_success "post-checkout is triggered on rebase $args" '
55 test_when_finished "rm -f .git/post-checkout.args" &&
56 git checkout -B rebase-test main &&
57 rm -f .git/post-checkout.args &&
58 git rebase $args rebase-on-me &&
59 read old new flag <.git/post-checkout.args &&
60 test_cmp_rev main $old &&
61 test_cmp_rev rebase-on-me $new &&
62 test $flag = 1
65 test_expect_success "post-checkout is triggered on rebase $args with fast-forward" '
66 test_when_finished "rm -f .git/post-checkout.args" &&
67 git checkout -B ff-rebase-test rebase-on-me^ &&
68 rm -f .git/post-checkout.args &&
69 git rebase $args rebase-on-me &&
70 read old new flag <.git/post-checkout.args &&
71 test_cmp_rev rebase-on-me^ $old &&
72 test_cmp_rev rebase-on-me $new &&
73 test $flag = 1
76 test_expect_success "rebase $args fast-forward branch checkout runs post-checkout hook" '
77 test_when_finished "test_might_fail git rebase --abort" &&
78 test_when_finished "rm -f .git/post-checkout.args" &&
79 git update-ref refs/heads/rebase-fast-forward three &&
80 git checkout two &&
81 rm -f .git/post-checkout.args &&
82 git rebase $args HEAD rebase-fast-forward &&
83 read old new flag <.git/post-checkout.args &&
84 test_cmp_rev two $old &&
85 test_cmp_rev three $new &&
86 test $flag = 1
89 test_expect_success "rebase $args checkout does not remove untracked files" '
90 test_when_finished "test_might_fail git rebase --abort" &&
91 test_when_finished "rm -f .git/post-checkout.args" &&
92 git update-ref refs/heads/rebase-fast-forward three &&
93 git checkout two &&
94 rm -f .git/post-checkout.args &&
95 echo untracked >three.t &&
96 test_when_finished "rm three.t" &&
97 test_must_fail git rebase $args HEAD rebase-fast-forward 2>err &&
98 grep "untracked working tree files would be overwritten by checkout" err &&
99 test_path_is_missing .git/post-checkout.args
104 test_rebase --apply &&
105 test_rebase --merge
107 test_expect_success 'post-checkout hook is triggered by clone' '
108 mkdir -p templates/hooks &&
109 write_script templates/hooks/post-checkout <<-\EOF &&
110 echo "$@" >"$GIT_DIR/post-checkout.args"
112 git clone --template=templates . clone3 &&
113 test -f clone3/.git/post-checkout.args
116 test_done