3 test_description
='reference transaction hooks'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success setup
'
13 PRE_OID=$(git rev-parse PRE) &&
15 POST_OID=$(git rev-parse POST)
18 test_expect_success
'hook allows updating ref if successful' '
19 git reset --hard PRE &&
20 test_hook reference-transaction <<-\EOF &&
27 git update-ref HEAD POST &&
28 test_cmp expect actual
31 test_expect_success
'hook aborts updating ref in prepared state' '
32 git reset --hard PRE &&
33 test_hook reference-transaction <<-\EOF &&
34 if test "$1" = prepared
39 test_must_fail git update-ref HEAD POST 2>err &&
40 test_i18ngrep "ref updates aborted by hook" err
43 test_expect_success
'hook gets all queued updates in prepared state' '
44 test_when_finished "rm actual" &&
45 git reset --hard PRE &&
46 test_hook reference-transaction <<-\EOF &&
47 if test "$1" = prepared
56 $ZERO_OID $POST_OID HEAD
57 $ZERO_OID $POST_OID refs/heads/main
59 git update-ref HEAD POST <<-EOF &&
60 update HEAD $ZERO_OID $POST_OID
61 update refs/heads/main $ZERO_OID $POST_OID
63 test_cmp expect actual
66 test_expect_success
'hook gets all queued updates in committed state' '
67 test_when_finished "rm actual" &&
68 git reset --hard PRE &&
69 test_hook reference-transaction <<-\EOF &&
70 if test "$1" = committed
79 $ZERO_OID $POST_OID HEAD
80 $ZERO_OID $POST_OID refs/heads/main
82 git update-ref HEAD POST &&
83 test_cmp expect actual
86 test_expect_success
'hook gets all queued updates in aborted state' '
87 test_when_finished "rm actual" &&
88 git reset --hard PRE &&
89 test_hook reference-transaction <<-\EOF &&
90 if test "$1" = aborted
99 $ZERO_OID $POST_OID HEAD
100 $ZERO_OID $POST_OID refs/heads/main
102 git update-ref --stdin <<-EOF &&
104 update HEAD POST $ZERO_OID
105 update refs/heads/main POST $ZERO_OID
108 test_cmp expect actual
111 test_expect_success
'interleaving hook calls succeed' '
112 test_when_finished "rm -r target-repo.git" &&
114 git init --bare target-repo.git &&
116 test_hook -C target-repo.git reference-transaction <<-\EOF &&
117 echo $0 "$@" >>actual
120 test_hook -C target-repo.git update <<-\EOF &&
121 echo $0 "$@" >>actual
124 cat >expect <<-EOF &&
125 hooks/update refs/tags/PRE $ZERO_OID $PRE_OID
126 hooks/reference-transaction prepared
127 hooks/reference-transaction committed
128 hooks/update refs/tags/POST $ZERO_OID $POST_OID
129 hooks/reference-transaction prepared
130 hooks/reference-transaction committed
133 git push ./target-repo.git PRE POST &&
134 test_cmp expect target-repo.git/actual