| 1 |
|
| 2 |
|
| 3 |
. "$(dirname "$0")/testlib.sh" |
| 4 |
|
| 5 |
begin_test "ls-files" |
| 6 |
( |
| 7 |
set -e |
| 8 |
|
| 9 |
mkdir repo |
| 10 |
cd repo |
| 11 |
git init |
| 12 |
git lfs track "*.dat" | grep "Tracking \"\*.dat\"" |
| 13 |
echo "some data" > some.dat |
| 14 |
echo "some text" > some.txt |
| 15 |
echo "missing" > missing.dat |
| 16 |
git add missing.dat |
| 17 |
git commit -m "add missing file" |
| 18 |
[ "6bbd052ab0 * missing.dat" = "$(git lfs ls-files)" ] |
| 19 |
|
| 20 |
git rm missing.dat |
| 21 |
git add some.dat some.txt |
| 22 |
git commit -m "added some files, removed missing one" |
| 23 |
|
| 24 |
git lfs ls-files | tee ls.log |
| 25 |
grep some.dat ls.log |
| 26 |
[ `wc -l < ls.log` = 1 ] |
| 27 |
|
| 28 |
diff -u <(git lfs ls-files --debug) <(cat <<-EOF |
| 29 |
filepath: some.dat |
| 30 |
size: 10 |
| 31 |
checkout: true |
| 32 |
download: true |
| 33 |
oid: sha256 5aa03f96c77536579166fba147929626cc3a97960e994057a9d80271a736d10f |
| 34 |
version: https://git-lfs.github.com/spec/v1 |
| 35 |
|
| 36 |
EOF) |
| 37 |
) |
| 38 |
end_test |
| 39 |
|
| 40 |
begin_test "ls-files: files in subdirectory" |
| 41 |
( |
| 42 |
set -e |
| 43 |
|
| 44 |
reponame="ls-files-subdir" |
| 45 |
git init "$reponame" |
| 46 |
cd "$reponame" |
| 47 |
|
| 48 |
git lfs track "*.dat" |
| 49 |
git add .gitattributes |
| 50 |
git commit -m "initial commit" |
| 51 |
|
| 52 |
mkdir subdir |
| 53 |
missing="missing" |
| 54 |
missing_oid="$(calc_oid "$missing")" |
| 55 |
printf "%s" "$missing" > subdir/missing.dat |
| 56 |
git add subdir |
| 57 |
git commit -m "add file in subdirectory" |
| 58 |
|
| 59 |
contents="some data" |
| 60 |
oid="$(calc_oid "$contents")" |
| 61 |
printf "%s" "$contents" > subdir/some.dat |
| 62 |
|
| 63 |
echo "some text" > subdir/some.txt |
| 64 |
|
| 65 |
[ "${missing_oid:0:10} * subdir/missing.dat" = "$(git lfs ls-files)" ] |
| 66 |
|
| 67 |
git rm subdir/missing.dat |
| 68 |
git add subdir |
| 69 |
git commit -m "add and remove files in subdirectory" |
| 70 |
|
| 71 |
expected="${oid:0:10} * subdir/some.dat" |
| 72 |
|
| 73 |
[ "$expected" = "$(git lfs ls-files)" ] |
| 74 |
|
| 75 |
diff -u <(git lfs ls-files --debug) <(cat <<-EOF |
| 76 |
filepath: subdir/some.dat |
| 77 |
size: 9 |
| 78 |
checkout: true |
| 79 |
download: true |
| 80 |
oid: sha256 $oid |
| 81 |
version: https://git-lfs.github.com/spec/v1 |
| 82 |
|
| 83 |
EOF) |
| 84 |
) |
| 85 |
end_test |
| 86 |
|
| 87 |
begin_test "ls-files: run within subdirectory" |
| 88 |
( |
| 89 |
set -e |
| 90 |
|
| 91 |
reponame="ls-files-in-subdir" |
| 92 |
git init "$reponame" |
| 93 |
cd "$reponame" |
| 94 |
|
| 95 |
git lfs track "*.dat" |
| 96 |
git add .gitattributes |
| 97 |
git commit -m "initial commit" |
| 98 |
|
| 99 |
mkdir subdir |
| 100 |
contents1="a" |
| 101 |
oid1="$(calc_oid "$contents1")" |
| 102 |
printf "%s" "$contents1" > a.dat |
| 103 |
contents2="b" |
| 104 |
oid2="$(calc_oid "$contents2")" |
| 105 |
printf "%s" "$contents2" > subdir/b.dat |
| 106 |
|
| 107 |
cd subdir |
| 108 |
|
| 109 |
[ "" = "$(git lfs ls-files)" ] |
| 110 |
|
| 111 |
git add ../a.dat b.dat |
| 112 |
|
| 113 |
expected="${oid1:0:10} * a.dat |
| 114 |
${oid2:0:10} * subdir/b.dat" |
| 115 |
|
| 116 |
[ "$expected" = "$(git lfs ls-files)" ] |
| 117 |
|
| 118 |
diff -u <(git lfs ls-files --debug) <(cat <<-EOF |
| 119 |
filepath: a.dat |
| 120 |
size: 1 |
| 121 |
checkout: true |
| 122 |
download: true |
| 123 |
oid: sha256 $oid1 |
| 124 |
version: https://git-lfs.github.com/spec/v1 |
| 125 |
|
| 126 |
filepath: subdir/b.dat |
| 127 |
size: 1 |
| 128 |
checkout: true |
| 129 |
download: true |
| 130 |
oid: sha256 $oid2 |
| 131 |
version: https://git-lfs.github.com/spec/v1 |
| 132 |
|
| 133 |
EOF) |
| 134 |
) |
| 135 |
end_test |
| 136 |
|
| 137 |
begin_test "ls-files: checkout and download status" |
| 138 |
( |
| 139 |
set -e |
| 140 |
|
| 141 |
reponame="ls-files-status" |
| 142 |
git init "$reponame" |
| 143 |
cd "$reponame" |
| 144 |
|
| 145 |
git lfs track "*.dat" |
| 146 |
git add .gitattributes |
| 147 |
git commit -m "initial commit" |
| 148 |
|
| 149 |
contents1="a" |
| 150 |
oid1="$(calc_oid "$contents1")" |
| 151 |
printf "%s" "$contents1" > a.dat |
| 152 |
contents2="b" |
| 153 |
oid2="$(calc_oid "$contents2")" |
| 154 |
printf "%s" "$contents2" > b.dat |
| 155 |
|
| 156 |
[ "" = "$(git lfs ls-files)" ] |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
git add a.dat b.dat |
| 163 |
rm a.dat b.dat |
| 164 |
rm ".git/lfs/objects/${oid2:0:2}/${oid2:2:2}/$oid2" |
| 165 |
|
| 166 |
expected="${oid1:0:10} - a.dat |
| 167 |
${oid2:0:10} - b.dat" |
| 168 |
|
| 169 |
[ "$expected" = "$(git lfs ls-files)" ] |
| 170 |
|
| 171 |
diff -u <(git lfs ls-files --debug) <(cat <<-EOF |
| 172 |
filepath: a.dat |
| 173 |
size: 1 |
| 174 |
checkout: false |
| 175 |
download: true |
| 176 |
oid: sha256 $oid1 |
| 177 |
version: https://git-lfs.github.com/spec/v1 |
| 178 |
|
| 179 |
filepath: b.dat |
| 180 |
size: 1 |
| 181 |
checkout: false |
| 182 |
download: false |
| 183 |
oid: sha256 $oid2 |
| 184 |
version: https://git-lfs.github.com/spec/v1 |
| 185 |
|
| 186 |
EOF) |
| 187 |
) |
| 188 |
end_test |
| 189 |
|
| 190 |
begin_test "ls-files: checkout and download status (run within subdirectory)" |
| 191 |
( |
| 192 |
set -e |
| 193 |
|
| 194 |
reponame="ls-files-status-in-subdir" |
| 195 |
git init "$reponame" |
| 196 |
cd "$reponame" |
| 197 |
|
| 198 |
git lfs track "*.dat" |
| 199 |
git add .gitattributes |
| 200 |
git commit -m "initial commit" |
| 201 |
|
| 202 |
contents1="a" |
| 203 |
oid1="$(calc_oid "$contents1")" |
| 204 |
printf "%s" "$contents1" > a.dat |
| 205 |
contents2="b" |
| 206 |
oid2="$(calc_oid "$contents2")" |
| 207 |
printf "%s" "$contents2" > b.dat |
| 208 |
|
| 209 |
mkdir subdir |
| 210 |
cd subdir |
| 211 |
|
| 212 |
contents3="c" |
| 213 |
oid3="$(calc_oid "$contents3")" |
| 214 |
printf "%s" "$contents3" > c.dat |
| 215 |
contents4="d" |
| 216 |
oid4="$(calc_oid "$contents4")" |
| 217 |
printf "%s" "$contents4" > d.dat |
| 218 |
|
| 219 |
[ "" = "$(git lfs ls-files)" ] |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
git add ../a.dat ../b.dat c.dat d.dat |
| 226 |
rm ../a.dat ../b.dat c.dat d.dat |
| 227 |
rm "../.git/lfs/objects/${oid2:0:2}/${oid2:2:2}/$oid2" |
| 228 |
rm "../.git/lfs/objects/${oid4:0:2}/${oid4:2:2}/$oid4" |
| 229 |
|
| 230 |
expected="${oid1:0:10} - a.dat |
| 231 |
${oid2:0:10} - b.dat |
| 232 |
${oid3:0:10} - subdir/c.dat |
| 233 |
${oid4:0:10} - subdir/d.dat" |
| 234 |
|
| 235 |
[ "$expected" = "$(git lfs ls-files)" ] |
| 236 |
|
| 237 |
diff -u <(git lfs ls-files --debug) <(cat <<-EOF |
| 238 |
filepath: a.dat |
| 239 |
size: 1 |
| 240 |
checkout: false |
| 241 |
download: true |
| 242 |
oid: sha256 $oid1 |
| 243 |
version: https://git-lfs.github.com/spec/v1 |
| 244 |
|
| 245 |
filepath: b.dat |
| 246 |
size: 1 |
| 247 |
checkout: false |
| 248 |
download: false |
| 249 |
oid: sha256 $oid2 |
| 250 |
version: https://git-lfs.github.com/spec/v1 |
| 251 |
|
| 252 |
filepath: subdir/c.dat |
| 253 |
size: 1 |
| 254 |
checkout: false |
| 255 |
download: true |
| 256 |
oid: sha256 $oid3 |
| 257 |
version: https://git-lfs.github.com/spec/v1 |
| 258 |
|
| 259 |
filepath: subdir/d.dat |
| 260 |
size: 1 |
| 261 |
checkout: false |
| 262 |
download: false |
| 263 |
oid: sha256 $oid4 |
| 264 |
version: https://git-lfs.github.com/spec/v1 |
| 265 |
|
| 266 |
EOF) |
| 267 |
) |
| 268 |
end_test |
| 269 |
|
| 270 |
begin_test "ls-files: --size" |
| 271 |
( |
| 272 |
set -e |
| 273 |
|
| 274 |
reponame="ls-files-size" |
| 275 |
git init "$reponame" |
| 276 |
cd "$reponame" |
| 277 |
|
| 278 |
git lfs track "*.dat" |
| 279 |
git add .gitattributes |
| 280 |
git commit -m "initial commit" |
| 281 |
|
| 282 |
contents="contents" |
| 283 |
size="$(printf "%s" "$contents" | wc -c | awk '{ print $1 }')" |
| 284 |
printf "%s" "$contents" > a.dat |
| 285 |
|
| 286 |
git add a.dat |
| 287 |
git commit -m "add a.dat" |
| 288 |
|
| 289 |
git lfs ls-files --size 2>&1 | tee ls.log |
| 290 |
[ "d1b2a59fbe * a.dat (8 B)" = "$(cat ls.log)" ] |
| 291 |
) |
| 292 |
end_test |
| 293 |
|
| 294 |
begin_test "ls-files: correctly reflects case sensitivity" |
| 295 |
( |
| 296 |
set -e |
| 297 |
|
| 298 |
reponame="ls-files-case-sensitive" |
| 299 |
git init "$reponame" |
| 300 |
cd "$reponame" |
| 301 |
ignorecase="$(git config core.ignorecase || true)" |
| 302 |
ignorecase="${ignorecase:-false}" |
| 303 |
|
| 304 |
git lfs track '*.DAT' |
| 305 |
git add .gitattributes |
| 306 |
|
| 307 |
contents="a" |
| 308 |
oid="$(calc_oid "$contents")" |
| 309 |
printf "%s" "$contents" > a.dat |
| 310 |
|
| 311 |
[ "" = "$(git lfs ls-files)" ] |
| 312 |
|
| 313 |
git add a.dat |
| 314 |
|
| 315 |
if [ "$ignorecase" = true ] |
| 316 |
then |
| 317 |
[ "${oid:0:10} * a.dat" = "$(git lfs ls-files)" ] |
| 318 |
else |
| 319 |
[ "" = "$(git lfs ls-files)" ] |
| 320 |
fi |
| 321 |
) |
| 322 |
end_test |
| 323 |
|
| 324 |
begin_test "ls-files: indexed files without tree" |
| 325 |
( |
| 326 |
set -e |
| 327 |
|
| 328 |
reponame="ls-files-indexed-files-without-tree" |
| 329 |
git init "$reponame" |
| 330 |
cd "$reponame" |
| 331 |
|
| 332 |
git lfs track '*.dat' |
| 333 |
git add .gitattributes |
| 334 |
|
| 335 |
contents="a" |
| 336 |
oid="$(calc_oid "$contents")" |
| 337 |
printf "%s" "$contents" > a.dat |
| 338 |
|
| 339 |
[ "" = "$(git lfs ls-files)" ] |
| 340 |
|
| 341 |
git add a.dat |
| 342 |
|
| 343 |
[ "${oid:0:10} * a.dat" = "$(git lfs ls-files)" ] |
| 344 |
) |
| 345 |
end_test |
| 346 |
|
| 347 |
begin_test "ls-files: indexed file with tree" |
| 348 |
( |
| 349 |
set -e |
| 350 |
|
| 351 |
reponame="ls-files-indexed-files-with-tree" |
| 352 |
git init "$reponame" |
| 353 |
cd "$reponame" |
| 354 |
|
| 355 |
git lfs track '*.dat' |
| 356 |
git add .gitattributes |
| 357 |
git commit -m "initial commit" |
| 358 |
|
| 359 |
tree_contents="a" |
| 360 |
tree_oid="$(calc_oid "$tree_contents")" |
| 361 |
|
| 362 |
printf "%s" "$tree_contents" > a.dat |
| 363 |
git add a.dat |
| 364 |
git commit -m "add a.dat" |
| 365 |
|
| 366 |
index_contents="b" |
| 367 |
index_oid="$(calc_oid "$index_contents")" |
| 368 |
|
| 369 |
printf "%s" "$index_contents" > a.dat |
| 370 |
git add a.dat |
| 371 |
|
| 372 |
[ "${index_oid:0:10} * a.dat" = "$(git lfs ls-files)" ] |
| 373 |
) |
| 374 |
end_test |
| 375 |
|
| 376 |
begin_test "ls-files: historical reference ignores index" |
| 377 |
( |
| 378 |
set -e |
| 379 |
|
| 380 |
reponame="ls-files-historical-reference-ignores-index" |
| 381 |
git init "$reponame" |
| 382 |
cd "$reponame" |
| 383 |
|
| 384 |
git lfs track "*.txt" |
| 385 |
echo "a.txt" > a.txt |
| 386 |
echo "b.txt" > b.txt |
| 387 |
echo "c.txt" > c.txt |
| 388 |
|
| 389 |
git add .gitattributes a.txt |
| 390 |
git commit -m "a.txt: initial commit" |
| 391 |
|
| 392 |
git add b.txt |
| 393 |
git commit -m "b.txt: initial commit" |
| 394 |
|
| 395 |
git add c.txt |
| 396 |
|
| 397 |
git lfs ls-files "$(git rev-parse HEAD~1)" 2>&1 | tee ls-files.log |
| 398 |
|
| 399 |
[ 1 -eq "$(grep -c "a.txt" ls-files.log)" ] |
| 400 |
[ 0 -eq "$(grep -c "b.txt" ls-files.log)" ] |
| 401 |
[ 0 -eq "$(grep -c "c.txt" ls-files.log)" ] |
| 402 |
) |
| 403 |
end_test |
| 404 |
|
| 405 |
begin_test "ls-files: non-HEAD reference referring to HEAD ignores index" |
| 406 |
( |
| 407 |
set -e |
| 408 |
|
| 409 |
reponame="ls-files-HEAD-ish-ignores-index" |
| 410 |
git init "$reponame" |
| 411 |
cd "$reponame" |
| 412 |
|
| 413 |
git lfs track "*.txt" |
| 414 |
echo "a.txt" > a.txt |
| 415 |
echo "b.txt" > b.txt |
| 416 |
|
| 417 |
git add .gitattributes a.txt |
| 418 |
git commit -m "a.txt: initial commit" |
| 419 |
|
| 420 |
tagname="v1.0.0" |
| 421 |
git tag "$tagname" |
| 422 |
|
| 423 |
git add b.txt |
| 424 |
|
| 425 |
git lfs ls-files "$tagname" 2>&1 | tee ls-files.log |
| 426 |
|
| 427 |
[ 1 -eq "$(grep -c "a.txt" ls-files.log)" ] |
| 428 |
[ 0 -eq "$(grep -c "b.txt" ls-files.log)" ] |
| 429 |
) |
| 430 |
end_test |
| 431 |
|
| 432 |
begin_test "ls-files: outside git repository" |
| 433 |
( |
| 434 |
set +e |
| 435 |
git lfs ls-files 2>&1 > ls-files.log |
| 436 |
res=$? |
| 437 |
|
| 438 |
set -e |
| 439 |
if [ "$res" = "0" ]; then |
| 440 |
echo "Passes because $GIT_LFS_TEST_DIR is unset." |
| 441 |
exit 0 |
| 442 |
fi |
| 443 |
[ "$res" = "128" ] |
| 444 |
grep "Not in a Git repository" ls-files.log |
| 445 |
) |
| 446 |
end_test |
| 447 |
|
| 448 |
begin_test "ls-files: --include" |
| 449 |
( |
| 450 |
set -e |
| 451 |
|
| 452 |
git init ls-files-include |
| 453 |
cd ls-files-include |
| 454 |
|
| 455 |
git lfs track "*.dat" "*.bin" |
| 456 |
echo "a" > a.dat |
| 457 |
echo "b" > b.dat |
| 458 |
echo "c" > c.bin |
| 459 |
|
| 460 |
git add *.gitattributes a.dat b.dat c.bin |
| 461 |
git commit -m "initial commit" |
| 462 |
|
| 463 |
git lfs ls-files --include="*.dat" 2>&1 | tee ls-files.log |
| 464 |
|
| 465 |
[ "0" -eq "$(grep -c "\.bin" ls-files.log)" ] |
| 466 |
[ "2" -eq "$(grep -c "\.dat" ls-files.log)" ] |
| 467 |
) |
| 468 |
end_test |
| 469 |
|
| 470 |
begin_test "ls-files: --exclude" |
| 471 |
( |
| 472 |
set -e |
| 473 |
|
| 474 |
git init ls-files-exclude |
| 475 |
cd ls-files-exclude |
| 476 |
|
| 477 |
mkdir dir |
| 478 |
|
| 479 |
git lfs track "*.dat" |
| 480 |
echo "a" > a.dat |
| 481 |
echo "b" > b.dat |
| 482 |
echo "c" > dir/c.dat |
| 483 |
|
| 484 |
git add *.gitattributes a.dat b.dat dir/c.dat |
| 485 |
git commit -m "initial commit" |
| 486 |
|
| 487 |
git lfs ls-files --exclude="dir/" 2>&1 | tee ls-files.log |
| 488 |
|
| 489 |
[ "0" -eq "$(grep -c "dir" ls-files.log)" ] |
| 490 |
[ "2" -eq "$(grep -c "\.dat" ls-files.log)" ] |
| 491 |
) |
| 492 |
end_test |
| 493 |
|
| 494 |
begin_test "ls-files: --include/--exclude with path cache settings" |
| 495 |
( |
| 496 |
set -e |
| 497 |
|
| 498 |
git init ls-files-include-exclude |
| 499 |
cd ls-files-include-exclude |
| 500 |
|
| 501 |
mkdir -p dir |
| 502 |
|
| 503 |
git lfs track "*.dat" |
| 504 |
echo "a" > a.dat |
| 505 |
echo "b" > dir/b.dat |
| 506 |
echo "c" > dir/c.dat |
| 507 |
echo "d" > dir/d.dat |
| 508 |
|
| 509 |
git add *.gitattributes a.dat dir |
| 510 |
git commit -m "initial commit" |
| 511 |
|
| 512 |
git lfs ls-files --include="dir/" --exclude="c.dat" 2>&1 | tee ls-files.log |
| 513 |
|
| 514 |
[ 1 -eq $(grep -c "dir/b.dat" "ls-files.log") ] |
| 515 |
[ 1 -eq $(grep -c "dir/d.dat" "ls-files.log") ] |
| 516 |
[ 2 -eq $(cat "ls-files.log" | wc -l) ] |
| 517 |
|
| 518 |
|
| 519 |
for cache in "none" "0" "1" "unlimited" "" "-1" "invalid"; do |
| 520 |
git config "lfs.pathFilterCacheSize" "$cache" |
| 521 |
|
| 522 |
git lfs ls-files --include="dir/" --exclude="c.dat" 2>&1 | tee ls-files.log |
| 523 |
|
| 524 |
[ 1 -eq $(grep -c "dir/b.dat" "ls-files.log") ] |
| 525 |
[ 1 -eq $(grep -c "dir/d.dat" "ls-files.log") ] |
| 526 |
[ 2 -eq $(cat "ls-files.log" | wc -l) ] |
| 527 |
done |
| 528 |
) |
| 529 |
end_test |
| 530 |
|
| 531 |
begin_test "ls-files: before first commit" |
| 532 |
( |
| 533 |
set -e |
| 534 |
|
| 535 |
reponame="ls-files-before-first-commit" |
| 536 |
git init "$reponame" |
| 537 |
cd "$reponame" |
| 538 |
|
| 539 |
if [ 0 -ne $(git lfs ls-files | wc -l) ]; then |
| 540 |
echo >&2 "Expected \`git lfs ls-files\` to produce no output" |
| 541 |
exit 1 |
| 542 |
fi |
| 543 |
) |
| 544 |
end_test |
| 545 |
|
| 546 |
begin_test "ls-files: show duplicate files" |
| 547 |
( |
| 548 |
set -e |
| 549 |
|
| 550 |
mkdir dupRepoShort |
| 551 |
cd dupRepoShort |
| 552 |
git init |
| 553 |
|
| 554 |
git lfs track "*.tgz" | grep "Tracking \"\*.tgz\"" |
| 555 |
echo "test content" > one.tgz |
| 556 |
echo "test content" > two.tgz |
| 557 |
git add one.tgz |
| 558 |
git add two.tgz |
| 559 |
git commit -m "add duplicate files" |
| 560 |
|
| 561 |
expected="$(echo "a1fff0ffef * one.tgz |
| 562 |
a1fff0ffef * two.tgz")" |
| 563 |
|
| 564 |
[ "$expected" = "$(git lfs ls-files)" ] |
| 565 |
) |
| 566 |
end_test |
| 567 |
|
| 568 |
begin_test "ls-files: show duplicate files with long OID" |
| 569 |
( |
| 570 |
set -e |
| 571 |
|
| 572 |
mkdir dupRepoLong |
| 573 |
cd dupRepoLong |
| 574 |
git init |
| 575 |
|
| 576 |
git lfs track "*.tgz" | grep "Tracking \"\*.tgz\"" |
| 577 |
echo "test content" > one.tgz |
| 578 |
echo "test content" > two.tgz |
| 579 |
git add one.tgz |
| 580 |
git add two.tgz |
| 581 |
git commit -m "add duplicate files with long OID" |
| 582 |
|
| 583 |
expected="$(echo "a1fff0ffefb9eace7230c24e50731f0a91c62f9cefdfe77121c2f607125dffae * one.tgz |
| 584 |
a1fff0ffefb9eace7230c24e50731f0a91c62f9cefdfe77121c2f607125dffae * two.tgz")" |
| 585 |
|
| 586 |
[ "$expected" = "$(git lfs ls-files --long)" ] |
| 587 |
) |
| 588 |
end_test |
| 589 |
|
| 590 |
begin_test "ls-files: history with --all" |
| 591 |
( |
| 592 |
set -e |
| 593 |
|
| 594 |
reponame="ls-files-history-with-all" |
| 595 |
git init "$reponame" |
| 596 |
cd "$reponame" |
| 597 |
|
| 598 |
git lfs track '*.dat' |
| 599 |
printf "a" > a.dat |
| 600 |
printf "b" > b.dat |
| 601 |
|
| 602 |
git add .gitattributes a.dat b.dat |
| 603 |
git commit -m "initial commit" |
| 604 |
|
| 605 |
rm b.dat |
| 606 |
git add b.dat |
| 607 |
git commit -m "remove b.dat" |
| 608 |
|
| 609 |
git lfs ls-files 2>&1 | tee ls-files.log |
| 610 |
[ 1 -eq $(grep -c "a\.dat" ls-files.log) ] |
| 611 |
[ 0 -eq $(grep -c "b\.dat" ls-files.log) ] |
| 612 |
|
| 613 |
git lfs ls-files --all 2>&1 | tee ls-files-all.log |
| 614 |
[ 1 -eq $(grep -c "a\.dat" ls-files-all.log) ] |
| 615 |
[ 1 -eq $(grep -c "b\.dat" ls-files-all.log) ] |
| 616 |
) |
| 617 |
end_test |
| 618 |
|
| 619 |
begin_test "ls-files: --all with argument(s)" |
| 620 |
( |
| 621 |
set -e |
| 622 |
|
| 623 |
reponame="ls-files-all-with-arguments" |
| 624 |
git init "$reponame" |
| 625 |
cd "$reponame" |
| 626 |
|
| 627 |
git lfs ls-files --all main 2>&1 | tee ls-files.log |
| 628 |
|
| 629 |
if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 630 |
echo >&2 "fatal: \`git lfs ls-files --all main\` to fail" |
| 631 |
exit 1 |
| 632 |
fi |
| 633 |
|
| 634 |
[ "Cannot use --all with explicit reference" = "$(cat ls-files.log)" ] |
| 635 |
) |
| 636 |
end_test |
| 637 |
|
| 638 |
begin_test "ls-files: reference with --deleted" |
| 639 |
( |
| 640 |
set -e |
| 641 |
|
| 642 |
reponame="ls-files-reference-with-deleted" |
| 643 |
git init "$reponame" |
| 644 |
cd "$reponame" |
| 645 |
|
| 646 |
git lfs track "*.dat" |
| 647 |
printf "a" > a.dat |
| 648 |
git add .gitattributes a.dat |
| 649 |
git commit -m "initial commit" |
| 650 |
|
| 651 |
rm a.dat |
| 652 |
git add a.dat |
| 653 |
git commit -m "a.dat: remove a.dat" |
| 654 |
|
| 655 |
git lfs ls-files 2>&1 | tee ls-files.log |
| 656 |
git lfs ls-files --deleted 2>&1 | tee ls-files-deleted.log |
| 657 |
|
| 658 |
[ 0 -eq $(grep -c "a\.dat" ls-files.log) ] |
| 659 |
[ 1 -eq $(grep -c "a\.dat" ls-files-deleted.log) ] |
| 660 |
) |
| 661 |
end_test |
| 662 |
|
| 663 |
begin_test "ls-files: invalid --all ordering" |
| 664 |
( |
| 665 |
set -e |
| 666 |
|
| 667 |
reponame="ls-files-invalid---all-ordering" |
| 668 |
git init "$reponame" |
| 669 |
cd "$reponame" |
| 670 |
|
| 671 |
git lfs track "*.dat" |
| 672 |
echo "Hello world" > a.dat |
| 673 |
|
| 674 |
git add .gitattributes a.dat |
| 675 |
git commit -m "initial commit" |
| 676 |
|
| 677 |
git lfs ls-files -- --all 2>&1 | tee ls-files.out |
| 678 |
if [ ${PIPESTATUS[0]} = "0" ]; then |
| 679 |
echo >&2 "Expected \`git lfs ls-files -- --all\' to fail" |
| 680 |
exit 1 |
| 681 |
fi |
| 682 |
grep "Did you mean \`git lfs ls-files --all --\` ?" ls-files.out |
| 683 |
) |
| 684 |
end_test |
| 685 |
|
| 686 |
begin_test "ls-files: list/stat files with escaped runes in path before commit" |
| 687 |
( |
| 688 |
set -e |
| 689 |
|
| 690 |
reponame=runes-in-path |
| 691 |
content="zero" |
| 692 |
checksum="d3eb539a55" |
| 693 |
pathWithGermanRunes="german/äöü" |
| 694 |
fileWithGermanRunes="schüüch.bin" |
| 695 |
|
| 696 |
mkdir $reponame |
| 697 |
git init "$reponame" |
| 698 |
cd $reponame |
| 699 |
git lfs track "**/*" |
| 700 |
|
| 701 |
echo "$content" > regular |
| 702 |
echo "$content" > "$fileWithGermanRunes" |
| 703 |
|
| 704 |
mkdir -p "$pathWithGermanRunes" |
| 705 |
echo "$content" > "$pathWithGermanRunes/regular" |
| 706 |
echo "$content" > "$pathWithGermanRunes/$fileWithGermanRunes" |
| 707 |
|
| 708 |
git add * |
| 709 |
|
| 710 |
|
| 711 |
[ 4 -eq "$(git lfs ls-files | grep -c '*')" ] |
| 712 |
|
| 713 |
|
| 714 |
[ 4 -eq "$(git lfs ls-files -l | grep -c '*')" ] |
| 715 |
|
| 716 |
) |
| 717 |
end_test |
| 718 |
|
| 719 |
begin_test "ls-files: --name-only" |
| 720 |
( |
| 721 |
set -e |
| 722 |
|
| 723 |
reponame="ls-files-name" |
| 724 |
git init "$reponame" |
| 725 |
cd "$reponame" |
| 726 |
|
| 727 |
git lfs track "*.dat" |
| 728 |
git add .gitattributes |
| 729 |
git commit -m "initial commit" |
| 730 |
|
| 731 |
contents="test contents" |
| 732 |
echo "$contents" > a.dat |
| 733 |
|
| 734 |
git add a.dat |
| 735 |
git commit -m "add a.dat" |
| 736 |
|
| 737 |
git lfs ls-files --name-only 2>&1 | tee ls.log |
| 738 |
[ "a.dat" = "$(cat ls.log)" ] |
| 739 |
) |
| 740 |
end_test |
| 741 |
|
| 742 |
begin_test "ls-files: history with reference range" |
| 743 |
( |
| 744 |
set -e |
| 745 |
|
| 746 |
reponame="ls-files-history-with-range" |
| 747 |
git init "$reponame" |
| 748 |
cd "$reponame" |
| 749 |
|
| 750 |
git lfs track "*.dat" |
| 751 |
git add .gitattributes |
| 752 |
git commit -m 'intial commit' |
| 753 |
|
| 754 |
echo "content of a-file" > a.dat |
| 755 |
git add a.dat |
| 756 |
git commit -m 'add a.dat' |
| 757 |
|
| 758 |
echo "content of b-file" > b.dat |
| 759 |
git add b.dat |
| 760 |
git commit -m 'add b.dat' |
| 761 |
|
| 762 |
git tag b-commit |
| 763 |
|
| 764 |
echo "content of c-file" > c.dat |
| 765 |
git add c.dat |
| 766 |
git commit -m 'add c.dat' |
| 767 |
|
| 768 |
echo "content of c-file and later modified" > c.dat |
| 769 |
git add c.dat |
| 770 |
git commit -m 'modify c.dat' |
| 771 |
|
| 772 |
git tag c-commit |
| 773 |
|
| 774 |
git rm a.dat |
| 775 |
git commit -m 'remove a.dat' |
| 776 |
|
| 777 |
git lfs ls-files --all 2>&1 | tee ls-files.log |
| 778 |
[ 1 -eq $(grep -c "a\.dat" ls-files.log) ] |
| 779 |
[ 1 -eq $(grep -c "b\.dat" ls-files.log) ] |
| 780 |
[ 2 -eq $(grep -c "c\.dat" ls-files.log) ] |
| 781 |
|
| 782 |
git lfs ls-files b-commit c-commit 2>&1 | tee ls-files.log |
| 783 |
[ 0 -eq $(grep -c "a\.dat" ls-files.log) ] |
| 784 |
[ 0 -eq $(grep -c "b\.dat" ls-files.log) ] |
| 785 |
[ 2 -eq $(grep -c "c\.dat" ls-files.log) ] |
| 786 |
|
| 787 |
git lfs ls-files c-commit~ c-commit 2>&1 | tee ls-files.log |
| 788 |
[ 0 -eq $(grep -c "a\.dat" ls-files.log) ] |
| 789 |
[ 0 -eq $(grep -c "b\.dat" ls-files.log) ] |
| 790 |
[ 1 -eq $(grep -c "c\.dat" ls-files.log) ] |
| 791 |
|
| 792 |
git lfs ls-files HEAD~ HEAD 2>&1 | tee ls-files.log |
| 793 |
[ 0 -eq $(grep -c "a\.dat" ls-files.log) ] |
| 794 |
[ 0 -eq $(grep -c "b\.dat" ls-files.log) ] |
| 795 |
[ 0 -eq $(grep -c "c\.dat" ls-files.log) ] |
| 796 |
) |
| 797 |
end_test |
| 798 |
|
| 799 |
begin_test "ls-files: not affected by lfs.fetchexclude" |
| 800 |
( |
| 801 |
set -e |
| 802 |
|
| 803 |
mkdir repo-fetchexclude |
| 804 |
cd repo-fetchexclude |
| 805 |
git init |
| 806 |
git lfs track "*.dat" | grep "Tracking \"\*.dat\"" |
| 807 |
echo "some data" > some.dat |
| 808 |
echo "some text" > some.txt |
| 809 |
echo "missing" > missing.dat |
| 810 |
git add missing.dat |
| 811 |
git commit -m "add missing file" |
| 812 |
git config lfs.fetchexclude '*' |
| 813 |
[ "6bbd052ab0 * missing.dat" = "$(git lfs ls-files)" ] |
| 814 |
) |
| 815 |
end_test |
| 816 |
|
| 817 |
begin_test "ls-files --json" |
| 818 |
( |
| 819 |
set -e |
| 820 |
|
| 821 |
reponame="ls-files-json" |
| 822 |
git init "$reponame" |
| 823 |
cd "$reponame" |
| 824 |
|
| 825 |
git lfs track "*.dat" | grep "Tracking \"\*.dat\"" |
| 826 |
echo "some data" > some.dat |
| 827 |
echo "some text" > some.txt |
| 828 |
echo "missing" > missing.dat |
| 829 |
git add missing.dat |
| 830 |
git commit -m "add missing file" |
| 831 |
|
| 832 |
git lfs ls-files --json > actual |
| 833 |
cat > expected <<-EOF |
| 834 |
{ |
| 835 |
"files": [ |
| 836 |
{ |
| 837 |
"name": "missing.dat", |
| 838 |
"size": 8, |
| 839 |
"checkout": true, |
| 840 |
"downloaded": true, |
| 841 |
"oid_type": "sha256", |
| 842 |
"oid": "6bbd052ab054ef222c1c87be60cd191addedd24cc882d1f5f7f7be61dc61bb3a", |
| 843 |
"version": "https://git-lfs.github.com/spec/v1" |
| 844 |
} |
| 845 |
] |
| 846 |
} |
| 847 |
EOF |
| 848 |
diff -u actual expected |
| 849 |
|
| 850 |
git rm missing.dat |
| 851 |
git add some.dat some.txt |
| 852 |
git commit -m "added some files, removed missing one" |
| 853 |
|
| 854 |
git lfs ls-files --json > actual |
| 855 |
cat > expected <<-EOF |
| 856 |
{ |
| 857 |
"files": [ |
| 858 |
{ |
| 859 |
"name": "some.dat", |
| 860 |
"size": 10, |
| 861 |
"checkout": true, |
| 862 |
"downloaded": true, |
| 863 |
"oid_type": "sha256", |
| 864 |
"oid": "5aa03f96c77536579166fba147929626cc3a97960e994057a9d80271a736d10f", |
| 865 |
"version": "https://git-lfs.github.com/spec/v1" |
| 866 |
} |
| 867 |
] |
| 868 |
} |
| 869 |
EOF |
| 870 |
diff -u actual expected |
| 871 |
) |
| 872 |
end_test |
| 873 |
|
| 874 |
begin_test "ls-files: files in subdirectory (--json)" |
| 875 |
( |
| 876 |
set -e |
| 877 |
|
| 878 |
reponame="ls-files-subdir-json" |
| 879 |
git init "$reponame" |
| 880 |
cd "$reponame" |
| 881 |
|
| 882 |
git lfs track "*.dat" |
| 883 |
git add .gitattributes |
| 884 |
git commit -m "initial commit" |
| 885 |
|
| 886 |
mkdir subdir |
| 887 |
missing="missing" |
| 888 |
missing_oid="$(calc_oid "$missing")" |
| 889 |
printf "%s" "$missing" > subdir/missing.dat |
| 890 |
git add subdir |
| 891 |
git commit -m "add file in subdirectory" |
| 892 |
|
| 893 |
contents="some data" |
| 894 |
oid="$(calc_oid "$contents")" |
| 895 |
printf "%s" "$contents" > subdir/some.dat |
| 896 |
|
| 897 |
echo "some text" > subdir/some.txt |
| 898 |
|
| 899 |
git rm subdir/missing.dat |
| 900 |
git add subdir |
| 901 |
git commit -m "add and remove files in subdirectory" |
| 902 |
|
| 903 |
diff -u <(git lfs ls-files --json) <(cat <<-EOF |
| 904 |
{ |
| 905 |
"files": [ |
| 906 |
{ |
| 907 |
"name": "subdir/some.dat", |
| 908 |
"size": 9, |
| 909 |
"checkout": true, |
| 910 |
"downloaded": true, |
| 911 |
"oid_type": "sha256", |
| 912 |
"oid": "$oid", |
| 913 |
"version": "https://git-lfs.github.com/spec/v1" |
| 914 |
} |
| 915 |
] |
| 916 |
} |
| 917 |
EOF) |
| 918 |
) |
| 919 |
end_test |
| 920 |
|
| 921 |
begin_test "ls-files: run within subdirectory (--json)" |
| 922 |
( |
| 923 |
set -e |
| 924 |
|
| 925 |
reponame="ls-files-in-subdir-json" |
| 926 |
git init "$reponame" |
| 927 |
cd "$reponame" |
| 928 |
|
| 929 |
git lfs track "*.dat" |
| 930 |
git add .gitattributes |
| 931 |
git commit -m "initial commit" |
| 932 |
|
| 933 |
mkdir subdir |
| 934 |
contents1="a" |
| 935 |
oid1="$(calc_oid "$contents1")" |
| 936 |
printf "%s" "$contents1" > a.dat |
| 937 |
contents2="b" |
| 938 |
oid2="$(calc_oid "$contents2")" |
| 939 |
printf "%s" "$contents2" > subdir/b.dat |
| 940 |
|
| 941 |
cd subdir |
| 942 |
|
| 943 |
git add ../a.dat b.dat |
| 944 |
|
| 945 |
diff -u <(git lfs ls-files --json) <(cat <<-EOF |
| 946 |
{ |
| 947 |
"files": [ |
| 948 |
{ |
| 949 |
"name": "a.dat", |
| 950 |
"size": 1, |
| 951 |
"checkout": true, |
| 952 |
"downloaded": true, |
| 953 |
"oid_type": "sha256", |
| 954 |
"oid": "$oid1", |
| 955 |
"version": "https://git-lfs.github.com/spec/v1" |
| 956 |
}, |
| 957 |
{ |
| 958 |
"name": "subdir/b.dat", |
| 959 |
"size": 1, |
| 960 |
"checkout": true, |
| 961 |
"downloaded": true, |
| 962 |
"oid_type": "sha256", |
| 963 |
"oid": "$oid2", |
| 964 |
"version": "https://git-lfs.github.com/spec/v1" |
| 965 |
} |
| 966 |
] |
| 967 |
} |
| 968 |
EOF) |
| 969 |
) |
| 970 |
end_test |
| 971 |
|
| 972 |
begin_test "ls-files: checkout and download status (--json)" |
| 973 |
( |
| 974 |
set -e |
| 975 |
|
| 976 |
reponame="ls-files-status-json" |
| 977 |
git init "$reponame" |
| 978 |
cd "$reponame" |
| 979 |
|
| 980 |
git lfs track "*.dat" |
| 981 |
git add .gitattributes |
| 982 |
git commit -m "initial commit" |
| 983 |
|
| 984 |
contents1="a" |
| 985 |
oid1="$(calc_oid "$contents1")" |
| 986 |
printf "%s" "$contents1" > a.dat |
| 987 |
contents2="b" |
| 988 |
oid2="$(calc_oid "$contents2")" |
| 989 |
printf "%s" "$contents2" > b.dat |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
git add a.dat b.dat |
| 996 |
rm a.dat b.dat |
| 997 |
rm ".git/lfs/objects/${oid2:0:2}/${oid2:2:2}/$oid2" |
| 998 |
|
| 999 |
diff -u <(git lfs ls-files --json) <(cat <<-EOF |
| 1000 |
{ |
| 1001 |
"files": [ |
| 1002 |
{ |
| 1003 |
"name": "a.dat", |
| 1004 |
"size": 1, |
| 1005 |
"checkout": false, |
| 1006 |
"downloaded": true, |
| 1007 |
"oid_type": "sha256", |
| 1008 |
"oid": "$oid1", |
| 1009 |
"version": "https://git-lfs.github.com/spec/v1" |
| 1010 |
}, |
| 1011 |
{ |
| 1012 |
"name": "b.dat", |
| 1013 |
"size": 1, |
| 1014 |
"checkout": false, |
| 1015 |
"downloaded": false, |
| 1016 |
"oid_type": "sha256", |
| 1017 |
"oid": "$oid2", |
| 1018 |
"version": "https://git-lfs.github.com/spec/v1" |
| 1019 |
} |
| 1020 |
] |
| 1021 |
} |
| 1022 |
EOF) |
| 1023 |
) |
| 1024 |
end_test |
| 1025 |
|
| 1026 |
begin_test "ls-files: checkout and download status (run within subdirectory) (--json)" |
| 1027 |
( |
| 1028 |
set -e |
| 1029 |
|
| 1030 |
reponame="ls-files-status-in-subdir-json" |
| 1031 |
git init "$reponame" |
| 1032 |
cd "$reponame" |
| 1033 |
|
| 1034 |
git lfs track "*.dat" |
| 1035 |
git add .gitattributes |
| 1036 |
git commit -m "initial commit" |
| 1037 |
|
| 1038 |
contents1="a" |
| 1039 |
oid1="$(calc_oid "$contents1")" |
| 1040 |
printf "%s" "$contents1" > a.dat |
| 1041 |
contents2="b" |
| 1042 |
oid2="$(calc_oid "$contents2")" |
| 1043 |
printf "%s" "$contents2" > b.dat |
| 1044 |
|
| 1045 |
mkdir subdir |
| 1046 |
cd subdir |
| 1047 |
|
| 1048 |
contents3="c" |
| 1049 |
oid3="$(calc_oid "$contents3")" |
| 1050 |
printf "%s" "$contents3" > c.dat |
| 1051 |
contents4="d" |
| 1052 |
oid4="$(calc_oid "$contents4")" |
| 1053 |
printf "%s" "$contents4" > d.dat |
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
git add ../a.dat ../b.dat c.dat d.dat |
| 1060 |
rm ../a.dat ../b.dat c.dat d.dat |
| 1061 |
rm "../.git/lfs/objects/${oid2:0:2}/${oid2:2:2}/$oid2" |
| 1062 |
rm "../.git/lfs/objects/${oid4:0:2}/${oid4:2:2}/$oid4" |
| 1063 |
|
| 1064 |
diff -u <(git lfs ls-files --json) <(cat <<-EOF |
| 1065 |
{ |
| 1066 |
"files": [ |
| 1067 |
{ |
| 1068 |
"name": "a.dat", |
| 1069 |
"size": 1, |
| 1070 |
"checkout": false, |
| 1071 |
"downloaded": true, |
| 1072 |
"oid_type": "sha256", |
| 1073 |
"oid": "$oid1", |
| 1074 |
"version": "https://git-lfs.github.com/spec/v1" |
| 1075 |
}, |
| 1076 |
{ |
| 1077 |
"name": "b.dat", |
| 1078 |
"size": 1, |
| 1079 |
"checkout": false, |
| 1080 |
"downloaded": false, |
| 1081 |
"oid_type": "sha256", |
| 1082 |
"oid": "$oid2", |
| 1083 |
"version": "https://git-lfs.github.com/spec/v1" |
| 1084 |
}, |
| 1085 |
{ |
| 1086 |
"name": "subdir/c.dat", |
| 1087 |
"size": 1, |
| 1088 |
"checkout": false, |
| 1089 |
"downloaded": true, |
| 1090 |
"oid_type": "sha256", |
| 1091 |
"oid": "$oid3", |
| 1092 |
"version": "https://git-lfs.github.com/spec/v1" |
| 1093 |
}, |
| 1094 |
{ |
| 1095 |
"name": "subdir/d.dat", |
| 1096 |
"size": 1, |
| 1097 |
"checkout": false, |
| 1098 |
"downloaded": false, |
| 1099 |
"oid_type": "sha256", |
| 1100 |
"oid": "$oid4", |
| 1101 |
"version": "https://git-lfs.github.com/spec/v1" |
| 1102 |
} |
| 1103 |
] |
| 1104 |
} |
| 1105 |
EOF) |
| 1106 |
) |
| 1107 |
end_test |