]>
Commit | Line | Data |
---|---|---|
469e2ebf JH |
1 | #!/bin/sh |
2 | ||
dbedf8bf JN |
3 | test_description='git fsck random collection of tests |
4 | ||
5 | * (HEAD) B | |
6 | * (master) A | |
7 | ' | |
469e2ebf JH |
8 | |
9 | . ./test-lib.sh | |
10 | ||
11 | test_expect_success setup ' | |
dbedf8bf | 12 | git config gc.auto 0 && |
0adc6a3d | 13 | git config i18n.commitencoding ISO-8859-1 && |
469e2ebf | 14 | test_commit A fileA one && |
0adc6a3d | 15 | git config --unset i18n.commitencoding && |
469e2ebf JH |
16 | git checkout HEAD^0 && |
17 | test_commit B fileB two && | |
18 | git tag -d A B && | |
dbedf8bf JN |
19 | git reflog expire --expire=now --all && |
20 | >empty | |
469e2ebf JH |
21 | ' |
22 | ||
e15ef669 JH |
23 | test_expect_success 'loose objects borrowed from alternate are not missing' ' |
24 | mkdir another && | |
25 | ( | |
26 | cd another && | |
27 | git init && | |
28 | echo ../../../.git/objects >.git/objects/info/alternates && | |
29 | test_commit C fileC one && | |
c6a13b2c | 30 | git fsck --no-dangling >../actual 2>&1 |
dbedf8bf | 31 | ) && |
dbedf8bf | 32 | test_cmp empty actual |
e15ef669 JH |
33 | ' |
34 | ||
dbedf8bf JN |
35 | test_expect_success 'HEAD is part of refs, valid objects appear valid' ' |
36 | git fsck >actual 2>&1 && | |
37 | test_cmp empty actual | |
0adc6a3d JN |
38 | ' |
39 | ||
02a6552c TR |
40 | # Corruption tests follow. Make sure to remove all traces of the |
41 | # specific corruption you test afterwards, lest a later test trip over | |
42 | # it. | |
43 | ||
dbedf8bf JN |
44 | test_expect_success 'setup: helpers for corruption tests' ' |
45 | sha1_file() { | |
46 | echo "$*" | sed "s#..#.git/objects/&/#" | |
47 | } && | |
48 | ||
49 | remove_object() { | |
50 | file=$(sha1_file "$*") && | |
51 | test -e "$file" && | |
52 | rm -f "$file" | |
53 | } | |
54 | ' | |
55 | ||
02a6552c TR |
56 | test_expect_success 'object with bad sha1' ' |
57 | sha=$(echo blob | git hash-object -w --stdin) && | |
02a6552c TR |
58 | old=$(echo $sha | sed "s+^..+&/+") && |
59 | new=$(dirname $old)/ffffffffffffffffffffffffffffffffffffff && | |
a48fcd83 | 60 | sha="$(dirname $new)$(basename $new)" && |
02a6552c | 61 | mv .git/objects/$old .git/objects/$new && |
dbedf8bf | 62 | test_when_finished "remove_object $sha" && |
02a6552c | 63 | git update-index --add --cacheinfo 100644 $sha foo && |
dbedf8bf | 64 | test_when_finished "git read-tree -u --reset HEAD" && |
02a6552c | 65 | tree=$(git write-tree) && |
dbedf8bf | 66 | test_when_finished "remove_object $tree" && |
02a6552c | 67 | cmt=$(echo bogus | git commit-tree $tree) && |
dbedf8bf | 68 | test_when_finished "remove_object $cmt" && |
02a6552c | 69 | git update-ref refs/heads/bogus $cmt && |
dbedf8bf JN |
70 | test_when_finished "git update-ref -d refs/heads/bogus" && |
71 | ||
2e770fe4 | 72 | test_must_fail git fsck 2>out && |
dbedf8bf JN |
73 | cat out && |
74 | grep "$sha.*corrupt" out | |
02a6552c TR |
75 | ' |
76 | ||
77 | test_expect_success 'branch pointing to non-commit' ' | |
dbedf8bf JN |
78 | git rev-parse HEAD^{tree} >.git/refs/heads/invalid && |
79 | test_when_finished "git update-ref -d refs/heads/invalid" && | |
122f76f5 | 80 | test_must_fail git fsck 2>out && |
dbedf8bf JN |
81 | cat out && |
82 | grep "not a commit" out | |
02a6552c TR |
83 | ' |
84 | ||
122f76f5 JH |
85 | test_expect_success 'HEAD link pointing at a funny object' ' |
86 | test_when_finished "mv .git/SAVED_HEAD .git/HEAD" && | |
87 | mv .git/HEAD .git/SAVED_HEAD && | |
88 | echo 0000000000000000000000000000000000000000 >.git/HEAD && | |
89 | # avoid corrupt/broken HEAD from interfering with repo discovery | |
90 | test_must_fail env GIT_DIR=.git git fsck 2>out && | |
91 | cat out && | |
92 | grep "detached HEAD points" out | |
93 | ' | |
94 | ||
95 | test_expect_success 'HEAD link pointing at a funny place' ' | |
96 | test_when_finished "mv .git/SAVED_HEAD .git/HEAD" && | |
97 | mv .git/HEAD .git/SAVED_HEAD && | |
98 | echo "ref: refs/funny/place" >.git/HEAD && | |
99 | # avoid corrupt/broken HEAD from interfering with repo discovery | |
100 | test_must_fail env GIT_DIR=.git git fsck 2>out && | |
101 | cat out && | |
102 | grep "HEAD points to something strange" out | |
103 | ' | |
104 | ||
daae1922 JN |
105 | test_expect_success 'email without @ is okay' ' |
106 | git cat-file commit HEAD >basis && | |
107 | sed "s/@/AT/" basis >okay && | |
108 | new=$(git hash-object -t commit -w --stdin <okay) && | |
dbedf8bf | 109 | test_when_finished "remove_object $new" && |
daae1922 | 110 | git update-ref refs/heads/bogus "$new" && |
dbedf8bf | 111 | test_when_finished "git update-ref -d refs/heads/bogus" && |
daae1922 JN |
112 | git fsck 2>out && |
113 | cat out && | |
dbedf8bf | 114 | ! grep "commit $new" out |
daae1922 | 115 | ' |
daae1922 | 116 | |
daae1922 JN |
117 | test_expect_success 'email with embedded > is not okay' ' |
118 | git cat-file commit HEAD >basis && | |
119 | sed "s/@[a-z]/&>/" basis >bad-email && | |
120 | new=$(git hash-object -t commit -w --stdin <bad-email) && | |
dbedf8bf | 121 | test_when_finished "remove_object $new" && |
daae1922 | 122 | git update-ref refs/heads/bogus "$new" && |
dbedf8bf | 123 | test_when_finished "git update-ref -d refs/heads/bogus" && |
2e770fe4 | 124 | test_must_fail git fsck 2>out && |
daae1922 JN |
125 | cat out && |
126 | grep "error in commit $new" out | |
127 | ' | |
02a6552c | 128 | |
53f53cff | 129 | test_expect_success 'missing < email delimiter is reported nicely' ' |
e3c98120 DI |
130 | git cat-file commit HEAD >basis && |
131 | sed "s/<//" basis >bad-email-2 && | |
132 | new=$(git hash-object -t commit -w --stdin <bad-email-2) && | |
133 | test_when_finished "remove_object $new" && | |
134 | git update-ref refs/heads/bogus "$new" && | |
135 | test_when_finished "git update-ref -d refs/heads/bogus" && | |
2e770fe4 | 136 | test_must_fail git fsck 2>out && |
e3c98120 DI |
137 | cat out && |
138 | grep "error in commit $new.* - bad name" out | |
139 | ' | |
140 | ||
53f53cff | 141 | test_expect_success 'missing email is reported nicely' ' |
e3c98120 DI |
142 | git cat-file commit HEAD >basis && |
143 | sed "s/[a-z]* <[^>]*>//" basis >bad-email-3 && | |
144 | new=$(git hash-object -t commit -w --stdin <bad-email-3) && | |
145 | test_when_finished "remove_object $new" && | |
146 | git update-ref refs/heads/bogus "$new" && | |
147 | test_when_finished "git update-ref -d refs/heads/bogus" && | |
2e770fe4 | 148 | test_must_fail git fsck 2>out && |
e3c98120 DI |
149 | cat out && |
150 | grep "error in commit $new.* - missing email" out | |
151 | ' | |
152 | ||
53f53cff | 153 | test_expect_success '> in name is reported' ' |
e3c98120 DI |
154 | git cat-file commit HEAD >basis && |
155 | sed "s/ </> </" basis >bad-email-4 && | |
156 | new=$(git hash-object -t commit -w --stdin <bad-email-4) && | |
157 | test_when_finished "remove_object $new" && | |
158 | git update-ref refs/heads/bogus "$new" && | |
159 | test_when_finished "git update-ref -d refs/heads/bogus" && | |
2e770fe4 | 160 | test_must_fail git fsck 2>out && |
e3c98120 DI |
161 | cat out && |
162 | grep "error in commit $new" out | |
163 | ' | |
164 | ||
d4b8de04 JK |
165 | # date is 2^64 + 1 |
166 | test_expect_success 'integer overflow in timestamps is reported' ' | |
167 | git cat-file commit HEAD >basis && | |
168 | sed "s/^\\(author .*>\\) [0-9]*/\\1 18446744073709551617/" \ | |
169 | <basis >bad-timestamp && | |
170 | new=$(git hash-object -t commit -w --stdin <bad-timestamp) && | |
171 | test_when_finished "remove_object $new" && | |
172 | git update-ref refs/heads/bogus "$new" && | |
173 | test_when_finished "git update-ref -d refs/heads/bogus" && | |
2e770fe4 | 174 | test_must_fail git fsck 2>out && |
d4b8de04 JK |
175 | cat out && |
176 | grep "error in commit $new.*integer overflow" out | |
177 | ' | |
178 | ||
80c7f5a0 RS |
179 | test_expect_success 'commit with NUL in header' ' |
180 | git cat-file commit HEAD >basis && | |
181 | sed "s/author ./author Q/" <basis | q_to_nul >commit-NUL-header && | |
182 | new=$(git hash-object -t commit -w --stdin <commit-NUL-header) && | |
183 | test_when_finished "remove_object $new" && | |
184 | git update-ref refs/heads/bogus "$new" && | |
185 | test_when_finished "git update-ref -d refs/heads/bogus" && | |
186 | test_must_fail git fsck 2>out && | |
187 | cat out && | |
188 | grep "error in commit $new.*unterminated header: NUL at offset" out | |
189 | ' | |
190 | ||
2e770fe4 JK |
191 | test_expect_success 'malformatted tree object' ' |
192 | test_when_finished "git update-ref -d refs/tags/wrong" && | |
193 | test_when_finished "remove_object \$T" && | |
194 | T=$( | |
195 | GIT_INDEX_FILE=test-index && | |
196 | export GIT_INDEX_FILE && | |
197 | rm -f test-index && | |
198 | >x && | |
199 | git add x && | |
200 | T=$(git write-tree) && | |
201 | ( | |
202 | git cat-file tree $T && | |
203 | git cat-file tree $T | |
204 | ) | | |
205 | git hash-object -w -t tree --stdin | |
206 | ) && | |
207 | test_must_fail git fsck 2>out && | |
208 | grep "error in tree .*contains duplicate file entries" out | |
209 | ' | |
210 | ||
4551d035 | 211 | test_expect_success 'tag pointing to nonexistent' ' |
a48fcd83 | 212 | cat >invalid-tag <<-\EOF && |
dbedf8bf JN |
213 | object ffffffffffffffffffffffffffffffffffffffff |
214 | type commit | |
215 | tag invalid | |
216 | tagger T A Gger <tagger@example.com> 1234567890 -0000 | |
217 | ||
218 | This is an invalid tag. | |
219 | EOF | |
220 | ||
221 | tag=$(git hash-object -t tag -w --stdin <invalid-tag) && | |
222 | test_when_finished "remove_object $tag" && | |
223 | echo $tag >.git/refs/tags/invalid && | |
224 | test_when_finished "git update-ref -d refs/tags/invalid" && | |
4551d035 | 225 | test_must_fail git fsck --tags >out && |
02a6552c | 226 | cat out && |
dbedf8bf | 227 | grep "broken link" out |
02a6552c TR |
228 | ' |
229 | ||
4551d035 | 230 | test_expect_success 'tag pointing to something else than its type' ' |
dbedf8bf JN |
231 | sha=$(echo blob | git hash-object -w --stdin) && |
232 | test_when_finished "remove_object $sha" && | |
233 | cat >wrong-tag <<-EOF && | |
234 | object $sha | |
235 | type commit | |
236 | tag wrong | |
237 | tagger T A Gger <tagger@example.com> 1234567890 -0000 | |
238 | ||
239 | This is an invalid tag. | |
240 | EOF | |
241 | ||
242 | tag=$(git hash-object -t tag -w --stdin <wrong-tag) && | |
243 | test_when_finished "remove_object $tag" && | |
244 | echo $tag >.git/refs/tags/wrong && | |
245 | test_when_finished "git update-ref -d refs/tags/wrong" && | |
9dad83be | 246 | test_must_fail git fsck --tags |
02a6552c TR |
247 | ' |
248 | ||
90e3e5f0 JS |
249 | test_expect_success 'tag with incorrect tag name & missing tagger' ' |
250 | sha=$(git rev-parse HEAD) && | |
251 | cat >wrong-tag <<-EOF && | |
252 | object $sha | |
253 | type commit | |
254 | tag wrong name format | |
255 | ||
256 | This is an invalid tag. | |
257 | EOF | |
258 | ||
259 | tag=$(git hash-object -t tag -w --stdin <wrong-tag) && | |
260 | test_when_finished "remove_object $tag" && | |
261 | echo $tag >.git/refs/tags/wrong && | |
262 | test_when_finished "git update-ref -d refs/tags/wrong" && | |
263 | git fsck --tags 2>out && | |
7add4419 JK |
264 | |
265 | cat >expect <<-EOF && | |
71ab8fa8 JS |
266 | warning in tag $tag: badTagName: invalid '\''tag'\'' name: wrong name format |
267 | warning in tag $tag: missingTaggerEntry: invalid format - expected '\''tagger'\'' line | |
7add4419 JK |
268 | EOF |
269 | test_cmp expect out | |
90e3e5f0 JS |
270 | ' |
271 | ||
b659605d JH |
272 | test_expect_success 'tag with bad tagger' ' |
273 | sha=$(git rev-parse HEAD) && | |
274 | cat >wrong-tag <<-EOF && | |
275 | object $sha | |
276 | type commit | |
277 | tag not-quite-wrong | |
278 | tagger Bad Tagger Name | |
279 | ||
280 | This is an invalid tag. | |
281 | EOF | |
282 | ||
283 | tag=$(git hash-object --literally -t tag -w --stdin <wrong-tag) && | |
284 | test_when_finished "remove_object $tag" && | |
285 | echo $tag >.git/refs/tags/wrong && | |
286 | test_when_finished "git update-ref -d refs/tags/wrong" && | |
287 | test_must_fail git fsck --tags 2>out && | |
288 | grep "error in tag .*: invalid author/committer" out | |
289 | ' | |
290 | ||
8a272f29 | 291 | test_expect_success 'tag with NUL in header' ' |
80c7f5a0 RS |
292 | sha=$(git rev-parse HEAD) && |
293 | q_to_nul >tag-NUL-header <<-EOF && | |
294 | object $sha | |
295 | type commit | |
296 | tag contains-Q-in-header | |
297 | tagger T A Gger <tagger@example.com> 1234567890 -0000 | |
298 | ||
299 | This is an invalid tag. | |
300 | EOF | |
301 | ||
302 | tag=$(git hash-object --literally -t tag -w --stdin <tag-NUL-header) && | |
303 | test_when_finished "remove_object $tag" && | |
304 | echo $tag >.git/refs/tags/wrong && | |
305 | test_when_finished "git update-ref -d refs/tags/wrong" && | |
306 | test_must_fail git fsck --tags 2>out && | |
307 | cat out && | |
308 | grep "error in tag $tag.*unterminated header: NUL at offset" out | |
309 | ' | |
310 | ||
dbedf8bf JN |
311 | test_expect_success 'cleaned up' ' |
312 | git fsck >actual 2>&1 && | |
313 | test_cmp empty actual | |
314 | ' | |
02a6552c | 315 | |
cb8da705 CB |
316 | test_expect_success 'rev-list --verify-objects' ' |
317 | git rev-list --verify-objects --all >/dev/null 2>out && | |
318 | test_cmp empty out | |
319 | ' | |
320 | ||
321 | test_expect_success 'rev-list --verify-objects with bad sha1' ' | |
322 | sha=$(echo blob | git hash-object -w --stdin) && | |
323 | old=$(echo $sha | sed "s+^..+&/+") && | |
324 | new=$(dirname $old)/ffffffffffffffffffffffffffffffffffffff && | |
325 | sha="$(dirname $new)$(basename $new)" && | |
326 | mv .git/objects/$old .git/objects/$new && | |
327 | test_when_finished "remove_object $sha" && | |
328 | git update-index --add --cacheinfo 100644 $sha foo && | |
329 | test_when_finished "git read-tree -u --reset HEAD" && | |
330 | tree=$(git write-tree) && | |
331 | test_when_finished "remove_object $tree" && | |
332 | cmt=$(echo bogus | git commit-tree $tree) && | |
333 | test_when_finished "remove_object $cmt" && | |
334 | git update-ref refs/heads/bogus $cmt && | |
335 | test_when_finished "git update-ref -d refs/heads/bogus" && | |
336 | ||
337 | test_might_fail git rev-list --verify-objects refs/heads/bogus >/dev/null 2>out && | |
338 | cat out && | |
339 | grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out | |
340 | ' | |
341 | ||
2becf00f JS |
342 | test_expect_success 'force fsck to ignore double author' ' |
343 | git cat-file commit HEAD >basis && | |
344 | sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors && | |
345 | new=$(git hash-object -t commit -w --stdin <multiple-authors) && | |
346 | test_when_finished "remove_object $new" && | |
347 | git update-ref refs/heads/bogus "$new" && | |
348 | test_when_finished "git update-ref -d refs/heads/bogus" && | |
349 | test_must_fail git fsck && | |
350 | git -c fsck.multipleAuthors=ignore fsck | |
351 | ' | |
352 | ||
c479d14a JK |
353 | _bz='\0' |
354 | _bz5="$_bz$_bz$_bz$_bz$_bz" | |
355 | _bz20="$_bz5$_bz5$_bz5$_bz5" | |
356 | ||
357 | test_expect_success 'fsck notices blob entry pointing to null sha1' ' | |
358 | (git init null-blob && | |
359 | cd null-blob && | |
360 | sha=$(printf "100644 file$_bz$_bz20" | | |
361 | git hash-object -w --stdin -t tree) && | |
362 | git fsck 2>out && | |
363 | cat out && | |
364 | grep "warning.*null sha1" out | |
365 | ) | |
366 | ' | |
367 | ||
368 | test_expect_success 'fsck notices submodule entry pointing to null sha1' ' | |
369 | (git init null-commit && | |
370 | cd null-commit && | |
371 | sha=$(printf "160000 submodule$_bz$_bz20" | | |
372 | git hash-object -w --stdin -t tree) && | |
373 | git fsck 2>out && | |
374 | cat out && | |
375 | grep "warning.*null sha1" out | |
376 | ) | |
377 | ' | |
378 | ||
a18fcc9f | 379 | while read name path pretty; do |
450870cb | 380 | while read mode type; do |
a18fcc9f JK |
381 | : ${pretty:=$path} |
382 | test_expect_success "fsck notices $pretty as $type" ' | |
450870cb JK |
383 | ( |
384 | git init $name-$type && | |
385 | cd $name-$type && | |
386 | echo content >file && | |
387 | git add file && | |
388 | git commit -m base && | |
389 | blob=$(git rev-parse :file) && | |
390 | tree=$(git rev-parse HEAD^{tree}) && | |
391 | value=$(eval "echo \$$type") && | |
392 | printf "$mode $type %s\t%s" "$value" "$path" >bad && | |
d08c13b9 | 393 | bad_tree=$(git mktree <bad) && |
450870cb JK |
394 | git fsck 2>out && |
395 | cat out && | |
d08c13b9 | 396 | grep "warning.*tree $bad_tree" out |
450870cb JK |
397 | )' |
398 | done <<-\EOF | |
399 | 100644 blob | |
400 | 040000 tree | |
401 | EOF | |
a18fcc9f | 402 | done <<-EOF |
450870cb JK |
403 | dot . |
404 | dotdot .. | |
405 | dotgit .git | |
76e86fc6 | 406 | dotgit-case .GIT |
a18fcc9f | 407 | dotgit-unicode .gI${u200c}T .gI{u200c}T |
d08c13b9 JS |
408 | dotgit-case2 .Git |
409 | git-tilde1 git~1 | |
410 | dotgitdot .git. | |
411 | dot-backslash-case .\\\\.GIT\\\\foobar | |
412 | dotgit-case-backslash .git\\\\foobar | |
450870cb | 413 | EOF |
5c17f512 | 414 | |
6aaf956b JK |
415 | test_expect_success 'fsck allows .Ňit' ' |
416 | ( | |
417 | git init not-dotgit && | |
418 | cd not-dotgit && | |
419 | echo content >file && | |
420 | git add file && | |
421 | git commit -m base && | |
422 | blob=$(git rev-parse :file) && | |
423 | printf "100644 blob $blob\t.\\305\\207it" >tree && | |
424 | tree=$(git mktree <tree) && | |
425 | git fsck 2>err && | |
426 | test_line_count = 0 err | |
427 | ) | |
428 | ' | |
429 | ||
6d2d780f JH |
430 | test_expect_success 'NUL in commit' ' |
431 | rm -fr nul-in-commit && | |
432 | git init nul-in-commit && | |
433 | ( | |
434 | cd nul-in-commit && | |
435 | git commit --allow-empty -m "initial commitQNUL after message" && | |
436 | git cat-file commit HEAD >original && | |
437 | q_to_nul <original >munged && | |
438 | git hash-object -w -t commit --stdin <munged >name && | |
439 | git branch bad $(cat name) && | |
440 | ||
441 | test_must_fail git -c fsck.nulInCommit=error fsck 2>warn.1 && | |
442 | grep nulInCommit warn.1 && | |
443 | git fsck 2>warn.2 && | |
444 | grep nulInCommit warn.2 | |
445 | ) | |
446 | ' | |
447 | ||
30d1038d JK |
448 | # create a static test repo which is broken by omitting |
449 | # one particular object ($1, which is looked up via rev-parse | |
450 | # in the new repository). | |
451 | create_repo_missing () { | |
452 | rm -rf missing && | |
453 | git init missing && | |
454 | ( | |
455 | cd missing && | |
456 | git commit -m one --allow-empty && | |
457 | mkdir subdir && | |
458 | echo content >subdir/file && | |
459 | git add subdir/file && | |
460 | git commit -m two && | |
461 | unrelated=$(echo unrelated | git hash-object --stdin -w) && | |
462 | git tag -m foo tag $unrelated && | |
463 | sha1=$(git rev-parse --verify "$1") && | |
464 | path=$(echo $sha1 | sed 's|..|&/|') && | |
465 | rm .git/objects/$path | |
466 | ) | |
467 | } | |
468 | ||
469 | test_expect_success 'fsck notices missing blob' ' | |
470 | create_repo_missing HEAD:subdir/file && | |
471 | test_must_fail git -C missing fsck | |
472 | ' | |
473 | ||
474 | test_expect_success 'fsck notices missing subtree' ' | |
475 | create_repo_missing HEAD:subdir && | |
476 | test_must_fail git -C missing fsck | |
477 | ' | |
478 | ||
479 | test_expect_success 'fsck notices missing root tree' ' | |
480 | create_repo_missing HEAD^{tree} && | |
481 | test_must_fail git -C missing fsck | |
482 | ' | |
483 | ||
484 | test_expect_success 'fsck notices missing parent' ' | |
485 | create_repo_missing HEAD^ && | |
486 | test_must_fail git -C missing fsck | |
487 | ' | |
488 | ||
489 | test_expect_success 'fsck notices missing tagged object' ' | |
490 | create_repo_missing tag^{blob} && | |
491 | test_must_fail git -C missing fsck | |
492 | ' | |
493 | ||
494 | test_expect_success 'fsck notices ref pointing to missing commit' ' | |
495 | create_repo_missing HEAD && | |
496 | test_must_fail git -C missing fsck | |
497 | ' | |
498 | ||
499 | test_expect_success 'fsck notices ref pointing to missing tag' ' | |
500 | create_repo_missing tag && | |
501 | test_must_fail git -C missing fsck | |
502 | ' | |
503 | ||
02976bf8 JS |
504 | test_expect_success 'fsck --connectivity-only' ' |
505 | rm -rf connectivity-only && | |
506 | git init connectivity-only && | |
507 | ( | |
508 | cd connectivity-only && | |
509 | touch empty && | |
510 | git add empty && | |
511 | test_commit empty && | |
512 | empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 && | |
513 | rm -f $empty && | |
514 | echo invalid >$empty && | |
515 | test_must_fail git fsck --strict && | |
516 | git fsck --strict --connectivity-only && | |
517 | tree=$(git rev-parse HEAD:) && | |
518 | suffix=${tree#??} && | |
519 | tree=.git/objects/${tree%$suffix}/$suffix && | |
520 | rm -f $tree && | |
521 | echo invalid >$tree && | |
522 | test_must_fail git fsck --strict --connectivity-only | |
523 | ) | |
524 | ' | |
525 | ||
90cf590f JS |
526 | remove_loose_object () { |
527 | sha1="$(git rev-parse "$1")" && | |
528 | remainder=${sha1#??} && | |
529 | firsttwo=${sha1%$remainder} && | |
530 | rm .git/objects/$firsttwo/$remainder | |
531 | } | |
532 | ||
533 | test_expect_success 'fsck --name-objects' ' | |
534 | rm -rf name-objects && | |
535 | git init name-objects && | |
536 | ( | |
537 | cd name-objects && | |
538 | test_commit julius caesar.t && | |
539 | test_commit augustus && | |
540 | test_commit caesar && | |
541 | remove_loose_object $(git rev-parse julius:caesar.t) && | |
542 | test_must_fail git fsck --name-objects >out && | |
543 | tree=$(git rev-parse --verify julius:) && | |
73fc2aad | 544 | egrep "$tree \((refs/heads/master|HEAD)@\{[0-9]*\}:" out |
90cf590f JS |
545 | ) |
546 | ' | |
547 | ||
469e2ebf | 548 | test_done |