Debian Codegraph @

t/t-status.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 "status"
6 (
7 set -e
8
9 mkdirscip-shell system . . mkdir. repo-1
10 cd repo-1
11 gitscip-shell system . . git. init
12 gitscip-shell system . . git. lfs track "*.dat"
13
14 file_1="some data"
15 file_1_oid="$(calc_oid "$file_1")"
16 file_1_oid_short="$(echoscip-shell system . . echo. "$file_1_oid" | headscip-shell system . . head. -c 7)"
17 printfscip-shell system . . printf. "%s" "$file_1" > file1.dat
18 gitscip-shell system . . git. add file1.dat
19 gitscip-shell system . . git. commit -m "file1.dat"
20
21 file_1_new="other data"
22 file_1_new_oid="$(calc_oid "$file_1_new")"
23 file_1_new_oid_short="$(echoscip-shell system . . echo. "$file_1_new_oid" | headscip-shell system . . head. -c 7)"
24 printfscip-shell system . . printf. "%s" "$file_1_new" > file1.dat
25
26 file_2="file2 data"
27 file_2_oid="$(calc_oid "$file_2")"
28 file_2_oid_short="$(echoscip-shell system . . echo. "$file_2_oid" | headscip-shell system . . head. -c 7)"
29 printfscip-shell system . . printf. "%s" "$file_2" > file2.dat
30 gitscip-shell system . . git. add file2.dat
31
32 file_3="file3 data"
33 file_3_oid="$(calc_oid "$file_3")"
34 file_3_oid_short="$(echoscip-shell system . . echo. "$file_3_oid" | headscip-shell system . . head. -c 7)"
35 printfscip-shell system . . printf. "%s" "$file_3" > file3.dat
36 gitscip-shell system . . git. add file3.dat
37
38 file_3_new="file3 other data"
39 file_3_new_oid="$(calc_oid "$file_3_new")"
40 file_3_new_oid_short="$(echoscip-shell system . . echo. "$file_3_new_oid" | headscip-shell system . . head. -c 7)"
41 printfscip-shell system . . printf. "%s" "$file_3_new" > file3.dat
42
43 expected="On branch main
44
45 Objects to be committed:
46
47 file2.dat (LFS: $file_2_oid_short)
48 file3.dat (LFS: $file_3_oid_short)
49
50 Objects not staged for commit:
51
52 file1.dat (LFS: $file_1_oid_short -> File: $file_1_new_oid_short)
53 file3.dat (File: $file_3_new_oid_short)"
54
55 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs status)" ]
56 )
57 end_test
58
59 begin_test "status --porcelain"
60 (
61 set -e
62
63 mkdirscip-shell system . . mkdir. repo-2
64 cd repo-2
65 gitscip-shell system . . git. init
66 gitscip-shell system . . git. lfs track "*.dat"
67 echoscip-shell system . . echo. "some data" > file1.dat
68 gitscip-shell system . . git. add file1.dat
69 gitscip-shell system . . git. commit -m "file1.dat"
70
71 echoscip-shell system . . echo. "other data" > file1.dat
72 echoscip-shell system . . echo. "file2 data" > file2.dat
73 gitscip-shell system . . git. add file2.dat
74
75 echoscip-shell system . . echo. "file3 data" > file3.dat
76 gitscip-shell system . . git. add file3.dat
77
78 echoscip-shell system . . echo. "file3 other data" > file3.dat
79
80 expected=" M file1.dat
81 A file3.dat
82 A file2.dat"
83
84 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs status --porcelain)" ]
85 )
86 end_test
87
88 begin_test "status --json"
89 (
90 set -e
91
92 mkdirscip-shell system . . mkdir. repo-3
93 cd repo-3
94 gitscip-shell system . . git. init
95 gitscip-shell system . . git. lfs track "*.dat"
96 echoscip-shell system . . echo. "some data" > file1.dat
97 gitscip-shell system . . git. add file1.dat
98 gitscip-shell system . . git. commit -m "file1.dat"
99
100 echoscip-shell system . . echo. "other data" > file1.dat
101
102 expected='{"files":{"file1.dat":{"status":"M"}}}'
103 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs status --json)" ]
104
105 gitscip-shell system . . git. add file1.dat
106 gitscip-shell system . . git. commit -m "file1.dat changed"
107 gitscip-shell system . . git. mv file1.dat file2.dat
108
109 expected='{"files":{"file2.dat":{"status":"R","from":"file1.dat"}}}'
110 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs status --json)" ]
111
112 gitscip-shell system . . git. commit -m "file1.dat -> file2.dat"
113
114 # Ensure status --json does not include non-lfs files
115 echoscip-shell system . . echo. hi > test1.txt
116 gitscip-shell system . . git. add test1.txt
117 expected='{"files":{}}'
118 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs status --json)" ]
119 )
120 end_test
121
122 begin_test "status in a sub-directory"
123 (
124 set -e
125
126 reponame="status-sub-directory"
127 gitscip-shell system . . git. init "$reponame"
128 cd "$reponame"
129
130 gitscip-shell system . . git. lfs track "*.dat"
131 printfscip-shell system . . printf. "asdf" > file.dat
132 mkdirscip-shell system . . mkdir. -p dir
133 gitscip-shell system . . git. add .gitattributes file.dat
134 gitscip-shell system . . git. commit -m "initial commit"
135
136 printfscip-shell system . . printf. "ASDF" > file.dat
137
138 expected="On branch main
139
140 Objects to be committed:
141
142
143 Objects not staged for commit:
144
145 ../file.dat (LFS: f0e4c2f -> File: 99b3bcf)"
146
147 [scip-shell system . . `[`. "$expected" = "$(cd dir && gitscip-shell system . . git. lfs status)" ]
148 )
149 end_test
150
151 begin_test "status: outside git repository"
152 (
153 set +e
154 gitscip-shell system . . git. lfs status 2>&1 > status.log
155 res=$?
156
157 set -e
158 if [scip-shell system . . `[`. "$res" = "0" ]; then
159 echoscip-shell system . . echo. "Passes because $GIT_LFS_TEST_DIR is unset."
160 exit 0
161 fi
162 [scip-shell system . . `[`. "$res" = "128" ]
163 grepscip-shell system . . grep. "Not in a Git repository" status.log
164 )
165 end_test
166
167 begin_test "status - before initial commit"
168 (
169 set -e
170
171 gitscip-shell system . . git. init repo-initial
172 cd repo-initial
173 gitscip-shell system . . git. lfs track "*.dat"
174
175 # should not fail when nothing to display (ignore output, will be blank)
176 gitscip-shell system . . git. lfs status
177
178 contents="some data"
179 contents_oid="$(calc_oid "$contents")"
180 contents_oid_short="$(echoscip-shell system . . echo. "$contents_oid" | headscip-shell system . . head. -c 7)"
181
182 printfscip-shell system . . printf. "%s" "$contents" > file1.dat
183 gitscip-shell system . . git. add file1.dat
184
185 expected="
186 Objects to be committed:
187
188 file1.dat (LFS: $contents_oid_short)
189
190 Objects not staged for commit:"
191
192 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs status)" ]
193 )
194 end_test
195
196 begin_test "status shows multiple files with identical contents"
197 (
198 set -e
199
200 reponame="uniq-status"
201 mkdirscip-shell system . . mkdir. "$reponame"
202 cd "$reponame"
203
204 gitscip-shell system . . git. init
205 gitscip-shell system . . git. lfs track "*.dat"
206
207 contents="contents"
208 printfscip-shell system . . printf. "%s" "$contents" > a.dat
209 printfscip-shell system . . printf. "%s" "$contents" > b.dat
210
211 gitscip-shell system . . git. add --all .
212
213 gitscip-shell system . . git. lfs status | teescip-shell system . . tee. status.log
214
215 [scip-shell system . . `[`. "1" -eq "$(grepscip-shell system . . grep. -c "a.dat" status.log)" ]
216 [scip-shell system . . `[`. "1" -eq "$(grepscip-shell system . . grep. -c "b.dat" status.log)" ]
217 )
218 end_test
219
220 begin_test "status shows multiple copies of partially staged files"
221 (
222 set -e
223
224 reponame="status-partially-staged"
225 gitscip-shell system . . git. init "$reponame"
226 cd "$reponame"
227
228 gitscip-shell system . . git. lfs track "*.dat"
229 gitscip-shell system . . git. add .gitattributes
230 gitscip-shell system . . git. commit -m "initial commit"
231
232 contents_1="part 1"
233 contents_1_oid="$(calc_oid "$contents_1")"
234 contents_1_oid_short="$(echoscip-shell system . . echo. "$contents_1_oid" | headscip-shell system . . head. -c 7)"
235 printfscip-shell system . . printf. "%s" "$contents_1" > a.dat
236
237 # "$contents_1" changes are staged
238 gitscip-shell system . . git. add a.dat
239
240 # "$contents_2" changes are unstaged
241 contents_2="part 2"
242 contents_2_oid="$(calc_oid "$contents_2")"
243 contents_2_oid_short="$(echoscip-shell system . . echo. "$contents_2_oid" | headscip-shell system . . head. -c 7)"
244 printfscip-shell system . . printf. "%s" "$contents_2" > a.dat
245
246 expected="On branch main
247
248 Objects to be committed:
249
250 a.dat (LFS: $contents_1_oid_short)
251
252 Objects not staged for commit:
253
254 a.dat (File: $contents_2_oid_short)"
255 actual="$(gitscip-shell system . . git. lfs status)"
256
257 diffscip-shell system . . diff. -u <(echoscip-shell system . . echo. "$expected") <(echoscip-shell system . . echo. "$actual")
258 )
259 end_test
260
261 begin_test "status: LFS to LFS change"
262 (
263 set -e
264
265 reponame="status-lfs-to-lfs-change"
266 setup_remote_repo "$reponame"
267 clone_repo "$reponame" "$reponame"
268
269 contents="contents"
270 contents_oid="$(calc_oid "$contents")"
271 contents_oid_short="$(echoscip-shell system . . echo. "$contents_oid" | headscip-shell system . . head. -c 7)"
272
273 gitscip-shell system . . git. lfs track "*.dat"
274 gitscip-shell system . . git. add .gitattributes
275 gitscip-shell system . . git. commit -m "track *.dat files"
276
277 printfscip-shell system . . printf. "%s" "$contents" > a.dat
278 gitscip-shell system . . git. add a.dat
279 gitscip-shell system . . git. commit -m "add a.dat"
280
281 contents_new="$contents +extra"
282 contents_new_oid="$(calc_oid "$contents_new")"
283 contents_new_oid_short="$(echoscip-shell system . . echo. $contents_new_oid | headscip-shell system . . head. -c 7)"
284
285 printfscip-shell system . . printf. "%s" "$contents_new" > a.dat
286 gitscip-shell system . . git. add a.dat
287
288 expected="On branch main
289
290 Objects to be committed:
291
292 a.dat (LFS: $contents_oid_short -> LFS: $contents_new_oid_short)
293
294 Objects not staged for commit:"
295 actual="$(gitscip-shell system . . git. lfs status)"
296
297 [scip-shell system . . `[`. "$expected" = "$actual" ]
298 )
299 end_test
300
301 begin_test "status: Git to LFS change"
302 (
303 set -e
304
305 reponame="status-git-to-lfs-change"
306 setup_remote_repo "$reponame"
307 clone_repo "$reponame" "$reponame"
308
309 contents="contents"
310 contents_oid="$(calc_oid "$contents")"
311 contents_oid_short="$(echoscip-shell system . . echo. "$contents_oid" | headscip-shell system . . head. -c 7)"
312
313 printfscip-shell system . . printf. "%s" "$contents" > a.dat
314 gitscip-shell system . . git. add a.dat
315 gitscip-shell system . . git. commit -m "add a.dat"
316
317 gitscip-shell system . . git. lfs track "*.dat"
318 gitscip-shell system . . git. add .gitattributes
319 gitscip-shell system . . git. commit -m "track *.dat files"
320
321 contents_new="$contents +extra"
322 contents_new_oid="$(calc_oid "$contents_new")"
323 contents_new_oid_short="$(echoscip-shell system . . echo. $contents_new_oid | headscip-shell system . . head. -c 7)"
324
325 printfscip-shell system . . printf. "%s" "$contents_new" > a.dat
326 gitscip-shell system . . git. add a.dat
327
328 expected="On branch main
329
330 Objects to be committed:
331
332 a.dat (Git: $contents_oid_short -> LFS: $contents_new_oid_short)
333
334 Objects not staged for commit:"
335 actual="$(gitscip-shell system . . git. lfs status)"
336
337 [scip-shell system . . `[`. "$expected" = "$actual" ]
338 )
339 end_test
340
341 begin_test "status: Git to LFS conversion"
342 (
343 set -e
344
345 reponame="status-git-to-lfs-conversion"
346 setup_remote_repo "$reponame"
347 clone_repo "$reponame" "$reponame"
348
349 contents="contents"
350 contents_oid="$(calc_oid "$contents")"
351 contents_oid_short="$(echoscip-shell system . . echo. "$contents_oid" | headscip-shell system . . head. -c 7)"
352
353 printfscip-shell system . . printf. "%s" "$contents" > a.dat
354 gitscip-shell system . . git. add a.dat
355 gitscip-shell system . . git. commit -m "add a.dat"
356
357 gitscip-shell system . . git. lfs track "*.dat"
358 gitscip-shell system . . git. add .gitattributes
359 gitscip-shell system . . git. commit -m "track *.dat"
360
361 gitscip-shell system . . git. push origin main
362
363 pushd "$TRASHDIR" > /dev/nullscip-shell filesystem . . `/dev/null`.
364 clone_repo "$reponame" "$reponame-2"
365
366 gitscip-shell system . . git. add a.dat
367
368 gitscip-shell system . . git. lfs status 2>&1 | teescip-shell system . . tee. status.log
369 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
370 echoscip-shell system . . echo. >&2 "git lfs status should have succeeded, didn't ..."
371 exit 1
372 fi
373
374 expected="On branch main
375 Objects to be pushed to origin/main:
376
377
378 Objects to be committed:
379
380 a.dat (Git: $contents_oid_short -> LFS: $contents_oid_short)
381
382 Objects not staged for commit:"
383 actual="$(catscip-shell system . . cat. status.log)"
384
385 [scip-shell system . . `[`. "$expected" = "$actual" ]
386 popd > /dev/nullscip-shell filesystem . . `/dev/null`.
387 )
388 end_test
389
390 begin_test "status (missing objects)"
391 (
392 set -e
393
394 reponame="status-missing-objects"
395 gitscip-shell system . . git. init "$reponame"
396 cd "$reponame"
397
398 gitscip-shell system . . git. lfs track "*.dat"
399 printfscip-shell system . . printf. "a" > a.dat
400
401 gitscip-shell system . . git. add .gitattributes a.dat
402 gitscip-shell system . . git. commit -m "initial commit"
403
404 # Remove the original object "a.dat" (ensure '--no-filters' is not given).
405 oid="$(gitscip-shell system . . git. hash-object -t blob -- a.dat)"
406 rmscip-shell system . . rm. -rf ".git/objects/${oid:0:2}/${oid:2}"
407
408 # Create an unstaged change against a source file that doesn't exist.
409 printfscip-shell system . . printf. "b" > a.dat
410 gitscip-shell system . . git. add a.dat
411
412 gitscip-shell system . . git. lfs status \
413 | grepscip-shell system . . grep. "a.dat (?: <missing> -> LFS: $(calc_oid b | headscip-shell system . . head. -c 7))"
414 )
415 end_test
416
417 begin_test "status (unpushed objects)"
418 (
419 set -e
420
421 reponame="status-unpushed-objects"
422 setup_remote_repo "$reponame"
423 clone_repo "$reponame" "$reponame"
424
425 gitscip-shell system . . git. lfs track "*.dat"
426 gitscip-shell system . . git. add .gitattributes
427 gitscip-shell system . . git. commit -m "initial commit"
428
429 gitscip-shell system . . git. push -u origin main
430
431 contents="a"
432 oid="$(calc_oid "$contents")"
433 printfscip-shell system . . printf. "%s" "$contents" > a.dat
434
435 gitscip-shell system . . git. add a.dat
436 gitscip-shell system . . git. commit -m "add a large file"
437
438 expected="On branch main
439 Objects to be pushed to origin/main:
440
441 a.dat ($oid)
442
443 Objects to be committed:
444
445
446 Objects not staged for commit:"
447
448 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs status)" ]
449 )
450 end_test
451
452 begin_test "status (without a working copy)"
453 (
454 reponame="status-no-working-copy.git"
455
456 gitscip-shell system . . git. init --bare "$reponame"
457 cd "$reponame"
458
459 gitscip-shell system . . git. lfs status 2>&1 | teescip-shell system . . tee. status.log
460 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
461 echoscip-shell system . . echo. >&2 "git lfs status should have failed, didn't ..."
462 exit 1
463 fi
464 [scip-shell system . . `[`. "This operation must be run in a work tree." = "$(catscip-shell system . . cat. status.log)" ]
465 )
466 end_test
467
468 begin_test "status (deleted files)"
469 (
470 set -e
471
472 reponame="status-deleted-files"
473 setup_remote_repo "$reponame"
474 clone_repo "$reponame" "$reponame"
475
476 gitscip-shell system . . git. lfs track "*.dat"
477 gitscip-shell system . . git. add .gitattributes
478 gitscip-shell system . . git. commit -m "initial commit"
479
480 gitscip-shell system . . git. push -u origin main
481
482 contents="a"
483 oid="$(calc_oid "$contents")"
484 oid_short="$(calc_oid "$contents" | headscip-shell system . . head. -c 7)"
485 printfscip-shell system . . printf. "%s" "$contents" > a.dat
486
487 gitscip-shell system . . git. add a.dat
488 gitscip-shell system . . git. commit -m "add a large file"
489
490 gitscip-shell system . . git. rm a.dat
491
492 expected="On branch main
493 Objects to be pushed to origin/main:
494
495 a.dat ($oid)
496
497 Objects to be committed:
498
499 a.dat (LFS: $oid_short -> File: deleted)
500
501 Objects not staged for commit:"
502
503 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs status)" ]
504 )
505 end_test
506
507 begin_test "status (file to dir)"
508 (
509 set -e
510
511 reponame="status-file-to-dir"
512 setup_remote_repo "$reponame"
513 clone_repo "$reponame" "$reponame"
514
515 gitscip-shell system . . git. lfs track "*.dat"
516 gitscip-shell system . . git. add .gitattributes
517 gitscip-shell system . . git. commit -m "initial commit"
518
519 printfscip-shell system . . printf. 'file' > test
520 gitscip-shell system . . git. add test
521 gitscip-shell system . . git. commit -m "add test"
522
523 obj=$(calc_oid "file" | headscip-shell system . . head. -c 7)
524
525 gitscip-shell system . . git. rm test
526 mkdirscip-shell system . . mkdir. test
527
528 contents="a"
529 oid="$(calc_oid "$contents")"
530 oid_short="$(calc_oid "$contents" | headscip-shell system . . head. -c 7)"
531 printfscip-shell system . . printf. "%s" "$contents" > test/a.dat
532
533 gitscip-shell system . . git. add test
534 gitscip-shell system . . git. commit -m "add files"
535
536 gitscip-shell system . . git. reset HEAD~
537 gitscip-shell system . . git. add test
538
539 expected="On branch main
540
541 Objects to be committed:
542
543 test (Git: $obj -> File: deleted)
544 test/a.dat (LFS: $oid_short)
545
546 Objects not staged for commit:"
547
548 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs status)" ]
549 )
550 end_test
551
552
553 begin_test "status: permission change"
554 (
555 set -e
556
557 # We're using chmod below.
558 if [scip-shell system . . `[`. "$IS_WINDOWS" -eq 1 ]; then
559 exit 0
560 fi
561
562 reponame="status-permission-change"
563 setup_remote_repo "$reponame"
564 clone_repo "$reponame" "$reponame"
565
566 contents="contents"
567
568 gitscip-shell system . . git. lfs track "*.dat"
569 gitscip-shell system . . git. add .gitattributes
570 gitscip-shell system . . git. commit -m "track *.dat"
571
572 printfscip-shell system . . printf. "%s" "$contents" > a.dat
573 gitscip-shell system . . git. add a.dat
574 gitscip-shell system . . git. commit -m "add a.dat"
575
576 chmodscip-shell system . . chmod. 400 a.dat
577
578 # A permission change should not result in any output.
579 gitscip-shell system . . git. lfs status 2>&1 | teescip-shell system . . tee. status.log
580 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
581 echoscip-shell system . . echo. >&2 "git lfs status should have succeeded, didn't ..."
582 exit 1
583 fi
584
585 expected="On branch main
586
587 Objects to be committed:
588
589
590 Objects not staged for commit:"
591 actual="$(catscip-shell system . . cat. status.log)"
592
593 [scip-shell system . . `[`. "$expected" = "$actual" ]
594 )
595 end_test