]>
Commit | Line | Data |
---|---|---|
27086d0f SP |
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) && | |
27086d0f SP |
14 | echo We hope it works. >a && |
15 | git-update-index a && | |
16 | tree1=$(git-write-tree) && | |
17 | commit1=$(echo modify | git-commit-tree $tree1 -p $commit0) && | |
05ef58ec SP |
18 | git-update-ref refs/heads/master $commit0 && |
19 | git-update-ref refs/heads/tofail $commit1 && | |
20 | git-clone ./. victim && | |
21 | GIT_DIR=victim/.git git-update-ref refs/heads/tofail $commit1 && | |
22 | git-update-ref refs/heads/master $commit1 && | |
23 | git-update-ref refs/heads/tofail $commit0 | |
27086d0f SP |
24 | ' |
25 | ||
05ef58ec SP |
26 | cat >victim/.git/hooks/pre-receive <<'EOF' |
27 | #!/bin/sh | |
28 | echo "$@" >>$GIT_DIR/pre-receive.args | |
29 | read x; printf "$x" >$GIT_DIR/pre-receive.stdin | |
30 | echo STDOUT pre-receive | |
31 | echo STDERR pre-receive >&2 | |
32 | EOF | |
33 | chmod u+x victim/.git/hooks/pre-receive | |
34 | ||
27086d0f SP |
35 | cat >victim/.git/hooks/update <<'EOF' |
36 | #!/bin/sh | |
05ef58ec | 37 | echo "$@" >>$GIT_DIR/update.args |
2aad957a | 38 | read x; printf "$x" >$GIT_DIR/update.stdin |
05ef58ec SP |
39 | echo STDOUT update $1 |
40 | echo STDERR update $1 >&2 | |
41 | test "$1" = refs/heads/master || exit | |
27086d0f SP |
42 | EOF |
43 | chmod u+x victim/.git/hooks/update | |
44 | ||
05ef58ec SP |
45 | cat >victim/.git/hooks/post-receive <<'EOF' |
46 | #!/bin/sh | |
47 | echo "$@" >>$GIT_DIR/post-receive.args | |
48 | read x; printf "$x" >$GIT_DIR/post-receive.stdin | |
49 | echo STDOUT post-receive | |
50 | echo STDERR post-receive >&2 | |
51 | EOF | |
52 | chmod u+x victim/.git/hooks/post-receive | |
53 | ||
27086d0f SP |
54 | cat >victim/.git/hooks/post-update <<'EOF' |
55 | #!/bin/sh | |
05ef58ec | 56 | echo "$@" >>$GIT_DIR/post-update.args |
2aad957a | 57 | read x; printf "$x" >$GIT_DIR/post-update.stdin |
27086d0f SP |
58 | echo STDOUT post-update |
59 | echo STDERR post-update >&2 | |
60 | EOF | |
61 | chmod u+x victim/.git/hooks/post-update | |
62 | ||
05ef58ec SP |
63 | test_expect_failure push ' |
64 | git-send-pack --force ./victim/.git master tofail >send.out 2>send.err | |
65 | ' | |
66 | ||
67 | test_expect_success 'updated as expected' ' | |
68 | test $(GIT_DIR=victim/.git git-rev-parse master) = $commit1 && | |
69 | test $(GIT_DIR=victim/.git git-rev-parse tofail) = $commit1 | |
27086d0f SP |
70 | ' |
71 | ||
72 | test_expect_success 'hooks ran' ' | |
05ef58ec SP |
73 | test -f victim/.git/pre-receive.args && |
74 | test -f victim/.git/pre-receive.stdin && | |
27086d0f SP |
75 | test -f victim/.git/update.args && |
76 | test -f victim/.git/update.stdin && | |
05ef58ec SP |
77 | test -f victim/.git/post-receive.args && |
78 | test -f victim/.git/post-receive.stdin && | |
27086d0f SP |
79 | test -f victim/.git/post-update.args && |
80 | test -f victim/.git/post-update.stdin | |
81 | ' | |
82 | ||
05ef58ec SP |
83 | test_expect_success 'pre-receive hook arguments' ' |
84 | echo \ | |
85 | refs/heads/master $commit0 $commit1 \ | |
86 | refs/heads/tofail $commit1 $commit0 \ | |
cf6981d4 | 87 | | git diff - victim/.git/pre-receive.args |
05ef58ec SP |
88 | ' |
89 | ||
27086d0f | 90 | test_expect_success 'update hook arguments' ' |
05ef58ec SP |
91 | (echo refs/heads/master $commit0 $commit1; |
92 | echo refs/heads/tofail $commit1 $commit0 | |
cf6981d4 | 93 | ) | git diff - victim/.git/update.args |
05ef58ec SP |
94 | ' |
95 | ||
96 | test_expect_success 'post-receive hook arguments' ' | |
27086d0f | 97 | echo refs/heads/master $commit0 $commit1 | |
cf6981d4 | 98 | git diff - victim/.git/post-receive.args |
27086d0f SP |
99 | ' |
100 | ||
101 | test_expect_success 'post-update hook arguments' ' | |
102 | echo refs/heads/master | | |
5bd74506 | 103 | git diff - victim/.git/post-update.args |
27086d0f SP |
104 | ' |
105 | ||
05ef58ec SP |
106 | test_expect_success 'all hook stdin is /dev/null' ' |
107 | ! test -s victim/.git/pre-receive.stdin && | |
108 | ! test -s victim/.git/update.stdin && | |
109 | ! test -s victim/.git/post-receive.stdin && | |
110 | ! test -s victim/.git/post-update.stdin | |
27086d0f SP |
111 | ' |
112 | ||
113 | test_expect_failure 'send-pack produced no output' ' | |
114 | test -s send.out | |
115 | ' | |
116 | ||
05ef58ec SP |
117 | cat <<EOF >expect |
118 | STDOUT pre-receive | |
119 | STDERR pre-receive | |
120 | STDOUT update refs/heads/master | |
121 | STDERR update refs/heads/master | |
122 | STDOUT update refs/heads/tofail | |
123 | STDERR update refs/heads/tofail | |
124 | STDOUT post-receive | |
125 | STDERR post-receive | |
126 | STDOUT post-update | |
127 | STDERR post-update | |
128 | EOF | |
27086d0f | 129 | test_expect_success 'send-pack stderr contains hook messages' ' |
05ef58ec | 130 | egrep ^STD send.err >actual && |
cf6981d4 | 131 | git diff - actual <expect |
27086d0f SP |
132 | ' |
133 | ||
134 | test_done |