Merge git://git.kernel.org/pub/scm/gitk/gitk into maint
[git] / t / t5401-update-hooks.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Shawn O. Pearce
4 #
5
6 test_description='Test the update hook infrastructure.'
7 . ./test-lib.sh
8
9 test_expect_success setup '
10         echo This is a test. >a &&
11         git-update-index --add a &&
12         tree0=$(git-write-tree) &&
13         commit0=$(echo setup | git-commit-tree $tree0) &&
14         git-update-ref HEAD $commit0 &&
15         git-clone ./. victim &&
16         echo We hope it works. >a &&
17         git-update-index a &&
18         tree1=$(git-write-tree) &&
19         commit1=$(echo modify | git-commit-tree $tree1 -p $commit0) &&
20         git-update-ref HEAD $commit1
21 '
22
23 cat >victim/.git/hooks/update <<'EOF'
24 #!/bin/sh
25 echo "$@" >$GIT_DIR/update.args
26 read x; printf "$x" >$GIT_DIR/update.stdin
27 echo STDOUT update
28 echo STDERR update >&2
29 EOF
30 chmod u+x victim/.git/hooks/update
31
32 cat >victim/.git/hooks/post-update <<'EOF'
33 #!/bin/sh
34 echo "$@" >$GIT_DIR/post-update.args
35 read x; printf "$x" >$GIT_DIR/post-update.stdin
36 echo STDOUT post-update
37 echo STDERR post-update >&2
38 EOF
39 chmod u+x victim/.git/hooks/post-update
40
41 test_expect_success push '
42         git-send-pack ./victim/.git/ master >send.out 2>send.err
43 '
44
45 test_expect_success 'hooks ran' '
46         test -f victim/.git/update.args &&
47         test -f victim/.git/update.stdin &&
48         test -f victim/.git/post-update.args &&
49         test -f victim/.git/post-update.stdin
50 '
51
52 test_expect_success 'update hook arguments' '
53         echo refs/heads/master $commit0 $commit1 |
54         diff -u - victim/.git/update.args
55 '
56
57 test_expect_success 'post-update hook arguments' '
58         echo refs/heads/master |
59         diff -u - victim/.git/post-update.args
60 '
61
62 test_expect_failure 'update hook stdin is /dev/null' '
63         test -s victim/.git/update.stdin
64 '
65
66 test_expect_failure 'post-update hook stdin is /dev/null' '
67         test -s victim/.git/post-update.stdin
68 '
69
70 test_expect_failure 'send-pack produced no output' '
71         test -s send.out
72 '
73
74 test_expect_success 'send-pack stderr contains hook messages' '
75         grep "STDOUT update" send.err &&
76         grep "STDERR update" send.err &&
77         grep "STDOUT post-update" send.err &&
78         grep "STDERR post-update" send.err
79 '
80
81 test_done