Merge branch 'ta/hash-function-transition-doc'
[git/debian.git] / t / t3211-peel-ref.sh
blob37b9d26f4b6ba88396a2aaaecd4675470cfaa581
1 #!/bin/sh
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
7 . ./test-lib.sh
9 test_expect_success 'create annotated tag in refs/tags' '
10 test_commit base &&
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
19 print_ref() {
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^{}"
31 } >expect
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^{}")"
58 } >tmp &&
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 &&
70 git branch yadda &&
71 git pack-refs --all &&
72 git branch -d yadda &&
73 test_cmp fully-peeled .git/packed-refs
76 test_done