3 test_description='tests for the peel_ref optimization of packed-refs'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 test_expect_success 'create annotated tag in refs/tags' '
11 git tag -m annotated foo
14 test_expect_success 'create annotated tag outside of refs/tags' '
15 git update-ref refs/outside/foo refs/tags/foo
18 # This matches show-ref's output
20 echo "$(git rev-parse "$1") $1"
23 test_expect_success 'set up expected show-ref output' '
25 print_ref "refs/heads/main" &&
26 print_ref "refs/outside/foo" &&
27 print_ref "refs/outside/foo^{}" &&
28 print_ref "refs/tags/base" &&
29 print_ref "refs/tags/foo" &&
30 print_ref "refs/tags/foo^{}"
34 test_expect_success 'refs are peeled outside of refs/tags (loose)' '
35 git show-ref -d >actual &&
36 test_cmp expect actual
39 test_expect_success 'refs are peeled outside of refs/tags (packed)' '
40 git pack-refs --all &&
41 git show-ref -d >actual &&
42 test_cmp expect actual
45 test_expect_success 'create old-style pack-refs without fully-peeled' '
46 # Git no longer writes without fully-peeled, so we just write our own
47 # from scratch; we could also munge the existing file to remove the
48 # fully-peeled bits, but that seems even more prone to failure,
49 # especially if the format ever changes again. At least this way we
50 # know we are emulating exactly what an older git would have written.
52 echo "# pack-refs with: peeled " &&
53 print_ref "refs/heads/main" &&
54 print_ref "refs/outside/foo" &&
55 print_ref "refs/tags/base" &&
56 print_ref "refs/tags/foo" &&
57 echo "^$(git rev-parse "refs/tags/foo^{}")"
59 mv tmp .git/packed-refs
62 test_expect_success 'refs are peeled outside of refs/tags (old packed)' '
63 git show-ref -d >actual &&
64 test_cmp expect actual
67 test_expect_success 'peeled refs survive deletion of packed ref' '
68 git pack-refs --all &&
69 cp .git/packed-refs fully-peeled &&
71 git pack-refs --all &&
72 git branch -d yadda &&
73 test_cmp fully-peeled .git/packed-refs