git-svn: fix a regression in dcommit that caused empty log messages
[alt-git.git] / t / t5401-update-hooks.sh
blob0514056ca6e8e54101b378cafd76b22a81df0ff5
1 #!/bin/sh
3 # Copyright (c) 2006 Shawn O. Pearce
6 test_description='Test the update hook infrastructure.'
7 . ./test-lib.sh
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
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
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
41 test_expect_success push '
42 git-send-pack ./victim/.git/ master >send.out 2>send.err
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
52 test_expect_success 'update hook arguments' '
53 echo refs/heads/master $commit0 $commit1 |
54 diff -u - victim/.git/update.args
57 test_expect_success 'post-update hook arguments' '
58 echo refs/heads/master |
59 diff -u - victim/.git/post-update.args
62 test_expect_failure 'update hook stdin is /dev/null' '
63 test -s victim/.git/update.stdin
66 test_expect_failure 'post-update hook stdin is /dev/null' '
67 test -s victim/.git/post-update.stdin
70 test_expect_failure 'send-pack produced no output' '
71 test -s send.out
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
81 test_done