Merge branch 'lw/daemon-log-destination'
[git] / t / t3211-peel-ref.sh
1 #!/bin/sh
2
3 test_description='tests for the peel_ref optimization of packed-refs'
4 . ./test-lib.sh
5
6 test_expect_success 'create annotated tag in refs/tags' '
7         test_commit base &&
8         git tag -m annotated foo
9 '
10
11 test_expect_success 'create annotated tag outside of refs/tags' '
12         git update-ref refs/outside/foo refs/tags/foo
13 '
14
15 # This matches show-ref's output
16 print_ref() {
17         echo "$(git rev-parse "$1") $1"
18 }
19
20 test_expect_success 'set up expected show-ref output' '
21         {
22                 print_ref "refs/heads/master" &&
23                 print_ref "refs/outside/foo" &&
24                 print_ref "refs/outside/foo^{}" &&
25                 print_ref "refs/tags/base" &&
26                 print_ref "refs/tags/foo" &&
27                 print_ref "refs/tags/foo^{}"
28         } >expect
29 '
30
31 test_expect_success 'refs are peeled outside of refs/tags (loose)' '
32         git show-ref -d >actual &&
33         test_cmp expect actual
34 '
35
36 test_expect_success 'refs are peeled outside of refs/tags (packed)' '
37         git pack-refs --all &&
38         git show-ref -d >actual &&
39         test_cmp expect actual
40 '
41
42 test_expect_success 'create old-style pack-refs without fully-peeled' '
43         # Git no longer writes without fully-peeled, so we just write our own
44         # from scratch; we could also munge the existing file to remove the
45         # fully-peeled bits, but that seems even more prone to failure,
46         # especially if the format ever changes again. At least this way we
47         # know we are emulating exactly what an older git would have written.
48         {
49                 echo "# pack-refs with: peeled " &&
50                 print_ref "refs/heads/master" &&
51                 print_ref "refs/outside/foo" &&
52                 print_ref "refs/tags/base" &&
53                 print_ref "refs/tags/foo" &&
54                 echo "^$(git rev-parse "refs/tags/foo^{}")"
55         } >tmp &&
56         mv tmp .git/packed-refs
57 '
58
59 test_expect_success 'refs are peeled outside of refs/tags (old packed)' '
60         git show-ref -d >actual &&
61         test_cmp expect actual
62 '
63
64 test_expect_success 'peeled refs survive deletion of packed ref' '
65         git pack-refs --all &&
66         cp .git/packed-refs fully-peeled &&
67         git branch yadda &&
68         git pack-refs --all &&
69         git branch -d yadda &&
70         test_cmp fully-peeled .git/packed-refs
71 '
72
73 test_done