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