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
|
#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
contents="a"
contents_oid=$(calc_oid "$contents")
b="b"
b_oid=$(calc_oid "$b")
reponame="$(basename "$0" ".sh")"
begin_test "init for fetch tests"
(
set -e
setup_remote_repo "$reponame"
clone_repo "$reponame" repo
git lfs track "*.dat" 2>&1 | tee track.log
grep "Tracking \"\*.dat\"" track.log
printf "%s" "$contents" > a.dat
git add a.dat
git add .gitattributes
git commit -m "add a.dat" 2>&1 | tee commit.log
grep "main (root-commit)" commit.log
grep "2 files changed" commit.log
grep "create mode 100644 a.dat" commit.log
grep "create mode 100644 .gitattributes" commit.log
[ "a" = "$(cat a.dat)" ]
assert_local_object "$contents_oid" 1
refute_server_object "$reponame" "$contents_oid"
git push origin main 2>&1 | tee push.log
grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
grep "main -> main" push.log
assert_server_object "$reponame" "$contents_oid"
# Add a file in a different branch
git checkout -b newbranch
printf "%s" "$b" > b.dat
git add b.dat
git commit -m "add b.dat"
assert_local_object "$b_oid" 1
git push origin newbranch
assert_server_object "$reponame" "$b_oid"
# These clones are used for subsequent tests
clone_repo "$reponame" clone
git clone --shared "$TRASHDIR/clone" "$TRASHDIR/shared"
)
end_test
begin_test "fetch"
(
set -e
cd clone
rm -rf .git/lfs/objects
git lfs fetch
assert_local_object "$contents_oid" 1
git lfs fsck 2>&1 | tee fsck.log
grep "Git LFS fsck OK" fsck.log
)
end_test
begin_test "fetch (empty file)"
(
set -e
cd clone
rm -rf .git/lfs/objects
touch empty.dat
git add empty.dat
git commit -m 'empty'
git lfs fetch
git lfs fsck 2>&1 | tee fsck.log
grep "Git LFS fsck OK" fsck.log
)
end_test
begin_test "fetch (shared repository)"
(
set -e
cd shared
rm -rf .git/lfs/objects
git lfs fetch 2>&1 | tee fetch.log
grep "Could not scan" fetch.log && exit 1
assert_local_object "$contents_oid" 1
git lfs fsck 2>&1 | tee fsck.log
grep "Git LFS fsck OK" fsck.log
)
end_test
begin_test "fetch with remote"
(
set -e
cd clone
rm -rf .git/lfs/objects
git lfs fetch origin
assert_local_object "$contents_oid" 1
refute_local_object "$b_oid" 1
git lfs fsck 2>&1 | tee fsck.log
grep "Git LFS fsck OK" fsck.log
)
end_test
begin_test "fetch with remote and branches"
(
set -e
cd clone
git checkout newbranch
git checkout main
rm -rf .git/lfs/objects
git lfs fetch origin main newbranch
assert_local_object "$contents_oid" 1
assert_local_object "$b_oid" 1
git lfs fsck 2>&1 | tee fsck.log
grep "Git LFS fsck OK" fsck.log
)
end_test
begin_test "fetch with main commit sha1"
(
set -e
cd clone
rm -rf .git/lfs/objects
main_sha1=$(git rev-parse main)
git lfs fetch origin "$main_sha1"
assert_local_object "$contents_oid" 1
refute_local_object "$b_oid" 1
git lfs fsck 2>&1 | tee fsck.log
grep "Git LFS fsck OK" fsck.log
)
end_test
begin_test "fetch with newbranch commit sha1"
(
set -e
cd clone
rm -rf .git/lfs/objects
newbranch_sha1=$(git rev-parse newbranch)
git lfs fetch origin "$newbranch_sha1"
assert_local_object "$contents_oid" 1
assert_local_object "$b_oid" 1
git lfs fsck 2>&1 | tee fsck.log
grep "Git LFS fsck OK" fsck.log
)
end_test
begin_test "fetch with include filters in gitconfig"
(
set -e
cd clone
rm -rf .git/lfs/objects
git config "lfs.fetchinclude" "a*"
git lfs fetch origin main newbranch
assert_local_object "$contents_oid" 1
refute_local_object "$b_oid"
git lfs fsck 2>&1 | tee fsck.log
grep "Git LFS fsck OK" fsck.log
)
end_test
begin_test "fetch with exclude filters in gitconfig"
(
set -e
cd clone
git config --unset "lfs.fetchinclude"
rm -rf .git/lfs/objects
git config "lfs.fetchexclude" "a*"
git lfs fetch origin main newbranch
refute_local_object "$contents_oid"
assert_local_object "$b_oid" 1
git lfs fsck 2>&1 | tee fsck.log
grep "Git LFS fsck OK" fsck.log
)
end_test
begin_test "fetch with include/exclude filters in gitconfig"
(
set -e
cd clone
rm -rf .git/lfs/objects
git config --unset "lfs.fetchexclude"
git config "lfs.fetchinclude" "a*,b*"
git config "lfs.fetchexclude" "c*,d*"
git lfs fetch origin main newbranch
assert_local_object "$contents_oid" 1
assert_local_object "$b_oid" 1
rm -rf .git/lfs/objects
git config "lfs.fetchinclude" "c*,d*"
git config "lfs.fetchexclude" "a*,b*"
git lfs fetch origin main newbranch
refute_local_object "$contents_oid"
refute_local_object "$b_oid"
)
end_test
begin_test "fetch with include filter in cli"
(
set -e
cd clone
git config --unset "lfs.fetchinclude"
git config --unset "lfs.fetchexclude"
rm -rf .git/lfs/objects
git lfs fetch --include="a*" origin main newbranch
assert_local_object "$contents_oid" 1
refute_local_object "$b_oid"
)
end_test
begin_test "fetch with exclude filter in cli"
(
set -e
cd clone
rm -rf .git/lfs/objects
git lfs fetch --exclude="a*" origin main newbranch
refute_local_object "$contents_oid"
assert_local_object "$b_oid" 1
)
end_test
begin_test "fetch with include/exclude filters in cli"
(
set -e
cd clone
rm -rf .git/lfs/objects
git lfs fetch -I "a*,b*" -X "c*,d*" origin main newbranch
assert_local_object "$contents_oid" 1
assert_local_object "$b_oid" 1
rm -rf .git/lfs/objects
git lfs fetch --include="c*,d*" --exclude="a*,b*" origin main newbranch
refute_local_object "$contents_oid"
refute_local_object "$b_oid"
)
end_test
begin_test "fetch with include filter overriding exclude filter"
(
set -e
cd clone
rm -rf .git/lfs/objects
git config lfs.fetchexclude "b*"
git lfs fetch -I "b.dat" -X "" origin main newbranch
assert_local_object "$b_oid" "1"
)
end_test
begin_test "fetch with missing object"
(
set -e
cd clone
git config --unset lfs.fetchexclude
rm -rf .git/lfs/objects
delete_server_object "$reponame" "$b_oid"
refute_server_object "$reponame" "$b_oid"
# should return non-zero, but should also download all the other valid files too
set +e
git lfs fetch origin main newbranch
fetch_exit=$?
set -e
[ "$fetch_exit" != "0" ]
assert_local_object "$contents_oid" 1
refute_local_object "$b_oid"
)
end_test
begin_test "fetch does not crash on empty key files"
(
set -e
cd clone
rm -rf .git/lfs/objects
git config --local http.sslKey /dev/null
git config --local http.sslCert /dev/null
git lfs fetch origin main 2>&1 | tee fetch.log
grep "Error decoding PEM block" fetch.log
)
end_test
begin_test "fetch-all"
(
set -e
reponame="fetch-all"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat" 2>&1 | tee track.log
grep "Tracking \"\*.dat\"" track.log
NUMFILES=12
# generate content we'll use
for ((a=0; a < NUMFILES ; a++))
do
content[$a]="filecontent$a"
oid[$a]=$(calc_oid "${content[$a]}")
done
echo "[
{
\"CommitDate\":\"$(get_date -180d)\",
\"Files\":[
{\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
{\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
},
{
\"NewBranch\":\"branch1\",
\"CommitDate\":\"$(get_date -140d)\",
\"Files\":[
{\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
},
{
\"ParentBranches\":[\"main\"],
\"CommitDate\":\"$(get_date -100d)\",
\"Files\":[
{\"Filename\":\"file1.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
},
{
\"NewBranch\":\"remote_branch_only\",
\"CommitDate\":\"$(get_date -80d)\",
\"Files\":[
{\"Filename\":\"file2.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}]
},
{
\"ParentBranches\":[\"main\"],
\"CommitDate\":\"$(get_date -75d)\",
\"Files\":[
{\"Filename\":\"file4.dat\",\"Size\":${#content[5]}, \"Data\":\"${content[5]}\"}]
},
{
\"NewBranch\":\"tag_only\",
\"Tags\":[\"tag1\"],
\"CommitDate\":\"$(get_date -70d)\",
\"Files\":[
{\"Filename\":\"file4.dat\",\"Size\":${#content[6]}, \"Data\":\"${content[6]}\"}]
},
{
\"ParentBranches\":[\"main\"],
\"CommitDate\":\"$(get_date -60d)\",
\"Files\":[
{\"Filename\":\"file1.dat\",\"Size\":${#content[7]}, \"Data\":\"${content[7]}\"}]
},
{
\"NewBranch\":\"branch3\",
\"CommitDate\":\"$(get_date -50d)\",
\"Files\":[
{\"Filename\":\"file4.dat\",\"Size\":${#content[8]}, \"Data\":\"${content[8]}\"}]
},
{
\"CommitDate\":\"$(get_date -40d)\",
\"ParentBranches\":[\"main\"],
\"Files\":[
{\"Filename\":\"file1.dat\",\"Size\":${#content[9]}, \"Data\":\"${content[9]}\"},
{\"Filename\":\"file2.dat\",\"Size\":${#content[10]}, \"Data\":\"${content[10]}\"}]
},
{
\"ParentBranches\":[\"main\"],
\"CommitDate\":\"$(get_date -30d)\",
\"Files\":[
{\"Filename\":\"file4.dat\",\"Size\":${#content[11]}, \"Data\":\"${content[11]}\"}]
}
]" | lfstest-testutils addcommits
git push origin main
git push origin branch1
git push origin branch3
git push origin remote_branch_only
git push origin tag_only
git push origin tag1
for ((a=0; a < NUMFILES ; a++))
do
assert_server_object "$reponame" "${oid[$a]}"
done
# delete remote_branch_only and make sure that objects are downloaded even
# though not checked out to a local branch (full backup always)
git branch -D remote_branch_only
# delete tag_only to make sure objects are downloaded when only reachable from tag
git branch -D tag_only
rm -rf .git/lfs/objects
git lfs fetch --all origin
for ((a=0; a < NUMFILES ; a++))
do
assert_local_object "${oid[$a]}" "${#content[$a]}"
done
rm -rf .git/lfs/objects
# fetch all objects reachable from the main branch only
git lfs fetch --all origin main
for a in 0 1 3 5 7 9 10 11
do
assert_local_object "${oid[$a]}" "${#content[$a]}"
done
for a in 2 4 6 8
do
refute_local_object "${oid[$a]}"
done
rm -rf .git/lfs/objects
# fetch all objects reachable from branch1 and tag1 only
git lfs fetch --all origin branch1 tag1
for a in 0 1 2 3 5 6
do
assert_local_object "${oid[$a]}" "${#content[$a]}"
done
for a in 4 7 8 9 10 11
do
refute_local_object "${oid[$a]}"
done
# Make a bare clone of the repository
cd ..
git clone --bare "$GITSERVER/$reponame" "$reponame-bare"
cd "$reponame-bare"
# Perform the same assertion as above, on the same data
git lfs fetch --all origin
for ((a=0; a < NUMFILES ; a++))
do
assert_local_object "${oid[$a]}" "${#content[$a]}"
done
rm -rf lfs/objects
# fetch all objects reachable from the main branch only
git lfs fetch --all origin main
for a in 0 1 3 5 7 9 10 11
do
assert_local_object "${oid[$a]}" "${#content[$a]}"
done
for a in 2 4 6 8
do
refute_local_object "${oid[$a]}"
done
rm -rf lfs/objects
# fetch all objects reachable from branch1 and tag1 only
git lfs fetch --all origin branch1 tag1
for a in 0 1 2 3 5 6
do
assert_local_object "${oid[$a]}" "${#content[$a]}"
done
for a in 4 7 8 9 10 11
do
refute_local_object "${oid[$a]}"
done
)
end_test
begin_test "fetch: outside git repository"
(
set +e
git lfs fetch 2>&1 > fetch.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" fetch.log
)
end_test
begin_test "fetch with no origin remote"
(
set -e
reponame="fetch-no-remote"
setup_remote_repo "$reponame"
clone_repo "$reponame" no-remote-clone
clone_repo "$reponame" no-remote-repo
git lfs track "*.dat" 2>&1 | tee track.log
grep "Tracking \"\*.dat\"" track.log
contents="a"
contents_oid=$(calc_oid "$contents")
printf "%s" "$contents" > a.dat
git add a.dat
git add .gitattributes
git commit -m "add a.dat" 2>&1 | tee commit.log
grep "main (root-commit)" commit.log
grep "2 files changed" commit.log
grep "create mode 100644 a.dat" commit.log
grep "create mode 100644 .gitattributes" commit.log
[ "a" = "$(cat a.dat)" ]
assert_local_object "$contents_oid" 1
refute_server_object "$reponame" "$contents_oid"
git push origin main 2>&1 | tee push.log
grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
grep "main -> main" push.log
# change to the clone's working directory
cd ../no-remote-clone
# pull commits & lfs
git pull origin main 2>&1
assert_local_object "$contents_oid" 1
# now checkout detached HEAD so we're not tracking anything on remote
git checkout --detach
# delete lfs
rm -rf .git/lfs
# rename remote from 'origin' to 'something'
git remote rename origin something
# fetch should still pick this remote as in the case of no tracked remote,
# and no origin, but only 1 remote, should pick the only one as default
git lfs fetch
assert_local_object "$contents_oid" 1
)
end_test
begin_test "fetch --prune"
(
set -e
reponame="fetch_prune"
setup_remote_repo "remote_$reponame"
clone_repo "remote_$reponame" "clone_$reponame"
git lfs track "*.dat" 2>&1 | tee track.log
grep "Tracking \"\*.dat\"" track.log
content_head="HEAD content"
content_commit2="Content for commit 2 (prune)"
content_commit1="Content for commit 1 (prune)"
oid_head=$(calc_oid "$content_head")
oid_commit2=$(calc_oid "$content_commit2")
oid_commit1=$(calc_oid "$content_commit1")
echo "[
{
\"CommitDate\":\"$(get_date -50d)\",
\"Files\":[
{\"Filename\":\"file.dat\",\"Size\":${#content_commit1}, \"Data\":\"$content_commit1\"}]
},
{
\"CommitDate\":\"$(get_date -35d)\",
\"Files\":[
{\"Filename\":\"file.dat\",\"Size\":${#content_commit2}, \"Data\":\"$content_commit2\"}]
},
{
\"CommitDate\":\"$(get_date -25d)\",
\"Files\":[
{\"Filename\":\"file.dat\",\"Size\":${#content_head}, \"Data\":\"$content_head\"}]
}
]" | lfstest-testutils addcommits
# push all so no unpushed reason to not prune
git push origin main
# set no recents so max ability to prune
git config lfs.fetchrecentrefsdays 0
git config lfs.fetchrecentcommitsdays 0
# delete HEAD object to prove that we still download something
# also prune at the same time which will remove anything other than HEAD
delete_local_object "$oid_head"
git lfs fetch --prune
assert_local_object "$oid_head" "${#content_head}"
refute_local_object "$oid_commit1"
refute_local_object "$oid_commit2"
)
end_test
begin_test "fetch raw remote url"
(
set -e
mkdir raw
cd raw
git init
git lfs install --local --skip-smudge
git remote add origin "$GITSERVER/$reponame"
git pull origin main
# LFS object not downloaded, pointer in working directory
refute_local_object "$contents_oid"
grep "$content_oid" a.dat
git lfs fetch "$GITSERVER/$reponame"
# LFS object downloaded, pointer still in working directory
assert_local_object "$contents_oid" 1
grep "$content_oid" a.dat
)
end_test
begin_test "fetch with invalid ref"
(
set -e
cd repo
git lfs fetch origin jibberish >fetch.log 2>&1 && exit 1
grep "Invalid ref argument" fetch.log
)
end_test
begin_test "fetch with invalid remote"
(
set -e
cd repo
git lfs fetch not-a-remote 2>&1 | tee fetch.log
grep "Invalid remote name" fetch.log
)
end_test
begin_test "fetch fails when LFS directory has wrong permissions"
(
set -e
# Windows lacks POSIX permissions.
[ "$IS_WINDOWS" -eq 1 ] && exit 0
# Root is exempt from permissions.
[ "$(id -u)" -eq 0 ] && exit 0
cd shared
rm -rf .git/lfs/objects
mkdir .git/lfs/objects
chmod 400 .git/lfs/objects
git lfs fetch 2>&1 | tee fetch.log
grep "error trying to create local storage directory" fetch.log
)
end_test
|