Skip to content

Commit 2ce8254

Browse files
pks-tgitster
authored andcommitted
refs: demonstrate excessive execution of the reference-transaction hook
Add tests which demonstate that we're executing the reference-transaction hook too often in some cases, which thus leaks implementation details about the reference store's implementation itself. Behaviour will be fixed in follow-up commits. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 958fbc7 commit 2ce8254

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

t/t1416-ref-transaction-hooks.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,68 @@ test_expect_success 'interleaving hook calls succeed' '
136136
test_cmp expect target-repo.git/actual
137137
'
138138

139+
test_expect_success 'hook does not get called on packing refs' '
140+
# Pack references first such that we are in a known state.
141+
git pack-refs --all &&
142+
143+
write_script .git/hooks/reference-transaction <<-\EOF &&
144+
echo "$@" >>actual
145+
cat >>actual
146+
EOF
147+
rm -f actual &&
148+
149+
git update-ref refs/heads/unpacked-ref $POST_OID &&
150+
git pack-refs --all &&
151+
152+
# We only expect a single hook invocation, which is the call to
153+
# git-update-ref(1). But currently, packing refs will also trigger the
154+
# hook.
155+
cat >expect <<-EOF &&
156+
prepared
157+
$ZERO_OID $POST_OID refs/heads/unpacked-ref
158+
committed
159+
$ZERO_OID $POST_OID refs/heads/unpacked-ref
160+
prepared
161+
$ZERO_OID $POST_OID refs/heads/unpacked-ref
162+
committed
163+
$ZERO_OID $POST_OID refs/heads/unpacked-ref
164+
prepared
165+
$POST_OID $ZERO_OID refs/heads/unpacked-ref
166+
committed
167+
$POST_OID $ZERO_OID refs/heads/unpacked-ref
168+
EOF
169+
170+
test_cmp expect actual
171+
'
172+
173+
test_expect_success 'deleting packed ref calls hook once' '
174+
# Create a reference and pack it.
175+
git update-ref refs/heads/to-be-deleted $POST_OID &&
176+
git pack-refs --all &&
177+
178+
write_script .git/hooks/reference-transaction <<-\EOF &&
179+
echo "$@" >>actual
180+
cat >>actual
181+
EOF
182+
rm -f actual &&
183+
184+
git update-ref -d refs/heads/to-be-deleted $POST_OID &&
185+
186+
# We only expect a single hook invocation, which is the logical
187+
# deletion. But currently, we see two interleaving transactions, once
188+
# for deleting the loose refs and once for deleting the packed ref.
189+
cat >expect <<-EOF &&
190+
prepared
191+
$ZERO_OID $ZERO_OID refs/heads/to-be-deleted
192+
prepared
193+
$POST_OID $ZERO_OID refs/heads/to-be-deleted
194+
committed
195+
$ZERO_OID $ZERO_OID refs/heads/to-be-deleted
196+
committed
197+
$POST_OID $ZERO_OID refs/heads/to-be-deleted
198+
EOF
199+
200+
test_cmp expect actual
201+
'
202+
139203
test_done

0 commit comments

Comments
 (0)