]>
Commit | Line | Data |
---|---|---|
919a3c98 CC |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Amos Waterland | |
4 | # Copyright (c) 2006 Christian Couder | |
5 | # | |
6 | ||
7 | test_description='git pack-refs should not change the branch semantic | |
8 | ||
9 | This test runs git pack-refs and git show-ref and checks that the branch | |
10 | semantic is still the same. | |
11 | ' | |
d6c6b108 | 12 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
13 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
14 | ||
919a3c98 CC |
15 | . ./test-lib.sh |
16 | ||
cbe73331 JK |
17 | test_expect_success 'enable reflogs' ' |
18 | git config core.logallrefupdates true | |
19 | ' | |
3b463c3f | 20 | |
919a3c98 CC |
21 | test_expect_success \ |
22 | 'prepare a trivial repository' \ | |
23 | 'echo Hello > A && | |
5be60078 | 24 | git update-index --add A && |
0cb0e143 | 25 | git commit -m "Initial commit." && |
5be60078 | 26 | HEAD=$(git rev-parse --verify HEAD)' |
919a3c98 CC |
27 | |
28 | SHA1= | |
29 | ||
30 | test_expect_success \ | |
31 | 'see if git show-ref works as expected' \ | |
5be60078 | 32 | 'git branch a && |
13f11b95 | 33 | SHA1=$(cat .git/refs/heads/a) && |
919a3c98 | 34 | echo "$SHA1 refs/heads/a" >expect && |
5be60078 | 35 | git show-ref a >result && |
4fdf71be | 36 | test_cmp expect result' |
919a3c98 CC |
37 | |
38 | test_expect_success \ | |
39 | 'see if a branch still exists when packed' \ | |
5be60078 JH |
40 | 'git branch b && |
41 | git pack-refs --all && | |
0f018bab | 42 | rm -f .git/refs/heads/b && |
919a3c98 | 43 | echo "$SHA1 refs/heads/b" >expect && |
5be60078 | 44 | git show-ref b >result && |
4fdf71be | 45 | test_cmp expect result' |
919a3c98 | 46 | |
41ac414e JH |
47 | test_expect_success 'git branch c/d should barf if branch c exists' ' |
48 | git branch c && | |
5be60078 | 49 | git pack-refs --all && |
41ac414e | 50 | rm -f .git/refs/heads/c && |
d492b31c | 51 | test_must_fail git branch c/d |
41ac414e | 52 | ' |
919a3c98 CC |
53 | |
54 | test_expect_success \ | |
55 | 'see if a branch still exists after git pack-refs --prune' \ | |
5be60078 JH |
56 | 'git branch e && |
57 | git pack-refs --all --prune && | |
919a3c98 | 58 | echo "$SHA1 refs/heads/e" >expect && |
5be60078 | 59 | git show-ref e >result && |
4fdf71be | 60 | test_cmp expect result' |
919a3c98 | 61 | |
41ac414e JH |
62 | test_expect_success 'see if git pack-refs --prune remove ref files' ' |
63 | git branch f && | |
5be60078 | 64 | git pack-refs --all --prune && |
41ac414e JH |
65 | ! test -f .git/refs/heads/f |
66 | ' | |
919a3c98 | 67 | |
be7c6d46 GP |
68 | test_expect_success 'see if git pack-refs --prune removes empty dirs' ' |
69 | git branch r/s/t && | |
70 | git pack-refs --all --prune && | |
71 | ! test -e .git/refs/heads/r | |
72 | ' | |
73 | ||
919a3c98 CC |
74 | test_expect_success \ |
75 | 'git branch g should work when git branch g/h has been deleted' \ | |
5be60078 JH |
76 | 'git branch g/h && |
77 | git pack-refs --all --prune && | |
78 | git branch -d g/h && | |
79 | git branch g && | |
80 | git pack-refs --all && | |
81 | git branch -d g' | |
919a3c98 | 82 | |
41ac414e JH |
83 | test_expect_success 'git branch i/j/k should barf if branch i exists' ' |
84 | git branch i && | |
5be60078 | 85 | git pack-refs --all --prune && |
d492b31c | 86 | test_must_fail git branch i/j/k |
41ac414e | 87 | ' |
14c8a681 CC |
88 | |
89 | test_expect_success \ | |
90 | 'test git branch k after branch k/l/m and k/lm have been deleted' \ | |
5be60078 JH |
91 | 'git branch k/l && |
92 | git branch k/lm && | |
93 | git branch -d k/l && | |
94 | git branch k/l/m && | |
95 | git branch -d k/l/m && | |
96 | git branch -d k/lm && | |
97 | git branch k' | |
14c8a681 CC |
98 | |
99 | test_expect_success \ | |
100 | 'test git branch n after some branch deletion and pruning' \ | |
5be60078 JH |
101 | 'git branch n/o && |
102 | git branch n/op && | |
103 | git branch -d n/o && | |
104 | git branch n/o/p && | |
105 | git branch -d n/op && | |
106 | git pack-refs --all --prune && | |
107 | git branch -d n/o/p && | |
108 | git branch n' | |
14c8a681 | 109 | |
5bdd8d4a CB |
110 | test_expect_success \ |
111 | 'see if up-to-date packed refs are preserved' \ | |
112 | 'git branch q && | |
113 | git pack-refs --all --prune && | |
114 | git update-ref refs/heads/q refs/heads/q && | |
115 | ! test -f .git/refs/heads/q' | |
116 | ||
1b555932 | 117 | test_expect_success 'pack, prune and repack' ' |
0cb0e143 | 118 | git tag foo && |
5be60078 JH |
119 | git pack-refs --all --prune && |
120 | git show-ref >all-of-them && | |
121 | git pack-refs && | |
122 | git show-ref >again && | |
4fdf71be | 123 | test_cmp all-of-them again |
1b555932 LT |
124 | ' |
125 | ||
0a0b8d15 MH |
126 | test_expect_success 'explicit pack-refs with dangling packed reference' ' |
127 | git commit --allow-empty -m "soon to be garbage-collected" && | |
128 | git pack-refs --all && | |
129 | git reset --hard HEAD^ && | |
130 | git reflog expire --expire=all --all && | |
131 | git prune --expire=all && | |
132 | git pack-refs --all 2>result && | |
ec21ac8c | 133 | test_must_be_empty result |
0a0b8d15 MH |
134 | ' |
135 | ||
136 | test_expect_success 'delete ref with dangling packed version' ' | |
137 | git checkout -b lamb && | |
138 | git commit --allow-empty -m "future garbage" && | |
139 | git pack-refs --all && | |
140 | git reset --hard HEAD^ && | |
d6c6b108 | 141 | git checkout main && |
0a0b8d15 MH |
142 | git reflog expire --expire=all --all && |
143 | git prune --expire=all && | |
144 | git branch -d lamb 2>result && | |
ec21ac8c | 145 | test_must_be_empty result |
0a0b8d15 MH |
146 | ' |
147 | ||
ab292bc4 | 148 | test_expect_success 'delete ref while another dangling packed ref' ' |
0a0b8d15 MH |
149 | git branch lamb && |
150 | git commit --allow-empty -m "future garbage" && | |
151 | git pack-refs --all && | |
152 | git reset --hard HEAD^ && | |
153 | git reflog expire --expire=all --all && | |
154 | git prune --expire=all && | |
155 | git branch -d lamb 2>result && | |
ec21ac8c | 156 | test_must_be_empty result |
0a0b8d15 MH |
157 | ' |
158 | ||
afd11d3e JK |
159 | test_expect_success 'pack ref directly below refs/' ' |
160 | git update-ref refs/top HEAD && | |
161 | git pack-refs --all --prune && | |
162 | grep refs/top .git/packed-refs && | |
163 | test_path_is_missing .git/refs/top | |
164 | ' | |
165 | ||
ce414b33 DT |
166 | test_expect_success 'do not pack ref in refs/bisect' ' |
167 | git update-ref refs/bisect/local HEAD && | |
168 | git pack-refs --all --prune && | |
169 | ! grep refs/bisect/local .git/packed-refs >/dev/null && | |
170 | test_path_is_file .git/refs/bisect/local | |
171 | ' | |
172 | ||
cbe73331 JK |
173 | test_expect_success 'disable reflogs' ' |
174 | git config core.logallrefupdates false && | |
175 | rm -rf .git/logs | |
176 | ' | |
177 | ||
178 | test_expect_success 'create packed foo/bar/baz branch' ' | |
179 | git branch foo/bar/baz && | |
180 | git pack-refs --all --prune && | |
181 | test_path_is_missing .git/refs/heads/foo/bar/baz && | |
d0ab0584 | 182 | test_must_fail git reflog exists refs/heads/foo/bar/baz |
cbe73331 JK |
183 | ' |
184 | ||
185 | test_expect_success 'notice d/f conflict with existing directory' ' | |
186 | test_must_fail git branch foo && | |
187 | test_must_fail git branch foo/bar | |
188 | ' | |
189 | ||
190 | test_expect_success 'existing directory reports concrete ref' ' | |
191 | test_must_fail git branch foo 2>stderr && | |
661558f0 | 192 | test_i18ngrep refs/heads/foo/bar/baz stderr |
cbe73331 JK |
193 | ' |
194 | ||
195 | test_expect_success 'notice d/f conflict with existing ref' ' | |
196 | test_must_fail git branch foo/bar/baz/extra && | |
197 | test_must_fail git branch foo/bar/baz/lots/of/extra/components | |
198 | ' | |
199 | ||
9308b7f3 | 200 | test_expect_success 'reject packed-refs with unterminated line' ' |
02a1a420 MH |
201 | cp .git/packed-refs .git/packed-refs.bak && |
202 | test_when_finished "mv .git/packed-refs.bak .git/packed-refs" && | |
203 | printf "%s" "$HEAD refs/zzzzz" >>.git/packed-refs && | |
204 | echo "fatal: unterminated line in .git/packed-refs: $HEAD refs/zzzzz" >expected_err && | |
205 | test_must_fail git for-each-ref >out 2>err && | |
206 | test_cmp expected_err err | |
207 | ' | |
208 | ||
9308b7f3 | 209 | test_expect_success 'reject packed-refs containing junk' ' |
02a1a420 MH |
210 | cp .git/packed-refs .git/packed-refs.bak && |
211 | test_when_finished "mv .git/packed-refs.bak .git/packed-refs" && | |
212 | printf "%s\n" "bogus content" >>.git/packed-refs && | |
213 | echo "fatal: unexpected line in .git/packed-refs: bogus content" >expected_err && | |
214 | test_must_fail git for-each-ref >out 2>err && | |
215 | test_cmp expected_err err | |
216 | ' | |
217 | ||
9308b7f3 | 218 | test_expect_success 'reject packed-refs with a short SHA-1' ' |
02a1a420 MH |
219 | cp .git/packed-refs .git/packed-refs.bak && |
220 | test_when_finished "mv .git/packed-refs.bak .git/packed-refs" && | |
221 | printf "%.7s %s\n" $HEAD refs/zzzzz >>.git/packed-refs && | |
222 | printf "fatal: unexpected line in .git/packed-refs: %.7s %s\n" $HEAD refs/zzzzz >expected_err && | |
223 | test_must_fail git for-each-ref >out 2>err && | |
224 | test_cmp expected_err err | |
225 | ' | |
226 | ||
f4ab4f3a MH |
227 | test_expect_success 'timeout if packed-refs.lock exists' ' |
228 | LOCK=.git/packed-refs.lock && | |
229 | >"$LOCK" && | |
230 | test_when_finished "rm -f $LOCK" && | |
231 | test_must_fail git pack-refs --all --prune | |
232 | ' | |
233 | ||
234 | test_expect_success 'retry acquiring packed-refs.lock' ' | |
235 | LOCK=.git/packed-refs.lock && | |
236 | >"$LOCK" && | |
3ea67379 | 237 | test_when_finished "wait && rm -f $LOCK" && |
f4ab4f3a | 238 | { |
3ea67379 | 239 | ( sleep 1 && rm -f $LOCK ) & |
f4ab4f3a MH |
240 | } && |
241 | git -c core.packedrefstimeout=3000 pack-refs --all --prune | |
242 | ' | |
243 | ||
198b808e MH |
244 | test_expect_success SYMLINKS 'pack symlinked packed-refs' ' |
245 | # First make sure that symlinking works when reading: | |
d6c6b108 | 246 | git update-ref refs/heads/lossy refs/heads/main && |
198b808e MH |
247 | git for-each-ref >all-refs-before && |
248 | mv .git/packed-refs .git/my-deviant-packed-refs && | |
249 | ln -s my-deviant-packed-refs .git/packed-refs && | |
250 | git for-each-ref >all-refs-linked && | |
251 | test_cmp all-refs-before all-refs-linked && | |
252 | git pack-refs --all --prune && | |
253 | git for-each-ref >all-refs-packed && | |
254 | test_cmp all-refs-before all-refs-packed && | |
255 | test -h .git/packed-refs && | |
256 | test "$(readlink .git/packed-refs)" = "my-deviant-packed-refs" | |
257 | ' | |
258 | ||
919a3c98 | 259 | test_done |