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