@@ -20,13 +20,26 @@ test_expect_success 'hook allows updating ref if successful' '
2020 echo "$*" >>actual
2121 EOF
2222 cat >expect <<-EOF &&
23+ preparing
2324 prepared
2425 committed
2526 EOF
2627 git update-ref HEAD POST &&
2728 test_cmp expect actual
2829'
2930
31+ test_expect_success ' hook aborts updating ref in preparing state' '
32+ git reset --hard PRE &&
33+ test_hook reference-transaction <<-\EOF &&
34+ if test "$1" = preparing
35+ then
36+ exit 1
37+ fi
38+ EOF
39+ test_must_fail git update-ref HEAD POST 2>err &&
40+ test_grep "ref updates aborted by preparing hook" err
41+ '
42+
3043test_expect_success ' hook aborts updating ref in prepared state' '
3144 git reset --hard PRE &&
3245 test_hook reference-transaction <<-\EOF &&
@@ -36,7 +49,7 @@ test_expect_success 'hook aborts updating ref in prepared state' '
3649 fi
3750 EOF
3851 test_must_fail git update-ref HEAD POST 2>err &&
39- test_grep "ref updates aborted by hook" err
52+ test_grep "ref updates aborted by prepared hook" err
4053'
4154
4255test_expect_success ' hook gets all queued updates in prepared state' '
@@ -121,6 +134,7 @@ test_expect_success 'interleaving hook calls succeed' '
121134 cat >expect <<-EOF &&
122135 hooks/update refs/tags/PRE $ZERO_OID $PRE_OID
123136 hooks/update refs/tags/POST $ZERO_OID $POST_OID
137+ hooks/reference-transaction preparing
124138 hooks/reference-transaction prepared
125139 hooks/reference-transaction committed
126140 EOF
@@ -143,6 +157,8 @@ test_expect_success 'hook captures git-symbolic-ref updates' '
143157 git symbolic-ref refs/heads/symref refs/heads/main &&
144158
145159 cat >expect <<-EOF &&
160+ preparing
161+ $ZERO_OID ref:refs/heads/main refs/heads/symref
146162 prepared
147163 $ZERO_OID ref:refs/heads/main refs/heads/symref
148164 committed
@@ -171,14 +187,20 @@ test_expect_success 'hook gets all queued symref updates' '
171187 # In the files backend, "delete" also triggers an additional transaction
172188 # update on the packed-refs backend, which constitutes additional reflog
173189 # entries.
190+ cat >expect <<-EOF &&
191+ preparing
192+ ref:refs/heads/main $ZERO_OID refs/heads/symref
193+ ref:refs/heads/main $ZERO_OID refs/heads/symrefd
194+ $ZERO_OID ref:refs/heads/main refs/heads/symrefc
195+ ref:refs/heads/main ref:refs/heads/branch refs/heads/symrefu
196+ EOF
197+
174198 if test_have_prereq REFFILES
175199 then
176- cat >expect <<-EOF
200+ cat >> expect <<-EOF
177201 aborted
178202 $ZERO_OID $ZERO_OID refs/heads/symrefd
179203 EOF
180- else
181- >expect
182204 fi &&
183205
184206 cat >>expect <<-EOF &&
0 commit comments