1#!/bin/sh
2#
3# Copyright (c) 2006 Josh England
4#
5
6test_description='Test the post-checkout hook.'
7. ./test-lib.sh
8
9test_expect_success setup '
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 &&
16 test_commit three
17'
18
19test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '
20 test_when_finished "rm -f .git/post-checkout.args" &&
21 git checkout master &&
22 read old new flag <.git/post-checkout.args &&
23 test $old = $new && test $flag = 1
24'
25
26test_expect_success 'post-checkout args are correct with git checkout -b ' '
27 test_when_finished "rm -f .git/post-checkout.args" &&
28 git checkout -b new1 &&
29 read old new flag <.git/post-checkout.args &&
30 test $old = $new && test $flag = 1
31'
32
33test_expect_success 'post-checkout receives the right args with HEAD changed ' '
34 test_when_finished "rm -f .git/post-checkout.args" &&
35 git checkout two &&
36 read old new flag <.git/post-checkout.args &&
37 test $old != $new && test $flag = 1
38'
39
40test_expect_success 'post-checkout receives the right args when not switching branches ' '
41 test_when_finished "rm -f .git/post-checkout.args" &&
42 git checkout master -- three.t &&
43 read old new flag <.git/post-checkout.args &&
44 test $old = $new && test $flag = 0
45'
46
47test_expect_success 'post-checkout hook is triggered by clone' '
48 mkdir -p templates/hooks &&
49 write_script templates/hooks/post-checkout <<-\EOF &&
50 echo "$@" >$GIT_DIR/post-checkout.args
51 EOF
52 git clone --template=templates . clone3 &&
53 test -f clone3/.git/post-checkout.args
54'
55
56test_done