3 # Copyright (c) 2006 Josh England
6 test_description
='Test the post-checkout hook.'
9 test_expect_success setup
'
10 mkdir -p .git/hooks &&
11 write_script .git/hooks/post-checkout <<-\EOF &&
12 echo "$@" >.git/post-checkout.args
16 test_commit rebase-on-me &&
17 git reset --hard HEAD^ &&
21 test_expect_success
'post-checkout receives the right arguments with HEAD unchanged ' '
22 test_when_finished "rm -f .git/post-checkout.args" &&
23 git checkout master &&
24 read old new flag <.git/post-checkout.args &&
25 test $old = $new && test $flag = 1
28 test_expect_success
'post-checkout args are correct with git checkout -b ' '
29 test_when_finished "rm -f .git/post-checkout.args" &&
30 git checkout -b new1 &&
31 read old new flag <.git/post-checkout.args &&
32 test $old = $new && test $flag = 1
35 test_expect_success
'post-checkout receives the right args with HEAD changed ' '
36 test_when_finished "rm -f .git/post-checkout.args" &&
38 read old new flag <.git/post-checkout.args &&
39 test $old != $new && test $flag = 1
42 test_expect_success
'post-checkout receives the right args when not switching branches ' '
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 &&
46 test $old = $new && test $flag = 0
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
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
67 test_expect_success
'post-checkout hook is triggered by clone' '
68 mkdir -p templates/hooks &&
69 write_script templates/hooks/post-checkout <<-\EOF &&
70 echo "$@" >"$GIT_DIR/post-checkout.args"
72 git clone --template=templates . clone3 &&
73 test -f clone3/.git/post-checkout.args