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