]>
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.' | |
7 | . ./test-lib.sh | |
8 | ||
9 | test_expect_success setup ' | |
10499a9d OS |
10 | mkdir -p .git/hooks && |
11 | write_script .git/hooks/post-checkout <<-\EOF && | |
12 | echo "$@" >.git/post-checkout.args | |
13 | EOF | |
14 | test_commit one && | |
15 | test_commit two && | |
8581df65 OS |
16 | test_commit rebase-on-me && |
17 | git reset --hard HEAD^ && | |
10499a9d | 18 | test_commit three |
1abbe475 JE |
19 | ' |
20 | ||
21 | test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' ' | |
10499a9d OS |
22 | test_when_finished "rm -f .git/post-checkout.args" && |
23 | git checkout master && | |
24 | read old new flag <.git/post-checkout.args && | |
7281f366 | 25 | test $old = $new && test $flag = 1 |
1abbe475 JE |
26 | ' |
27 | ||
1abbe475 | 28 | test_expect_success 'post-checkout args are correct with git checkout -b ' ' |
10499a9d OS |
29 | test_when_finished "rm -f .git/post-checkout.args" && |
30 | git checkout -b new1 && | |
31 | read old new flag <.git/post-checkout.args && | |
7281f366 | 32 | test $old = $new && test $flag = 1 |
1abbe475 JE |
33 | ' |
34 | ||
35 | test_expect_success 'post-checkout receives the right args with HEAD changed ' ' | |
10499a9d OS |
36 | test_when_finished "rm -f .git/post-checkout.args" && |
37 | git checkout two && | |
38 | read old new flag <.git/post-checkout.args && | |
7281f366 | 39 | test $old != $new && test $flag = 1 |
1abbe475 JE |
40 | ' |
41 | ||
42 | test_expect_success 'post-checkout receives the right args when not switching branches ' ' | |
10499a9d OS |
43 | test_when_finished "rm -f .git/post-checkout.args" && |
44 | git checkout master -- three.t && | |
45 | read old new flag <.git/post-checkout.args && | |
7281f366 | 46 | test $old = $new && test $flag = 0 |
1abbe475 JE |
47 | ' |
48 | ||
8581df65 OS |
49 | test_expect_success 'post-checkout is triggered on rebase' ' |
50 | test_when_finished "rm -f .git/post-checkout.args" && | |
51 | git checkout -b rebase-test master && | |
52 | rm -f .git/post-checkout.args && | |
53 | git rebase rebase-on-me && | |
54 | read old new flag <.git/post-checkout.args && | |
55 | test $old != $new && test $flag = 1 | |
56 | ' | |
57 | ||
58 | test_expect_success 'post-checkout is triggered on rebase with fast-forward' ' | |
59 | test_when_finished "rm -f .git/post-checkout.args" && | |
60 | git checkout -b ff-rebase-test rebase-on-me^ && | |
61 | rm -f .git/post-checkout.args && | |
62 | git rebase rebase-on-me && | |
63 | read old new flag <.git/post-checkout.args && | |
64 | test $old != $new && test $flag = 1 | |
65 | ' | |
66 | ||
dfa7a6c5 | 67 | test_expect_success 'post-checkout hook is triggered by clone' ' |
10499a9d OS |
68 | mkdir -p templates/hooks && |
69 | write_script templates/hooks/post-checkout <<-\EOF && | |
a250d418 | 70 | echo "$@" >"$GIT_DIR/post-checkout.args" |
10499a9d | 71 | EOF |
dfa7a6c5 JK |
72 | git clone --template=templates . clone3 && |
73 | test -f clone3/.git/post-checkout.args | |
74 | ' | |
75 | ||
1abbe475 | 76 | test_done |