rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t5403-post-checkout-hook.sh
blob978f240cdaceb4e7593adcf89136e9de9b558aa1
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-lib.sh
12 test_expect_success setup '
13 test_hook --setup post-checkout <<-\EOF &&
14 echo "$@" >.git/post-checkout.args
15 EOF
16 test_commit one &&
17 test_commit two &&
18 test_commit rebase-on-me &&
19 git reset --hard HEAD^ &&
20 test_commit three
23 test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '
24 test_when_finished "rm -f .git/post-checkout.args" &&
25 git checkout main &&
26 read old new flag <.git/post-checkout.args &&
27 test $old = $new && test $flag = 1
30 test_expect_success 'post-checkout args are correct with git checkout -b ' '
31 test_when_finished "rm -f .git/post-checkout.args" &&
32 git checkout -b new1 &&
33 read old new flag <.git/post-checkout.args &&
34 test $old = $new && test $flag = 1
37 test_expect_success 'post-checkout receives the right args with HEAD changed ' '
38 test_when_finished "rm -f .git/post-checkout.args" &&
39 git checkout two &&
40 read old new flag <.git/post-checkout.args &&
41 test $old != $new && test $flag = 1
44 test_expect_success 'post-checkout receives the right args when not switching branches ' '
45 test_when_finished "rm -f .git/post-checkout.args" &&
46 git checkout main -- three.t &&
47 read old new flag <.git/post-checkout.args &&
48 test $old = $new && test $flag = 0
51 test_rebase () {
52 args="$*" &&
53 test_expect_success "post-checkout is triggered on rebase $args" '
54 test_when_finished "rm -f .git/post-checkout.args" &&
55 git checkout -B rebase-test main &&
56 rm -f .git/post-checkout.args &&
57 git rebase $args rebase-on-me &&
58 read old new flag <.git/post-checkout.args &&
59 test_cmp_rev main $old &&
60 test_cmp_rev rebase-on-me $new &&
61 test $flag = 1
64 test_expect_success "post-checkout is triggered on rebase $args with fast-forward" '
65 test_when_finished "rm -f .git/post-checkout.args" &&
66 git checkout -B ff-rebase-test rebase-on-me^ &&
67 rm -f .git/post-checkout.args &&
68 git rebase $args rebase-on-me &&
69 read old new flag <.git/post-checkout.args &&
70 test_cmp_rev rebase-on-me^ $old &&
71 test_cmp_rev rebase-on-me $new &&
72 test $flag = 1
75 test_expect_success "rebase $args fast-forward branch checkout runs post-checkout hook" '
76 test_when_finished "test_might_fail git rebase --abort" &&
77 test_when_finished "rm -f .git/post-checkout.args" &&
78 git update-ref refs/heads/rebase-fast-forward three &&
79 git checkout two &&
80 rm -f .git/post-checkout.args &&
81 git rebase $args HEAD rebase-fast-forward &&
82 read old new flag <.git/post-checkout.args &&
83 test_cmp_rev two $old &&
84 test_cmp_rev three $new &&
85 test $flag = 1
88 test_expect_success "rebase $args checkout does not remove untracked files" '
89 test_when_finished "test_might_fail git rebase --abort" &&
90 test_when_finished "rm -f .git/post-checkout.args" &&
91 git update-ref refs/heads/rebase-fast-forward three &&
92 git checkout two &&
93 rm -f .git/post-checkout.args &&
94 echo untracked >three.t &&
95 test_when_finished "rm three.t" &&
96 test_must_fail git rebase $args HEAD rebase-fast-forward 2>err &&
97 grep "untracked working tree files would be overwritten by checkout" err &&
98 test_path_is_missing .git/post-checkout.args
103 test_rebase --apply &&
104 test_rebase --merge
106 test_expect_success 'post-checkout hook is triggered by clone' '
107 mkdir -p templates/hooks &&
108 write_script templates/hooks/post-checkout <<-\EOF &&
109 echo "$@" >"$GIT_DIR/post-checkout.args"
111 git clone --template=templates . clone3 &&
112 test -f clone3/.git/post-checkout.args
115 test_done