]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t1416-ref-transaction-hooks.sh
refs: demonstrate excessive execution of the reference-transaction hook
[thirdparty/git.git] / t / t1416-ref-transaction-hooks.sh
index 6c941027a811a5fa2429f03b3092940b6fa2b782..0567fbdf0b2b55b651e9b181d46e94c57574fc2d 100755 (executable)
@@ -136,4 +136,68 @@ test_expect_success 'interleaving hook calls succeed' '
        test_cmp expect target-repo.git/actual
 '
 
+test_expect_success 'hook does not get called on packing refs' '
+       # Pack references first such that we are in a known state.
+       git pack-refs --all &&
+
+       write_script .git/hooks/reference-transaction <<-\EOF &&
+               echo "$@" >>actual
+               cat >>actual
+       EOF
+       rm -f actual &&
+
+       git update-ref refs/heads/unpacked-ref $POST_OID &&
+       git pack-refs --all &&
+
+       # We only expect a single hook invocation, which is the call to
+       # git-update-ref(1). But currently, packing refs will also trigger the
+       # hook.
+       cat >expect <<-EOF &&
+               prepared
+               $ZERO_OID $POST_OID refs/heads/unpacked-ref
+               committed
+               $ZERO_OID $POST_OID refs/heads/unpacked-ref
+               prepared
+               $ZERO_OID $POST_OID refs/heads/unpacked-ref
+               committed
+               $ZERO_OID $POST_OID refs/heads/unpacked-ref
+               prepared
+               $POST_OID $ZERO_OID refs/heads/unpacked-ref
+               committed
+               $POST_OID $ZERO_OID refs/heads/unpacked-ref
+       EOF
+
+       test_cmp expect actual
+'
+
+test_expect_success 'deleting packed ref calls hook once' '
+       # Create a reference and pack it.
+       git update-ref refs/heads/to-be-deleted $POST_OID &&
+       git pack-refs --all &&
+
+       write_script .git/hooks/reference-transaction <<-\EOF &&
+               echo "$@" >>actual
+               cat >>actual
+       EOF
+       rm -f actual &&
+
+       git update-ref -d refs/heads/to-be-deleted $POST_OID &&
+
+       # We only expect a single hook invocation, which is the logical
+       # deletion. But currently, we see two interleaving transactions, once
+       # for deleting the loose refs and once for deleting the packed ref.
+       cat >expect <<-EOF &&
+               prepared
+               $ZERO_OID $ZERO_OID refs/heads/to-be-deleted
+               prepared
+               $POST_OID $ZERO_OID refs/heads/to-be-deleted
+               committed
+               $ZERO_OID $ZERO_OID refs/heads/to-be-deleted
+               committed
+               $POST_OID $ZERO_OID refs/heads/to-be-deleted
+       EOF
+
+       test_cmp expect actual
+'
+
 test_done