1#!/bin/sh
2
3test_description='avoid rewriting packed-refs unnecessarily'
4
5. ./test-lib.sh
6
7# Add an identifying mark to the packed-refs file header line. This
8# shouldn't upset readers, and it should be omitted if the file is
9# ever rewritten.
10mark_packed_refs () {
11 sed -e "s/^\(#.*\)/\1 t1409 /" <.git/packed-refs >.git/packed-refs.new &&
12 mv .git/packed-refs.new .git/packed-refs
13}
14
15# Verify that the packed-refs file is still marked.
16check_packed_refs_marked () {
17 grep -q '^#.* t1409 ' .git/packed-refs
18}
19
20test_expect_success 'setup' '
21 git commit --allow-empty -m "Commit A" &&
22 A=$(git rev-parse HEAD) &&
23 git commit --allow-empty -m "Commit B" &&
24 B=$(git rev-parse HEAD) &&
25 git commit --allow-empty -m "Commit C" &&
26 C=$(git rev-parse HEAD)
27'
28
29test_expect_success 'do not create packed-refs file gratuitously' '
30 test_must_fail test -f .git/packed-refs &&
31 git update-ref refs/heads/foo $A &&
32 test_must_fail test -f .git/packed-refs &&
33 git update-ref refs/heads/foo $B &&
34 test_must_fail test -f .git/packed-refs &&
35 git update-ref refs/heads/foo $C $B &&
36 test_must_fail test -f .git/packed-refs &&
37 git update-ref -d refs/heads/foo &&
38 test_must_fail test -f .git/packed-refs
39'
40
41test_expect_success 'check that marking the packed-refs file works' '
42 git for-each-ref >expected &&
43 git pack-refs --all &&
44 mark_packed_refs &&
45 check_packed_refs_marked &&
46 git for-each-ref >actual &&
47 test_cmp expected actual &&
48 git pack-refs --all &&
49 test_must_fail check_packed_refs_marked &&
50 git for-each-ref >actual2 &&
51 test_cmp expected actual2
52'
53
54test_expect_success 'leave packed-refs untouched on update of packed' '
55 git update-ref refs/heads/packed-update $A &&
56 git pack-refs --all &&
57 mark_packed_refs &&
58 git update-ref refs/heads/packed-update $B &&
59 check_packed_refs_marked
60'
61
62test_expect_success 'leave packed-refs untouched on checked update of packed' '
63 git update-ref refs/heads/packed-checked-update $A &&
64 git pack-refs --all &&
65 mark_packed_refs &&
66 git update-ref refs/heads/packed-checked-update $B $A &&
67 check_packed_refs_marked
68'
69
70test_expect_success 'leave packed-refs untouched on verify of packed' '
71 git update-ref refs/heads/packed-verify $A &&
72 git pack-refs --all &&
73 mark_packed_refs &&
74 echo "verify refs/heads/packed-verify $A" | git update-ref --stdin &&
75 check_packed_refs_marked
76'
77
78test_expect_success 'touch packed-refs on delete of packed' '
79 git update-ref refs/heads/packed-delete $A &&
80 git pack-refs --all &&
81 mark_packed_refs &&
82 git update-ref -d refs/heads/packed-delete &&
83 test_must_fail check_packed_refs_marked
84'
85
86test_expect_success 'leave packed-refs untouched on update of loose' '
87 git pack-refs --all &&
88 git update-ref refs/heads/loose-update $A &&
89 mark_packed_refs &&
90 git update-ref refs/heads/loose-update $B &&
91 check_packed_refs_marked
92'
93
94test_expect_success 'leave packed-refs untouched on checked update of loose' '
95 git pack-refs --all &&
96 git update-ref refs/heads/loose-checked-update $A &&
97 mark_packed_refs &&
98 git update-ref refs/heads/loose-checked-update $B $A &&
99 check_packed_refs_marked
100'
101
102test_expect_success 'leave packed-refs untouched on verify of loose' '
103 git pack-refs --all &&
104 git update-ref refs/heads/loose-verify $A &&
105 mark_packed_refs &&
106 echo "verify refs/heads/loose-verify $A" | git update-ref --stdin &&
107 check_packed_refs_marked
108'
109
110test_expect_success 'leave packed-refs untouched on delete of loose' '
111 git pack-refs --all &&
112 git update-ref refs/heads/loose-delete $A &&
113 mark_packed_refs &&
114 git update-ref -d refs/heads/loose-delete &&
115 check_packed_refs_marked
116'
117
118test_done