File: t-ls-files.sh

package info (click to toggle)
git-lfs 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,808 kB
  • sloc: sh: 21,256; makefile: 507; ruby: 417
file content (1040 lines) | stat: -rwxr-xr-x 21,936 bytes parent folder | download
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
#!/usr/bin/env bash

. "$(dirname "$0")/testlib.sh"

begin_test "ls-files"
(
  set -e

  mkdir repo
  cd repo
  git init
  git lfs track "*.dat" | grep "Tracking \"\*.dat\""
  echo "some data" > some.dat
  echo "some text" > some.txt
  echo "missing" > missing.dat
  git add missing.dat
  git commit -m "add missing file"
  [ "6bbd052ab0 * missing.dat" = "$(git lfs ls-files)" ]

  git rm missing.dat
  git add some.dat some.txt
  git commit -m "added some files, removed missing one"

  git lfs ls-files | tee ls.log
  grep some.dat ls.log
  [ `wc -l < ls.log` = 1 ]

  diff -u <(git lfs ls-files --debug) <(cat <<-EOF
filepath: some.dat
    size: 10
checkout: true
download: true
     oid: sha256 5aa03f96c77536579166fba147929626cc3a97960e994057a9d80271a736d10f
 version: https://git-lfs.github.com/spec/v1

EOF)
)
end_test

begin_test "ls-files: files in subdirectory"
(
  set -e

  reponame="ls-files-subdir"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  git add .gitattributes
  git commit -m "initial commit"

  mkdir subdir
  missing="missing"
  missing_oid="$(calc_oid "$missing")"
  printf "%s" "$missing" > subdir/missing.dat
  git add subdir
  git commit -m "add file in subdirectory"

  contents="some data"
  oid="$(calc_oid "$contents")"
  printf "%s" "$contents" > subdir/some.dat

  echo "some text" > subdir/some.txt

  [ "${missing_oid:0:10} * subdir/missing.dat" = "$(git lfs ls-files)" ]

  git rm subdir/missing.dat
  git add subdir
  git commit -m "add and remove files in subdirectory"

  expected="${oid:0:10} * subdir/some.dat"

  [ "$expected" = "$(git lfs ls-files)" ]

  diff -u <(git lfs ls-files --debug) <(cat <<-EOF
filepath: subdir/some.dat
    size: 9
checkout: true
download: true
     oid: sha256 $oid
 version: https://git-lfs.github.com/spec/v1

EOF)
)
end_test

begin_test "ls-files: run within subdirectory"
(
  set -e

  reponame="ls-files-in-subdir"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  git add .gitattributes
  git commit -m "initial commit"

  mkdir subdir
  contents1="a"
  oid1="$(calc_oid "$contents1")"
  printf "%s" "$contents1" > a.dat
  contents2="b"
  oid2="$(calc_oid "$contents2")"
  printf "%s" "$contents2" > subdir/b.dat

  cd subdir

  [ "" = "$(git lfs ls-files)" ]

  git add ../a.dat b.dat

  expected="${oid1:0:10} * a.dat
${oid2:0:10} * subdir/b.dat"

  [ "$expected" = "$(git lfs ls-files)" ]

  diff -u <(git lfs ls-files --debug) <(cat <<-EOF
filepath: a.dat
    size: 1
checkout: true
download: true
     oid: sha256 $oid1
 version: https://git-lfs.github.com/spec/v1

filepath: subdir/b.dat
    size: 1
checkout: true
download: true
     oid: sha256 $oid2
 version: https://git-lfs.github.com/spec/v1

EOF)
)
end_test

begin_test "ls-files: checkout and download status"
(
  set -e

  reponame="ls-files-status"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  git add .gitattributes
  git commit -m "initial commit"

  contents1="a"
  oid1="$(calc_oid "$contents1")"
  printf "%s" "$contents1" > a.dat
  contents2="b"
  oid2="$(calc_oid "$contents2")"
  printf "%s" "$contents2" > b.dat

  [ "" = "$(git lfs ls-files)" ]

  # Note that if we don't remove b.dat from the working tree as well as the
  # Git LFS object cache, Git calls (as invoked by Git LFS) may restore the
  # cache copy from the working tree copy by re-invoking Git LFS in
  # "clean" filter mode.
  git add a.dat b.dat
  rm a.dat b.dat
  rm ".git/lfs/objects/${oid2:0:2}/${oid2:2:2}/$oid2"

  expected="${oid1:0:10} - a.dat
${oid2:0:10} - b.dat"

  [ "$expected" = "$(git lfs ls-files)" ]

  diff -u <(git lfs ls-files --debug) <(cat <<-EOF
filepath: a.dat
    size: 1
checkout: false
download: true
     oid: sha256 $oid1
 version: https://git-lfs.github.com/spec/v1

filepath: b.dat
    size: 1
checkout: false
download: false
     oid: sha256 $oid2
 version: https://git-lfs.github.com/spec/v1

EOF)
)
end_test

begin_test "ls-files: checkout and download status (run within subdirectory)"
(
  set -e

  reponame="ls-files-status-in-subdir"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  git add .gitattributes
  git commit -m "initial commit"

  contents1="a"
  oid1="$(calc_oid "$contents1")"
  printf "%s" "$contents1" > a.dat
  contents2="b"
  oid2="$(calc_oid "$contents2")"
  printf "%s" "$contents2" > b.dat

  mkdir subdir
  cd subdir

  contents3="c"
  oid3="$(calc_oid "$contents3")"
  printf "%s" "$contents3" > c.dat
  contents4="d"
  oid4="$(calc_oid "$contents4")"
  printf "%s" "$contents4" > d.dat

  [ "" = "$(git lfs ls-files)" ]

  # Note that if we don't remove b.dat and d.dat from the working tree as
  # well as the Git LFS object cache, Git calls (as invoked by Git LFS) may
  # restore the cache copies from the working tree copies by re-invoking
  # Git LFS in "clean" filter mode.
  git add ../a.dat ../b.dat c.dat d.dat
  rm ../a.dat ../b.dat c.dat d.dat
  rm "../.git/lfs/objects/${oid2:0:2}/${oid2:2:2}/$oid2"
  rm "../.git/lfs/objects/${oid4:0:2}/${oid4:2:2}/$oid4"

  expected="${oid1:0:10} - a.dat
${oid2:0:10} - b.dat
${oid3:0:10} - subdir/c.dat
${oid4:0:10} - subdir/d.dat"

  [ "$expected" = "$(git lfs ls-files)" ]

  diff -u <(git lfs ls-files --debug) <(cat <<-EOF
filepath: a.dat
    size: 1
checkout: false
download: true
     oid: sha256 $oid1
 version: https://git-lfs.github.com/spec/v1

filepath: b.dat
    size: 1
checkout: false
download: false
     oid: sha256 $oid2
 version: https://git-lfs.github.com/spec/v1

filepath: subdir/c.dat
    size: 1
checkout: false
download: true
     oid: sha256 $oid3
 version: https://git-lfs.github.com/spec/v1

filepath: subdir/d.dat
    size: 1
checkout: false
download: false
     oid: sha256 $oid4
 version: https://git-lfs.github.com/spec/v1

EOF)
)
end_test

begin_test "ls-files: --size"
(
  set -e

  reponame="ls-files-size"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  git add .gitattributes
  git commit -m "initial commit"

  contents="contents"
  size="$(printf "%s" "$contents" | wc -c | awk '{ print $1 }')"
  printf "%s" "$contents" > a.dat

  git add a.dat
  git commit -m "add a.dat"

  git lfs ls-files --size 2>&1 | tee ls.log
  [ "d1b2a59fbe * a.dat (8 B)" = "$(cat ls.log)" ]
)
end_test

begin_test "ls-files: indexed files without tree"
(
  set -e

  reponame="ls-files-indexed-files-without-tree"
  git init "$reponame"
  cd "$reponame"

  git lfs track '*.dat'
  git add .gitattributes

  contents="a"
  oid="$(calc_oid "$contents")"
  printf "%s" "$contents" > a.dat

  [ "" = "$(git lfs ls-files)" ]

  git add a.dat

  [ "${oid:0:10} * a.dat" = "$(git lfs ls-files)" ]
)
end_test

begin_test "ls-files: indexed file with tree"
(
  set -e

  reponame="ls-files-indexed-files-with-tree"
  git init "$reponame"
  cd "$reponame"

  git lfs track '*.dat'
  git add .gitattributes
  git commit -m "initial commit"

  tree_contents="a"
  tree_oid="$(calc_oid "$tree_contents")"

  printf "%s" "$tree_contents" > a.dat
  git add a.dat
  git commit -m "add a.dat"

  index_contents="b"
  index_oid="$(calc_oid "$index_contents")"

  printf "%s" "$index_contents" > a.dat
  git add a.dat

  [ "${index_oid:0:10} * a.dat" = "$(git lfs ls-files)" ]
)
end_test

begin_test "ls-files: historical reference ignores index"
(
  set -e

  reponame="ls-files-historical-reference-ignores-index"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.txt"
  echo "a.txt" > a.txt
  echo "b.txt" > b.txt
  echo "c.txt" > c.txt

  git add .gitattributes a.txt
  git commit -m "a.txt: initial commit"

  git add b.txt
  git commit -m "b.txt: initial commit"

  git add c.txt

  git lfs ls-files "$(git rev-parse HEAD~1)" 2>&1 | tee ls-files.log

  [ 1 -eq "$(grep -c "a.txt" ls-files.log)" ]
  [ 0 -eq "$(grep -c "b.txt" ls-files.log)" ]
  [ 0 -eq "$(grep -c "c.txt" ls-files.log)" ]
)
end_test

begin_test "ls-files: non-HEAD reference referring to HEAD ignores index"
(
  set -e

  reponame="ls-files-HEAD-ish-ignores-index"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.txt"
  echo "a.txt" > a.txt
  echo "b.txt" > b.txt

  git add .gitattributes a.txt
  git commit -m "a.txt: initial commit"

  tagname="v1.0.0"
  git tag "$tagname"

  git add b.txt

  git lfs ls-files "$tagname" 2>&1 | tee ls-files.log

  [ 1 -eq "$(grep -c "a.txt" ls-files.log)" ]
  [ 0 -eq "$(grep -c "b.txt" ls-files.log)" ]
)
end_test

begin_test "ls-files: outside git repository"
(
  set +e
  git lfs ls-files 2>&1 > ls-files.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" ls-files.log
)
end_test

begin_test "ls-files: --include"
(
  set -e

  git init ls-files-include
  cd ls-files-include

  git lfs track "*.dat" "*.bin"
  echo "a" > a.dat
  echo "b" > b.dat
  echo "c" > c.bin

  git add *.gitattributes a.dat b.dat c.bin
  git commit -m "initial commit"

  git lfs ls-files --include="*.dat" 2>&1 | tee ls-files.log

  [ "0" -eq "$(grep -c "\.bin" ls-files.log)" ]
  [ "2" -eq "$(grep -c "\.dat" ls-files.log)" ]
)
end_test

begin_test "ls-files: --exclude"
(
  set -e

  git init ls-files-exclude
  cd ls-files-exclude

  mkdir dir

  git lfs track "*.dat"
  echo "a" > a.dat
  echo "b" > b.dat
  echo "c" > dir/c.dat

  git add *.gitattributes a.dat b.dat dir/c.dat
  git commit -m "initial commit"

  git lfs ls-files --exclude="dir/" 2>&1 | tee ls-files.log

  [ "0" -eq "$(grep -c "dir" ls-files.log)" ]
  [ "2" -eq "$(grep -c "\.dat" ls-files.log)" ]
)
end_test

begin_test "ls-files: before first commit"
(
  set -e

  reponame="ls-files-before-first-commit"
  git init "$reponame"
  cd "$reponame"

  if [ 0 -ne $(git lfs ls-files | wc -l) ]; then
    echo >&2 "Expected \`git lfs ls-files\` to produce no output"
    exit 1
  fi
)
end_test

begin_test "ls-files: show duplicate files"
(
  set -e

  mkdir dupRepoShort
  cd dupRepoShort
  git init

  git lfs track "*.tgz" | grep "Tracking \"\*.tgz\""
  echo "test content" > one.tgz
  echo "test content" > two.tgz
  git add one.tgz
  git add two.tgz
  git commit -m "add duplicate files"

  expected="$(echo "a1fff0ffef * one.tgz
a1fff0ffef * two.tgz")"

  [ "$expected" = "$(git lfs ls-files)" ]
)
end_test

begin_test "ls-files: show duplicate files with long OID"
(
  set -e

  mkdir dupRepoLong
  cd dupRepoLong
  git init

  git lfs track "*.tgz" | grep "Tracking \"\*.tgz\""
  echo "test content" > one.tgz
  echo "test content" > two.tgz
  git add one.tgz
  git add two.tgz
  git commit -m "add duplicate files with long OID"

  expected="$(echo "a1fff0ffefb9eace7230c24e50731f0a91c62f9cefdfe77121c2f607125dffae * one.tgz
a1fff0ffefb9eace7230c24e50731f0a91c62f9cefdfe77121c2f607125dffae * two.tgz")"

  [ "$expected" = "$(git lfs ls-files --long)" ]
)
end_test

begin_test "ls-files: history with --all"
(
  set -e

  reponame="ls-files-history-with-all"
  git init "$reponame"
  cd "$reponame"

  git lfs track '*.dat'
  printf "a" > a.dat
  printf "b" > b.dat

  git add .gitattributes a.dat b.dat
  git commit -m "initial commit"

  rm b.dat
  git add b.dat
  git commit -m "remove b.dat"

  git lfs ls-files 2>&1 | tee ls-files.log
  [ 1 -eq $(grep -c "a\.dat" ls-files.log) ]
  [ 0 -eq $(grep -c "b\.dat" ls-files.log) ]

  git lfs ls-files --all 2>&1 | tee ls-files-all.log
  [ 1 -eq $(grep -c "a\.dat" ls-files-all.log) ]
  [ 1 -eq $(grep -c "b\.dat" ls-files-all.log) ]
)
end_test

begin_test "ls-files: --all with argument(s)"
(
  set -e

  reponame="ls-files-all-with-arguments"
  git init "$reponame"
  cd "$reponame"

  git lfs ls-files --all main 2>&1 | tee ls-files.log

  if [ "0" -eq "${PIPESTATUS[0]}" ]; then
    echo >&2 "fatal: \`git lfs ls-files --all main\` to fail"
    exit 1
  fi

  [ "Cannot use --all with explicit reference" = "$(cat ls-files.log)" ]
)
end_test

begin_test "ls-files: reference with --deleted"
(
  set -e

  reponame="ls-files-reference-with-deleted"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  printf "a" > a.dat
  git add .gitattributes a.dat
  git commit -m "initial commit"

  rm a.dat
  git add a.dat
  git commit -m "a.dat: remove a.dat"

  git lfs ls-files 2>&1 | tee ls-files.log
  git lfs ls-files --deleted 2>&1 | tee ls-files-deleted.log

  [ 0 -eq $(grep -c "a\.dat" ls-files.log) ]
  [ 1 -eq $(grep -c "a\.dat" ls-files-deleted.log) ]
)
end_test

begin_test "ls-files: invalid --all ordering"
(
  set -e

  reponame="ls-files-invalid---all-ordering"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  echo "Hello world" > a.dat

  git add .gitattributes a.dat
  git commit -m "initial commit"

  git lfs ls-files -- --all 2>&1 | tee ls-files.out
  if [ ${PIPESTATUS[0]} = "0" ]; then
    echo >&2 "Expected \`git lfs ls-files -- --all\' to fail"
    exit 1
  fi
  grep "Did you mean \`git lfs ls-files --all --\` ?" ls-files.out
)
end_test

begin_test "ls-files: list/stat files with escaped runes in path before commit"
(
  set -e

  reponame=runes-in-path
  content="zero"
  checksum="d3eb539a55"
  pathWithGermanRunes="german/äöü"
  fileWithGermanRunes="schüüch.bin"

  mkdir $reponame
  git init "$reponame"
  cd $reponame
  git lfs track "**/*"

  echo "$content" > regular
  echo "$content" > "$fileWithGermanRunes"

  mkdir -p "$pathWithGermanRunes"
  echo "$content" > "$pathWithGermanRunes/regular"
  echo "$content" > "$pathWithGermanRunes/$fileWithGermanRunes"

  git add *

  # check short form
  [ 4 -eq "$(git lfs ls-files | grep -c '*')" ]

  # also check long format
  [ 4 -eq "$(git lfs ls-files -l | grep -c '*')" ]

)
end_test

begin_test "ls-files: --name-only"
(
  set -e

  reponame="ls-files-name"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  git add .gitattributes
  git commit -m "initial commit"

  contents="test contents"
  echo "$contents" > a.dat

  git add a.dat
  git commit -m "add a.dat"

  git lfs ls-files --name-only 2>&1 | tee ls.log
  [ "a.dat" = "$(cat ls.log)" ]
)
end_test

begin_test "ls-files: history with reference range"
(
  set -e

  reponame="ls-files-history-with-range"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  git add .gitattributes
  git commit -m 'intial commit'

  echo "content of a-file" > a.dat
  git add a.dat
  git commit -m 'add a.dat'

  echo "content of b-file" > b.dat
  git add b.dat
  git commit -m 'add b.dat'

  git tag b-commit

  echo "content of c-file" > c.dat
  git add c.dat
  git commit -m 'add c.dat'

  echo "content of c-file and later modified" > c.dat
  git add c.dat
  git commit -m 'modify c.dat'

  git tag c-commit

  git rm a.dat
  git commit -m 'remove a.dat'

  git lfs ls-files --all 2>&1 | tee ls-files.log
  [ 1 -eq $(grep -c "a\.dat" ls-files.log) ]
  [ 1 -eq $(grep -c "b\.dat" ls-files.log) ]
  [ 2 -eq $(grep -c "c\.dat" ls-files.log) ]

  git lfs ls-files b-commit c-commit 2>&1 | tee ls-files.log
  [ 0 -eq $(grep -c "a\.dat" ls-files.log) ]
  [ 0 -eq $(grep -c "b\.dat" ls-files.log) ]
  [ 2 -eq $(grep -c "c\.dat" ls-files.log) ]

  git lfs ls-files c-commit~ c-commit 2>&1 | tee ls-files.log
  [ 0 -eq $(grep -c "a\.dat" ls-files.log) ]
  [ 0 -eq $(grep -c "b\.dat" ls-files.log) ]
  [ 1 -eq $(grep -c "c\.dat" ls-files.log) ]

  git lfs ls-files HEAD~ HEAD 2>&1 | tee ls-files.log
  [ 0 -eq $(grep -c "a\.dat" ls-files.log) ]
  [ 0 -eq $(grep -c "b\.dat" ls-files.log) ]
  [ 0 -eq $(grep -c "c\.dat" ls-files.log) ]
)
end_test

begin_test "ls-files: not affected by lfs.fetchexclude"
(
  set -e

  mkdir repo-fetchexclude
  cd repo-fetchexclude
  git init
  git lfs track "*.dat" | grep "Tracking \"\*.dat\""
  echo "some data" > some.dat
  echo "some text" > some.txt
  echo "missing" > missing.dat
  git add missing.dat
  git commit -m "add missing file"
  git config lfs.fetchexclude '*'
  [ "6bbd052ab0 * missing.dat" = "$(git lfs ls-files)" ]
)
end_test

begin_test "ls-files --json"
(
  set -e

  reponame="ls-files-json"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat" | grep "Tracking \"\*.dat\""
  echo "some data" > some.dat
  echo "some text" > some.txt
  echo "missing" > missing.dat
  git add missing.dat
  git commit -m "add missing file"

  git lfs ls-files --json > actual
  cat > expected <<-EOF
{
 "files": [
  {
   "name": "missing.dat",
   "size": 8,
   "checkout": true,
   "downloaded": true,
   "oid_type": "sha256",
   "oid": "6bbd052ab054ef222c1c87be60cd191addedd24cc882d1f5f7f7be61dc61bb3a",
   "version": "https://git-lfs.github.com/spec/v1"
  }
 ]
}
EOF
  diff -u actual expected

  git rm missing.dat
  git add some.dat some.txt
  git commit -m "added some files, removed missing one"

  git lfs ls-files --json > actual
  cat > expected <<-EOF
{
 "files": [
  {
   "name": "some.dat",
   "size": 10,
   "checkout": true,
   "downloaded": true,
   "oid_type": "sha256",
   "oid": "5aa03f96c77536579166fba147929626cc3a97960e994057a9d80271a736d10f",
   "version": "https://git-lfs.github.com/spec/v1"
  }
 ]
}
EOF
  diff -u actual expected
)
end_test

begin_test "ls-files: files in subdirectory (--json)"
(
  set -e

  reponame="ls-files-subdir-json"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  git add .gitattributes
  git commit -m "initial commit"

  mkdir subdir
  missing="missing"
  missing_oid="$(calc_oid "$missing")"
  printf "%s" "$missing" > subdir/missing.dat
  git add subdir
  git commit -m "add file in subdirectory"

  contents="some data"
  oid="$(calc_oid "$contents")"
  printf "%s" "$contents" > subdir/some.dat

  echo "some text" > subdir/some.txt

  git rm subdir/missing.dat
  git add subdir
  git commit -m "add and remove files in subdirectory"

  diff -u <(git lfs ls-files --json) <(cat <<-EOF
{
 "files": [
  {
   "name": "subdir/some.dat",
   "size": 9,
   "checkout": true,
   "downloaded": true,
   "oid_type": "sha256",
   "oid": "$oid",
   "version": "https://git-lfs.github.com/spec/v1"
  }
 ]
}
EOF)
)
end_test

begin_test "ls-files: run within subdirectory (--json)"
(
  set -e

  reponame="ls-files-in-subdir-json"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  git add .gitattributes
  git commit -m "initial commit"

  mkdir subdir
  contents1="a"
  oid1="$(calc_oid "$contents1")"
  printf "%s" "$contents1" > a.dat
  contents2="b"
  oid2="$(calc_oid "$contents2")"
  printf "%s" "$contents2" > subdir/b.dat

  cd subdir

  git add ../a.dat b.dat

  diff -u <(git lfs ls-files --json) <(cat <<-EOF
{
 "files": [
  {
   "name": "a.dat",
   "size": 1,
   "checkout": true,
   "downloaded": true,
   "oid_type": "sha256",
   "oid": "$oid1",
   "version": "https://git-lfs.github.com/spec/v1"
  },
  {
   "name": "subdir/b.dat",
   "size": 1,
   "checkout": true,
   "downloaded": true,
   "oid_type": "sha256",
   "oid": "$oid2",
   "version": "https://git-lfs.github.com/spec/v1"
  }
 ]
}
EOF)
)
end_test

begin_test "ls-files: checkout and download status (--json)"
(
  set -e

  reponame="ls-files-status-json"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  git add .gitattributes
  git commit -m "initial commit"

  contents1="a"
  oid1="$(calc_oid "$contents1")"
  printf "%s" "$contents1" > a.dat
  contents2="b"
  oid2="$(calc_oid "$contents2")"
  printf "%s" "$contents2" > b.dat

  # Note that if we don't remove b.dat from the working tree as well as the
  # Git LFS object cache, Git calls (as invoked by Git LFS) may restore the
  # cache copy from the working tree copy by re-invoking Git LFS in
  # "clean" filter mode.
  git add a.dat b.dat
  rm a.dat b.dat
  rm ".git/lfs/objects/${oid2:0:2}/${oid2:2:2}/$oid2"

  diff -u <(git lfs ls-files --json) <(cat <<-EOF
{
 "files": [
  {
   "name": "a.dat",
   "size": 1,
   "checkout": false,
   "downloaded": true,
   "oid_type": "sha256",
   "oid": "$oid1",
   "version": "https://git-lfs.github.com/spec/v1"
  },
  {
   "name": "b.dat",
   "size": 1,
   "checkout": false,
   "downloaded": false,
   "oid_type": "sha256",
   "oid": "$oid2",
   "version": "https://git-lfs.github.com/spec/v1"
  }
 ]
}
EOF)
)
end_test

begin_test "ls-files: checkout and download status (run within subdirectory) (--json)"
(
  set -e

  reponame="ls-files-status-in-subdir-json"
  git init "$reponame"
  cd "$reponame"

  git lfs track "*.dat"
  git add .gitattributes
  git commit -m "initial commit"

  contents1="a"
  oid1="$(calc_oid "$contents1")"
  printf "%s" "$contents1" > a.dat
  contents2="b"
  oid2="$(calc_oid "$contents2")"
  printf "%s" "$contents2" > b.dat

  mkdir subdir
  cd subdir

  contents3="c"
  oid3="$(calc_oid "$contents3")"
  printf "%s" "$contents3" > c.dat
  contents4="d"
  oid4="$(calc_oid "$contents4")"
  printf "%s" "$contents4" > d.dat

  # Note that if we don't remove b.dat and d.dat from the working tree as
  # well as the Git LFS object cache, Git calls (as invoked by Git LFS) may
  # restore the cache copies from the working tree copies by re-invoking
  # Git LFS in "clean" filter mode.
  git add ../a.dat ../b.dat c.dat d.dat
  rm ../a.dat ../b.dat c.dat d.dat
  rm "../.git/lfs/objects/${oid2:0:2}/${oid2:2:2}/$oid2"
  rm "../.git/lfs/objects/${oid4:0:2}/${oid4:2:2}/$oid4"

  diff -u <(git lfs ls-files --json) <(cat <<-EOF
{
 "files": [
  {
   "name": "a.dat",
   "size": 1,
   "checkout": false,
   "downloaded": true,
   "oid_type": "sha256",
   "oid": "$oid1",
   "version": "https://git-lfs.github.com/spec/v1"
  },
  {
   "name": "b.dat",
   "size": 1,
   "checkout": false,
   "downloaded": false,
   "oid_type": "sha256",
   "oid": "$oid2",
   "version": "https://git-lfs.github.com/spec/v1"
  },
  {
   "name": "subdir/c.dat",
   "size": 1,
   "checkout": false,
   "downloaded": true,
   "oid_type": "sha256",
   "oid": "$oid3",
   "version": "https://git-lfs.github.com/spec/v1"
  },
  {
   "name": "subdir/d.dat",
   "size": 1,
   "checkout": false,
   "downloaded": false,
   "oid_type": "sha256",
   "oid": "$oid4",
   "version": "https://git-lfs.github.com/spec/v1"
  }
 ]
}
EOF)
)
end_test