1#!/bin/sh
2#
3# Copyright (c) 2006 Shawn O. Pearce
4#
56
test_description='Test the update hook infrastructure.'
7. ./test-lib.sh
89
test_expect_success setup '
10echo This is a test. >a &&
11git-update-index --add a &&
12tree0=$(git-write-tree) &&
13commit0=$(echo setup | git-commit-tree $tree0) &&
14git-update-ref HEAD $commit0 &&
15git-clone ./. victim &&
16echo We hope it works. >a &&
17git-update-index a &&
18tree1=$(git-write-tree) &&
19commit1=$(echo modify | git-commit-tree $tree1 -p $commit0) &&
20git-update-ref HEAD $commit1
21'
2223
cat >victim/.git/hooks/update <<'EOF'
24#!/bin/sh
25echo "$@" >$GIT_DIR/update.args
26read x; printf "$x" >$GIT_DIR/update.stdin
27echo STDOUT update
28echo STDERR update >&2
29EOF
30chmod u+x victim/.git/hooks/update
3132
cat >victim/.git/hooks/post-update <<'EOF'
33#!/bin/sh
34echo "$@" >$GIT_DIR/post-update.args
35read x; printf "$x" >$GIT_DIR/post-update.stdin
36echo STDOUT post-update
37echo STDERR post-update >&2
38EOF
39chmod u+x victim/.git/hooks/post-update
4041
test_expect_success push '
42git-send-pack ./victim/.git/ master >send.out 2>send.err
43'
4445
test_expect_success 'hooks ran' '
46test -f victim/.git/update.args &&
47test -f victim/.git/update.stdin &&
48test -f victim/.git/post-update.args &&
49test -f victim/.git/post-update.stdin
50'
5152
test_expect_success 'update hook arguments' '
53echo refs/heads/master $commit0 $commit1 |
54diff -u - victim/.git/update.args
55'
5657
test_expect_success 'post-update hook arguments' '
58echo refs/heads/master |
59diff -u - victim/.git/post-update.args
60'
6162
test_expect_failure 'update hook stdin is /dev/null' '
63test -s victim/.git/update.stdin
64'
6566
test_expect_failure 'post-update hook stdin is /dev/null' '
67test -s victim/.git/post-update.stdin
68'
6970
test_expect_failure 'send-pack produced no output' '
71test -s send.out
72'
7374
test_expect_success 'send-pack stderr contains hook messages' '
75grep "STDOUT update" send.err &&
76grep "STDERR update" send.err &&
77grep "STDOUT post-update" send.err &&
78grep "STDERR post-update" send.err
79'
8081
test_done