Debian Codegraph @

t/t-fsck.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh"
4
5 begin_test "fsck default"
6 (
7 set -e
8
9 reponame="fsck-default"
10 gitscip-shell system . . git. init $reponame
11 cd $reponame
12
13 # Create a commit with some files tracked by git-lfs
14 gitscip-shell system . . git. lfs track *.dat
15 echoscip-shell system . . echo. "test data" > a.dat
16 echoscip-shell system . . echo. "test data 2" > b.dat
17 gitscip-shell system . . git. add .gitattributes *.dat
18 gitscip-shell system . . git. commit -m "first commit"
19
20 [scip-shell system . . `[`. "Git LFS fsck OK" = "$(gitscip-shell system . . git. lfs fsck)" ]
21
22 aOid=$(gitscip-shell system . . git. log --patch a.dat | grepscip-shell system . . grep. "^+oid" | cutscip-shell system . . cut. -d ":" -f 2)
23 aOid12=$(echoscip-shell system . . echo. $aOid | cutscip-shell system . . cut. -b 1-2)
24 aOid34=$(echoscip-shell system . . echo. $aOid | cutscip-shell system . . cut. -b 3-4)
25 if [scip-shell system . . `[`. "$aOid" != "$(calc_oid_file .git/lfs/objects/$aOid12/$aOid34/$aOid)" ]; then
26 echoscip-shell system . . echo. "oid for a.dat does not match"
27 exit 1
28 fi
29
30 bOid=$(gitscip-shell system . . git. log --patch b.dat | grepscip-shell system . . grep. "^+oid" | cutscip-shell system . . cut. -d ":" -f 2)
31 bOid12=$(echoscip-shell system . . echo. $bOid | cutscip-shell system . . cut. -b 1-2)
32 bOid34=$(echoscip-shell system . . echo. $bOid | cutscip-shell system . . cut. -b 3-4)
33 if [scip-shell system . . `[`. "$bOid" != "$(calc_oid_file .git/lfs/objects/$bOid12/$bOid34/$bOid)" ]; then
34 echoscip-shell system . . echo. "oid for b.dat does not match"
35 exit 1
36 fi
37
38 echoscip-shell system . . echo. "CORRUPTION" >> .git/lfs/objects/$aOid12/$aOid34/$aOid
39
40 moved=$(canonical_path "$TRASHDIR/$reponame/.git/lfs/bad")
41 expected="$(printfscip-shell system . . printf. 'objects: corruptObject: a.dat (%s) is corrupt
42 objects: repair: moving corrupt objects to %s' "$aOid" "$moved")"
43 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs fsck)" ]
44
45 [scip-shell system . . `[`. -e ".git/lfs/bad/$aOid" ]
46 [scip-shell system . . `[`. ! -e ".git/lfs/objects/$aOid12/$aOid34/$aOid" ]
47 [scip-shell system . . `[`. "$bOid" = "$(calc_oid_file .git/lfs/objects/$bOid12/$bOid34/$bOid)" ]
48 )
49 end_test
50
51 begin_test "fsck dry run"
52 (
53 set -e
54
55 reponame="fsck-dry-run"
56 gitscip-shell system . . git. init $reponame
57 cd $reponame
58
59 # Create a commit with some files tracked by git-lfs
60 gitscip-shell system . . git. lfs track *.dat
61 echoscip-shell system . . echo. "test data" > a.dat
62 echoscip-shell system . . echo. "test data 2" > b.dat
63 gitscip-shell system . . git. add .gitattributes *.dat
64 gitscip-shell system . . git. commit -m "first commit"
65
66 [scip-shell system . . `[`. "Git LFS fsck OK" = "$(gitscip-shell system . . git. lfs fsck --dry-run)" ]
67
68 aOid=$(gitscip-shell system . . git. log --patch a.dat | grepscip-shell system . . grep. "^+oid" | cutscip-shell system . . cut. -d ":" -f 2)
69 aOid12=$(echoscip-shell system . . echo. $aOid | cutscip-shell system . . cut. -b 1-2)
70 aOid34=$(echoscip-shell system . . echo. $aOid | cutscip-shell system . . cut. -b 3-4)
71 if [scip-shell system . . `[`. "$aOid" != "$(calc_oid_file .git/lfs/objects/$aOid12/$aOid34/$aOid)" ]; then
72 echoscip-shell system . . echo. "oid for a.dat does not match"
73 exit 1
74 fi
75
76 bOid=$(gitscip-shell system . . git. log --patch b.dat | grepscip-shell system . . grep. "^+oid" | cutscip-shell system . . cut. -d ":" -f 2)
77 bOid12=$(echoscip-shell system . . echo. $bOid | cutscip-shell system . . cut. -b 1-2)
78 bOid34=$(echoscip-shell system . . echo. $bOid | cutscip-shell system . . cut. -b 3-4)
79 if [scip-shell system . . `[`. "$bOid" != "$(calc_oid_file .git/lfs/objects/$bOid12/$bOid34/$bOid)" ]; then
80 echoscip-shell system . . echo. "oid for b.dat does not match"
81 exit 1
82 fi
83
84 echoscip-shell system . . echo. "CORRUPTION" >> .git/lfs/objects/$aOid12/$aOid34/$aOid
85
86 [scip-shell system . . `[`. "objects: corruptObject: a.dat ($aOid) is corrupt" = "$(gitscip-shell system . . git. lfs fsck --dry-run)" ]
87
88 if [scip-shell system . . `[`. "$aOid" = "$(calc_oid_file .git/lfs/objects/$aOid12/$aOid34/$aOid)" ]; then
89 echoscip-shell system . . echo. "oid for a.dat still matches match"
90 exit 1
91 fi
92
93 if [scip-shell system . . `[`. "$bOid" != "$(calc_oid_file .git/lfs/objects/$bOid12/$bOid34/$bOid)" ]; then
94 echoscip-shell system . . echo. "oid for b.dat does not match"
95 exit 1
96 fi
97 )
98 end_test
99
100 begin_test "fsck does not fail with shell characters in paths"
101 (
102 set -e
103
104 mkdirscip-shell system . . mkdir. '[[path]]'
105 cd '[[path]]'
106 reponame="fsck-shell-paths"
107 gitscip-shell system . . git. init $reponame
108 cd $reponame
109
110 # Create a commit with some files tracked by git-lfs
111 gitscip-shell system . . git. lfs track *.dat
112 echoscip-shell system . . echo. "test data" > a.dat
113 echoscip-shell system . . echo. "test data 2" > b.dat
114 gitscip-shell system . . git. add .gitattributes *.dat
115 gitscip-shell system . . git. commit -m "first commit"
116
117 # Verify that the pack code handles glob patterns properly.
118 gitscip-shell system . . git. gc --aggressive --prune=now
119
120 [scip-shell system . . `[`. "Git LFS fsck OK" = "$(gitscip-shell system . . git. lfs fsck)" ]
121 )
122 end_test
123
124 begin_test "fsck: outside git repository"
125 (
126 set +e
127 gitscip-shell system . . git. lfs fsck 2>&1 > fsck.log
128 res=$?
129 set -e
130
131 if [scip-shell system . . `[`. "$res" = "0" ]; then
132 echoscip-shell system . . echo. "Passes because $GIT_LFS_TEST_DIR is unset."
133 exit 0
134 fi
135 [scip-shell system . . `[`. "$res" = "128" ]
136 grepscip-shell system . . grep. "Not in a Git repository" fsck.log
137 )
138 end_test
139
140 create_invalid_pointersscip-shell shell shell-project 0.0.0 create_invalid_pointers().() {
141 valid="$1"
142 ext="${2:-dat}"
143
144 gitscip-shell system . . git. cat-file blob ":$valid" | awkscip-shell system . . awk. '{ sub(/$/, "\r"); print }' >"crlf.$ext"
145
146 # Test with a file size larger than the size of the read buffer used when
147 # decoding pointers. See https://github.com/git-lfs/git-lfs/issues/1729,
148 # https://github.com/git-lfs/git-lfs/pull/1796,
149 # and https://github.com/git-lfs/git-lfs/pull/4525.
150 max_pointer_size="$(lfstest-getlimit --max-pointer-size)"
151 lfstest-genrandom --base64 $((max_pointer_size + 1)) >"large.$ext"
152
153 gitscip-shell system . . git. \
154 -c "filter.lfs.process=" \
155 -c "filter.lfs.clean=cat" \
156 -c "filter.lfs.required=false" \
157 add "crlf.$ext" "large.$ext"
158 gitscip-shell system . . git. commit -m "invalid pointers"
159 }
160
161 setup_invalid_pointersscip-shell shell shell-project 0.0.0 setup_invalid_pointers(). () {
162 gitscip-shell system . . git. init $reponame
163 cd $reponame
164
165 # Create a commit with some files tracked by git-lfs
166 gitscip-shell system . . git. lfs track *.dat
167 echoscip-shell system . . echo. "test data" > a.dat
168 echoscip-shell system . . echo. "test data 2" > b.dat
169 gitscip-shell system . . git. add .gitattributes *.dat
170 gitscip-shell system . . git. commit -m "first commit"
171
172 create_invalid_pointersscip-shell shell shell-project 0.0.0 create_invalid_pointers(). "a.dat"
173 }
174
175 begin_test "fsck detects invalid pointers"
176 (
177 set -e
178
179 reponame="fsck-pointers"
180 setup_invalid_pointersscip-shell shell shell-project 0.0.0 setup_invalid_pointers().
181
182 set +e
183 gitscip-shell system . . git. lfs fsck >test.log 2>&1
184 RET=$?
185 gitscip-shell system . . git. lfs fsck --pointers >>test.log 2>&1
186 RET2=$?
187 set -e
188
189 [scip-shell system . . `[`. "$RET" -eq 1 ]
190 [scip-shell system . . `[`. "$RET2" -eq 1 ]
191 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'pointer: nonCanonicalPointer: Pointer.*was not canonical' test.log) -eq 2 ]
192 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'pointer: unexpectedGitObject: "large.dat".*should have been a pointer but was not' test.log) -eq 2 ]
193 )
194 end_test
195
196 begin_test "fsck detects invalid pointers with macro patterns"
197 (
198 set -e
199
200 reponame="fsck-pointers-macros"
201 gitscip-shell system . . git. init $reponame
202 cd $reponame
203
204 printfscip-shell system . . printf. '[attr]lfs filter=lfs diff=lfs merge=lfs -text\n*.dat lfs\n' \
205 >.gitattributes
206 echoscip-shell system . . echo. "test data" >a.dat
207 mkdirscip-shell system . . mkdir. dir
208 printfscip-shell system . . printf. '*.bin lfs\n' >dir/.gitattributes
209 gitscip-shell system . . git. add .gitattributes a.dat dir
210 gitscip-shell system . . git. commit -m "first commit"
211
212 create_invalid_pointersscip-shell shell shell-project 0.0.0 create_invalid_pointers(). "a.dat"
213
214 cd dir
215 create_invalid_pointersscip-shell shell shell-project 0.0.0 create_invalid_pointers(). "a.dat" "bin"
216 cd ..
217
218 # NOTE: We should also create a .dir directory with the same files as
219 # as in the dir/ directory, and confirm those .dir/*.bin files are
220 # reported by "git lfs fsck" as well. However, at the moment
221 # "git lfs fsck" will not resolve a macro attribute reference
222 # in .dir/.gitattributes because it sorts that file before
223 # .gitattributes and then processes them in that order.
224
225 set +e
226 gitscip-shell system . . git. lfs fsck >test.log 2>&1
227 RET=$?
228 gitscip-shell system . . git. lfs fsck --pointers >>test.log 2>&1
229 RET2=$?
230 set -e
231
232 [scip-shell system . . `[`. "$RET" -eq 1 ]
233 [scip-shell system . . `[`. "$RET2" -eq 1 ]
234 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'pointer: nonCanonicalPointer: Pointer.*was not canonical' test.log) -eq 4 ]
235 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'pointer: unexpectedGitObject: "large.dat".*should have been a pointer but was not' test.log) -eq 2 ]
236 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'pointer: unexpectedGitObject: "dir/large.bin".*should have been a pointer but was not' test.log) -eq 2 ]
237 )
238 end_test
239
240 begin_test "fsck detects invalid pointers with GIT_OBJECT_DIRECTORY"
241 (
242 set -e
243
244 reponame="fsck-pointers-object-directory"
245 setup_invalid_pointersscip-shell shell shell-project 0.0.0 setup_invalid_pointers().
246
247 head=$(gitscip-shell system . . git. rev-parse HEAD)
248 objdir="$(lfstest-realpath .git/objects)"
249 cd ..
250 gitscip-shell system . . git. init "$reponame-2"
251 gitdir="$(lfstest-realpath "$reponame-2/.git")"
252 GIT_WORK_TREE="$reponame-2" GIT_DIR="$gitdir" GIT_OBJECT_DIRECTORY="$objdir" gitscip-shell system . . git. update-ref refs/heads/main "$head"
253
254 set +e
255 GIT_WORK_TREE="$reponame-2" GIT_DIR="$gitdir" GIT_OBJECT_DIRECTORY="$objdir" gitscip-shell system . . git. lfs fsck --pointers >test.log 2>&1
256 RET=$?
257 set -e
258
259 [scip-shell system . . `[`. "$RET" -eq 1 ]
260 grepscip-shell system . . grep. 'pointer: nonCanonicalPointer: Pointer.*was not canonical' test.log
261 grepscip-shell system . . grep. 'pointer: unexpectedGitObject: "large.dat".*should have been a pointer but was not' test.log
262 )
263 end_test
264
265 begin_test "fsck does not detect invalid pointers with no LFS objects"
266 (
267 set -e
268
269 reponame="fsck-pointers-none"
270 gitscip-shell system . . git. init "$reponame"
271 cd "$reponame"
272
273 echoscip-shell system . . echo. "# README" > README.md
274 gitscip-shell system . . git. add README.md
275 gitscip-shell system . . git. commit -m "Add README"
276
277 gitscip-shell system . . git. lfs fsck
278 gitscip-shell system . . git. lfs fsck --pointers
279 )
280 end_test
281
282 begin_test "fsck does not detect invalid pointers with symlinks"
283 (
284 set -e
285
286 reponame="fsck-pointers-symlinks"
287 gitscip-shell system . . git. init "$reponame"
288 cd "$reponame"
289
290 gitscip-shell system . . git. lfs track '*.dat'
291
292 echoscip-shell system . . echo. "# Test" > a.dat
293 lnscip-shell system . . ln. -s a.dat b.dat
294 gitscip-shell system . . git. add .gitattributes *.dat
295 gitscip-shell system . . git. commit -m "Add files"
296
297 gitscip-shell system . . git. lfs fsck
298 gitscip-shell system . . git. lfs fsck --pointers
299 )
300 end_test
301
302 begin_test "fsck does not detect invalid pointers with negated patterns"
303 (
304 set -e
305
306 reponame="fsck-pointers-none"
307 gitscip-shell system . . git. init "$reponame"
308 cd "$reponame"
309
310 catscip-shell system . . cat. > .gitattributes <<EOF
311 *.dat filter=lfs diff=lfs merge=lfs -text
312 b.dat !filter !diff !merge text
313 EOF
314
315 echoscip-shell system . . echo. "# Test" > a.dat
316 cpscip-shell system . . cp. a.dat b.dat
317 gitscip-shell system . . git. add .gitattributes *.dat
318 gitscip-shell system . . git. commit -m "Add files"
319
320 gitscip-shell system . . git. lfs fsck
321 gitscip-shell system . . git. lfs fsck --pointers
322 )
323 end_test
324
325 begin_test "fsck does not detect invalid pointers with negated macro patterns"
326 (
327 set -e
328
329 reponame="fsck-pointers-macros-none"
330 gitscip-shell system . . git. init "$reponame"
331 cd "$reponame"
332
333 printfscip-shell system . . printf. '[attr]lfs filter=lfs diff=lfs merge=lfs -text\n*.dat lfs\nb.dat !lfs\n' \
334 >.gitattributes
335 echoscip-shell system . . echo. "test data" >a.dat
336 cpscip-shell system . . cp. a.dat b.dat
337 mkdirscip-shell system . . mkdir. dir .dir
338 printfscip-shell system . . printf. '*.dat !lfs\n' >dir/.gitattributes
339 cpscip-shell system . . cp. b.dat dir
340 printfscip-shell system . . printf. '*.dat !lfs\n' >.dir/.gitattributes
341 cpscip-shell system . . cp. b.dat .dir
342 gitscip-shell system . . git. add .gitattributes *.dat dir .dir
343 gitscip-shell system . . git. commit -m "first commit"
344
345 # NOTE: The "git lfs fsck" command exempts the .dir/b.dat file from the
346 # *.dat pattern from the top-level .gitattributes and so permits
347 # it as a valid non-pointer file; however, it permits it for a
348 # different reason than the dir/b.dat file, because it processes
349 # the .dir/.gitattributes file before the .gitattributes one
350 # and does not recognize the "!lfs" macro attribute reference until
351 # after it has processed .gitattributes. Ideally both the dir/
352 # and .dir/ directories should be processed identically.
353
354 gitscip-shell system . . git. lfs fsck
355 gitscip-shell system . . git. lfs fsck --pointers
356 )
357 end_test
358
359 setup_invalid_objectsscip-shell shell shell-project 0.0.0 setup_invalid_objects(). () {
360 gitscip-shell system . . git. init $reponame
361 cd $reponame
362
363 # Create a commit with some files tracked by git-lfs
364 gitscip-shell system . . git. lfs track *.dat
365 echoscip-shell system . . echo. "test data" > a.dat
366 echoscip-shell system . . echo. "test data 2" > b.dat
367 mkdirscip-shell system . . mkdir. foo
368 echoscip-shell system . . echo. "test test 3" > foo/a.dat
369 echoscip-shell system . . echo. "test data 4" > foo/b.dat
370 gitscip-shell system . . git. add .gitattributes *.dat foo
371 gitscip-shell system . . git. commit -m "first commit"
372
373 oid1=$(calc_oid_file a.dat)
374 oid2=$(calc_oid_file b.dat)
375 oid3=$(calc_oid_file foo/a.dat)
376 oid4=$(calc_oid_file foo/b.dat)
377 echoscip-shell system . . echo. "CORRUPTION" >>".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
378 rmscip-shell system . . rm. ".git/lfs/objects/${oid2:0:2}/${oid2:2:2}/$oid2"
379 echoscip-shell system . . echo. "CORRUPTION" >>".git/lfs/objects/${oid3:0:2}/${oid3:2:2}/$oid3"
380 rmscip-shell system . . rm. ".git/lfs/objects/${oid4:0:2}/${oid4:2:2}/$oid4"
381 }
382
383 begin_test "fsck detects invalid objects"
384 (
385 set -e
386
387 reponame="fsck-objects"
388 setup_invalid_objectsscip-shell shell shell-project 0.0.0 setup_invalid_objects().
389
390 set +e
391 gitscip-shell system . . git. lfs fsck >test.log 2>&1
392 RET=$?
393 set -e
394
395 [scip-shell system . . `[`. "$RET" -eq 1 ]
396 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: corruptObject: a.dat (.*) is corrupt' test.log) -eq 1 ]
397 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: openError: b.dat (.*) could not be checked: .*' test.log) -eq 1 ]
398 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: corruptObject: foo/a.dat (.*) is corrupt' test.log) -eq 1 ]
399 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: openError: foo/b.dat (.*) could not be checked: .*' test.log) -eq 1 ]
400 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: repair: moving corrupt objects to .*' test.log) -eq 1 ]
401
402 cd ..
403 rmscip-shell system . . rm. -rf $reponame
404 setup_invalid_objectsscip-shell shell shell-project 0.0.0 setup_invalid_objects().
405
406 set +e
407 gitscip-shell system . . git. lfs fsck --objects >test.log 2>&1
408 RET=$?
409 set -e
410
411 [scip-shell system . . `[`. "$RET" -eq 1 ]
412 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: corruptObject: a.dat (.*) is corrupt' test.log) -eq 1 ]
413 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: openError: b.dat (.*) could not be checked: .*' test.log) -eq 1 ]
414 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: corruptObject: foo/a.dat (.*) is corrupt' test.log) -eq 1 ]
415 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: openError: foo/b.dat (.*) could not be checked: .*' test.log) -eq 1 ]
416 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: repair: moving corrupt objects to .*' test.log) -eq 1 ]
417 )
418 end_test
419
420 begin_test "fsck detects invalid objects except in excluded paths"
421 (
422 set -e
423
424 reponame="fsck-objects-exclude"
425 setup_invalid_objectsscip-shell shell shell-project 0.0.0 setup_invalid_objects().
426
427 # We need to prevent MSYS from rewriting /foo into a Windows path.
428 MSYS_NO_PATHCONV=1 gitscip-shell system . . git. config "lfs.fetchexclude" "/fooscip-shell filesystem . . `/foo`."
429
430 set +e
431 gitscip-shell system . . git. lfs fsck >test.log 2>&1
432 RET=$?
433 set -e
434
435 [scip-shell system . . `[`. "$RET" -eq 1 ]
436 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: corruptObject: a.dat (.*) is corrupt' test.log) -eq 1 ]
437 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: openError: b.dat (.*) could not be checked: .*' test.log) -eq 1 ]
438 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: corruptObject: foo/a.dat (.*) is corrupt' test.log) -eq 0 ]
439 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: openError: foo/b.dat (.*) could not be checked: .*' test.log) -eq 0 ]
440 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: repair: moving corrupt objects to .*' test.log) -eq 1 ]
441
442 cd ..
443 rmscip-shell system . . rm. -rf $reponame
444 setup_invalid_objectsscip-shell shell shell-project 0.0.0 setup_invalid_objects().
445
446 # We need to prevent MSYS from rewriting /foo into a Windows path.
447 MSYS_NO_PATHCONV=1 gitscip-shell system . . git. config "lfs.fetchexclude" "/fooscip-shell filesystem . . `/foo`."
448
449 set +e
450 gitscip-shell system . . git. lfs fsck --objects >test.log 2>&1
451 RET=$?
452 set -e
453
454 [scip-shell system . . `[`. "$RET" -eq 1 ]
455 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: corruptObject: a.dat (.*) is corrupt' test.log) -eq 1 ]
456 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: openError: b.dat (.*) could not be checked: .*' test.log) -eq 1 ]
457 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: corruptObject: foo/a.dat (.*) is corrupt' test.log) -eq 0 ]
458 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: openError: foo/b.dat (.*) could not be checked: .*' test.log) -eq 0 ]
459 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c 'objects: repair: moving corrupt objects to .*' test.log) -eq 1 ]
460 )
461 end_test
462
463 begin_test "fsck does not detect invalid objects with no LFS objects"
464 (
465 set -e
466
467 reponame="fsck-objects-none"
468 gitscip-shell system . . git. init "$reponame"
469 cd "$reponame"
470
471 echoscip-shell system . . echo. "# README" > README.md
472 gitscip-shell system . . git. add README.md
473 gitscip-shell system . . git. commit -m "Add README"
474
475 gitscip-shell system . . git. lfs fsck
476 gitscip-shell system . . git. lfs fsck --objects
477 )
478 end_test
479
480 begin_test "fsck operates on specified refs"
481 (
482 set -e
483
484 reponame="fsck-refs"
485 setup_invalid_pointersscip-shell shell shell-project 0.0.0 setup_invalid_pointers().
486
487 gitscip-shell system . . git. rm -f crlf.dat large.dat
488 echoscip-shell system . . echo. "# Test" > new.dat
489 gitscip-shell system . . git. add new.dat
490 gitscip-shell system . . git. commit -m 'third commit'
491
492 gitscip-shell system . . git. commit --allow-empty -m 'fourth commit'
493
494 # Should succeed. (HEAD and index).
495
496 gitscip-shell system . . git. lfs fsck
497 gitscip-shell system . . git. lfs fsck HEAD
498 gitscip-shell system . . git. lfs fsck HEAD^^ && exit 1
499 gitscip-shell system . . git. lfs fsck HEAD^
500 gitscip-shell system . . git. lfs fsck HEAD^..HEAD
501 gitscip-shell system . . git. lfs fsck HEAD^^^..HEAD && exit 1
502 gitscip-shell system . . git. lfs fsck HEAD^^^..HEAD^ && exit 1
503
504 gitscip-shell system . . git. lfs fsck --pointers HEAD^^^..HEAD^^ >test.log 2>&1 && exit 1
505
506 grepscip-shell system . . grep. 'pointer: nonCanonicalPointer: Pointer.*was not canonical' test.log
507 grepscip-shell system . . grep. 'pointer: unexpectedGitObject: "large.dat".*should have been a pointer but was not' test.log
508
509 oid=$(calc_oid_file new.dat)
510 echoscip-shell system . . echo. "CORRUPTION" >>".git/lfs/objects/${oid:0:2}/${oid:2:2}/$oid"
511
512 gitscip-shell system . . git. lfs fsck --objects HEAD^^..HEAD^ >test.log 2>&1 && exit 1
513
514 grepscip-shell system . . grep. 'objects: corruptObject: new.dat (.*) is corrupt' test.log
515 grepscip-shell system . . grep. 'objects: repair: moving corrupt objects to .*' test.log
516
517 # Make the result of the subshell a success.
518 truescip-shell system . . true.
519 )
520 end_test
521
522 begin_test "fsck detects invalid ref"
523 (
524 set -e
525 reponame="fsck-default"
526 gitscip-shell system . . git. init $reponame
527 cd $reponame
528
529 gitscip-shell system . . git. lfs fsck jibberish >fsck.log 2>&1 && exit 1
530 grepscip-shell system . . grep. "can't resolve ref" fsck.log
531 )
532 end_test