]>
Commit | Line | Data |
---|---|---|
1abbe475 JE |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Josh England | |
4 | # | |
5 | ||
6 | test_description='Test the post-checkout hook.' | |
966b4be2 | 7 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
8 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
9 | ||
1abbe475 JE |
10 | . ./test-lib.sh |
11 | ||
12 | test_expect_success setup ' | |
bef805b7 | 13 | test_hook --setup post-checkout <<-\EOF && |
10499a9d OS |
14 | echo "$@" >.git/post-checkout.args |
15 | EOF | |
16 | test_commit one && | |
17 | test_commit two && | |
8581df65 OS |
18 | test_commit rebase-on-me && |
19 | git reset --hard HEAD^ && | |
10499a9d | 20 | test_commit three |
1abbe475 JE |
21 | ' |
22 | ||
23 | test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' ' | |
10499a9d | 24 | test_when_finished "rm -f .git/post-checkout.args" && |
966b4be2 | 25 | git checkout main && |
10499a9d | 26 | read old new flag <.git/post-checkout.args && |
7281f366 | 27 | test $old = $new && test $flag = 1 |
1abbe475 JE |
28 | ' |
29 | ||
1abbe475 | 30 | test_expect_success 'post-checkout args are correct with git checkout -b ' ' |
10499a9d OS |
31 | test_when_finished "rm -f .git/post-checkout.args" && |
32 | git checkout -b new1 && | |
33 | read old new flag <.git/post-checkout.args && | |
7281f366 | 34 | test $old = $new && test $flag = 1 |
1abbe475 JE |
35 | ' |
36 | ||
37 | test_expect_success 'post-checkout receives the right args with HEAD changed ' ' | |
10499a9d OS |
38 | test_when_finished "rm -f .git/post-checkout.args" && |
39 | git checkout two && | |
40 | read old new flag <.git/post-checkout.args && | |
7281f366 | 41 | test $old != $new && test $flag = 1 |
1abbe475 JE |
42 | ' |
43 | ||
44 | test_expect_success 'post-checkout receives the right args when not switching branches ' ' | |
10499a9d | 45 | test_when_finished "rm -f .git/post-checkout.args" && |
966b4be2 | 46 | git checkout main -- three.t && |
10499a9d | 47 | read old new flag <.git/post-checkout.args && |
7281f366 | 48 | test $old = $new && test $flag = 0 |
1abbe475 JE |
49 | ' |
50 | ||
bd55eee0 PW |
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 | |
62 | ' | |
8581df65 | 63 | |
bd55eee0 PW |
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 | |
73 | ' | |
69f4c230 PW |
74 | |
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 | |
86 | ' | |
ab2fba08 PW |
87 | |
88 | test_expect_success "rebase $args checkout does not remove untracked files" ' | |
89 | test_when_finished "test_might_fail git rebase --abort" && | |
4840002a | 90 | test_when_finished "rm -f .git/post-checkout.args" && |
ab2fba08 PW |
91 | git update-ref refs/heads/rebase-fast-forward three && |
92 | git checkout two && | |
4840002a | 93 | rm -f .git/post-checkout.args && |
ab2fba08 PW |
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 && | |
4840002a PW |
97 | grep "untracked working tree files would be overwritten by checkout" err && |
98 | test_path_is_missing .git/post-checkout.args | |
99 | ||
ab2fba08 | 100 | ' |
bd55eee0 PW |
101 | } |
102 | ||
103 | test_rebase --apply && | |
104 | test_rebase --merge | |
8581df65 | 105 | |
dfa7a6c5 | 106 | test_expect_success 'post-checkout hook is triggered by clone' ' |
10499a9d OS |
107 | mkdir -p templates/hooks && |
108 | write_script templates/hooks/post-checkout <<-\EOF && | |
a250d418 | 109 | echo "$@" >"$GIT_DIR/post-checkout.args" |
10499a9d | 110 | EOF |
dfa7a6c5 JK |
111 | git clone --template=templates . clone3 && |
112 | test -f clone3/.git/post-checkout.args | |
113 | ' | |
114 | ||
1abbe475 | 115 | test_done |