3 test_description='reference transaction hooks'
7 test_expect_success setup '
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 &&
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
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
54 $ZERO_OID $POST_OID HEAD
55 $ZERO_OID $POST_OID refs/heads/master
57 git update-ref HEAD POST <<-EOF &&
58 update HEAD $ZERO_OID $POST_OID
59 update refs/heads/master $ZERO_OID $POST_OID
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
77 $ZERO_OID $POST_OID HEAD
78 $ZERO_OID $POST_OID refs/heads/master
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
97 $ZERO_OID $POST_OID HEAD
98 $ZERO_OID $POST_OID refs/heads/master
100 git update-ref --stdin <<-EOF &&
102 update HEAD POST $ZERO_OID
103 update refs/heads/master POST $ZERO_OID
106 test_cmp expect actual