Fourth batch
[git/raj.git] / t / t1416-ref-transaction-hooks.sh
blobda58d867a56f57360c7090bced0911350bc5fef0
1 #!/bin/sh
3 test_description='reference transaction hooks'
5 . ./test-lib.sh
7 test_expect_success setup '
8 mkdir -p .git/hooks &&
9 test_commit PRE &&
10 test_commit POST &&
11 POST_OID=$(git rev-parse POST)
14 test_expect_success 'hook allows updating ref if successful' '
15 test_when_finished "rm .git/hooks/reference-transaction" &&
16 git reset --hard PRE &&
17 write_script .git/hooks/reference-transaction <<-\EOF &&
18 echo "$*" >>actual
19 EOF
20 cat >expect <<-EOF &&
21 prepared
22 committed
23 EOF
24 git update-ref HEAD POST &&
25 test_cmp expect actual
28 test_expect_success 'hook aborts updating ref in prepared state' '
29 test_when_finished "rm .git/hooks/reference-transaction" &&
30 git reset --hard PRE &&
31 write_script .git/hooks/reference-transaction <<-\EOF &&
32 if test "$1" = prepared
33 then
34 exit 1
36 EOF
37 test_must_fail git update-ref HEAD POST 2>err &&
38 test_i18ngrep "ref updates aborted by hook" err
41 test_expect_success 'hook gets all queued updates in prepared state' '
42 test_when_finished "rm .git/hooks/reference-transaction actual" &&
43 git reset --hard PRE &&
44 write_script .git/hooks/reference-transaction <<-\EOF &&
45 if test "$1" = prepared
46 then
47 while read -r line
49 printf "%s\n" "$line"
50 done >actual
52 EOF
53 cat >expect <<-EOF &&
54 $ZERO_OID $POST_OID HEAD
55 $ZERO_OID $POST_OID refs/heads/master
56 EOF
57 git update-ref HEAD POST <<-EOF &&
58 update HEAD $ZERO_OID $POST_OID
59 update refs/heads/master $ZERO_OID $POST_OID
60 EOF
61 test_cmp expect actual
64 test_expect_success 'hook gets all queued updates in committed state' '
65 test_when_finished "rm .git/hooks/reference-transaction actual" &&
66 git reset --hard PRE &&
67 write_script .git/hooks/reference-transaction <<-\EOF &&
68 if test "$1" = committed
69 then
70 while read -r line
72 printf "%s\n" "$line"
73 done >actual
75 EOF
76 cat >expect <<-EOF &&
77 $ZERO_OID $POST_OID HEAD
78 $ZERO_OID $POST_OID refs/heads/master
79 EOF
80 git update-ref HEAD POST &&
81 test_cmp expect actual
84 test_expect_success 'hook gets all queued updates in aborted state' '
85 test_when_finished "rm .git/hooks/reference-transaction actual" &&
86 git reset --hard PRE &&
87 write_script .git/hooks/reference-transaction <<-\EOF &&
88 if test "$1" = aborted
89 then
90 while read -r line
92 printf "%s\n" "$line"
93 done >actual
95 EOF
96 cat >expect <<-EOF &&
97 $ZERO_OID $POST_OID HEAD
98 $ZERO_OID $POST_OID refs/heads/master
99 EOF
100 git update-ref --stdin <<-EOF &&
101 start
102 update HEAD POST $ZERO_OID
103 update refs/heads/master POST $ZERO_OID
104 abort
106 test_cmp expect actual
109 test_done