| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | contents="a" |
| 6 | contents_oid=$(calc_oid "$contents") |
| 7 | b="b" |
| 8 | b_oid=$(calc_oid "$b") |
| 9 | reponame="$(basename "$0" ".sh")" |
| 10 | |
| 11 | begin_test "init for fetch tests" |
| 12 | ( |
| 13 | set -e |
| 14 | |
| 15 | setup_remote_repo "$reponame" |
| 16 | |
| 17 | clone_repo "$reponame" repo |
| 18 | |
| 19 | git lfs track "*.dat" 2>&1 | tee track.log |
| 20 | grep "Tracking \"\*.dat\"" track.log |
| 21 | |
| 22 | |
| 23 | printf "%s" "$contents" > a.dat |
| 24 | git add a.dat |
| 25 | git add .gitattributes |
| 26 | git commit -m "add a.dat" 2>&1 | tee commit.log |
| 27 | grep "main (root-commit)" commit.log |
| 28 | grep "2 files changed" commit.log |
| 29 | grep "create mode 100644 a.dat" commit.log |
| 30 | grep "create mode 100644 .gitattributes" commit.log |
| 31 | |
| 32 | [ "a" = "$(cat a.dat)" ] |
| 33 | |
| 34 | assert_local_object "$contents_oid" 1 |
| 35 | |
| 36 | refute_server_object "$reponame" "$contents_oid" |
| 37 | |
| 38 | git push origin main 2>&1 | tee push.log |
| 39 | grep "Uploading LFS objects: 100% (1/1), 1 B" push.log |
| 40 | grep "main -> main" push.log |
| 41 | |
| 42 | assert_server_object "$reponame" "$contents_oid" |
| 43 | |
| 44 | # Add an empty file |
| 45 | touch empty.dat |
| 46 | git add empty.dat |
| 47 | git commit -m 'empty' |
| 48 | |
| 49 | # Add a file in a different branch |
| 50 | git checkout -b newbranch |
| 51 | printf "%s" "$b" > b.dat |
| 52 | git add b.dat |
| 53 | git commit -m "add b.dat" |
| 54 | assert_local_object "$b_oid" 1 |
| 55 | |
| 56 | git push origin newbranch |
| 57 | assert_server_object "$reponame" "$b_oid" |
| 58 | |
| 59 | # These clones are used for subsequent tests |
| 60 | clone_repo "$reponame" clone |
| 61 | git clone --shared "$TRASHDIR/clone" "$TRASHDIR/shared" |
| 62 | ) |
| 63 | end_test |
| 64 | |
| 65 | begin_test "fetch" |
| 66 | ( |
| 67 | set -e |
| 68 | cd clone |
| 69 | rm -rf .git/lfs/objects |
| 70 | |
| 71 | git lfs fetch --dry-run 2>&1 | tee fetch.log |
| 72 | grep "fetch $contents_oid => a\.dat" fetch.log |
| 73 | refute_local_object "$contents_oid" |
| 74 | |
| 75 | git lfs fetch |
| 76 | assert_local_object "$contents_oid" 1 |
| 77 | |
| 78 | git lfs fsck 2>&1 | tee fsck.log |
| 79 | grep "Git LFS fsck OK" fsck.log |
| 80 | |
| 81 | git lfs fetch --dry-run 2>&1 | tee fetch.log |
| 82 | grep "fetch .* => a\.dat" fetch.log && exit 1 || true |
| 83 | ) |
| 84 | end_test |
| 85 | |
| 86 | begin_test "fetch --json" |
| 87 | ( |
| 88 | set -e |
| 89 | cd clone |
| 90 | rm -rf .git/lfs/objects |
| 91 | |
| 92 | git lfs fetch --dry-run --json | tee fetch-dry-run.json |
| 93 | git lfs fetch --json | tee fetch.json |
| 94 | assert_local_object "$contents_oid" 1 |
| 95 | cat > expected.json <<-EOF |
| 96 | { |
| 97 | "transfers": [ |
| 98 | { |
| 99 | "name": "a.dat", |
| 100 | "oid": "$contents_oid", |
| 101 | "size": 1, |
| 102 | "actions": { |
| 103 | "download": { |
| 104 | "href": "$GITSERVER/storage/$contents_oid?r=$reponame", |
| 105 | "expires_at": "0001-01-01T00:00:00Z" |
| 106 | } |
| 107 | }, |
| 108 | "path": "$(native_path_escaped "$(local_object_path "$contents_oid")")" |
| 109 | } |
| 110 | ] |
| 111 | } |
| 112 | EOF |
| 113 | diff -u expected.json fetch-dry-run.json |
| 114 | diff -u expected.json fetch.json |
| 115 | |
| 116 | git lfs fetch --json | tee fetch.json |
| 117 | cat > expected.json <<-EOF |
| 118 | { |
| 119 | "transfers": [] |
| 120 | } |
| 121 | EOF |
| 122 | diff -u expected.json fetch.json |
| 123 | ) |
| 124 | end_test |
| 125 | |
| 126 | begin_test "fetch --refetch" |
| 127 | ( |
| 128 | set -e |
| 129 | cd clone |
| 130 | rm -rf .git/lfs/objects |
| 131 | |
| 132 | git lfs fetch |
| 133 | assert_local_object "$contents_oid" 1 |
| 134 | |
| 135 | corrupt_local_object "$contents_oid" |
| 136 | refute_local_object "$contents_oid" 1 |
| 137 | |
| 138 | git lfs fetch --refetch |
| 139 | assert_local_object "$contents_oid" 1 |
| 140 | |
| 141 | git lfs fsck 2>&1 | tee fsck.log |
| 142 | grep "Git LFS fsck OK" fsck.log |
| 143 | ) |
| 144 | end_test |
| 145 | |
| 146 | begin_test "fetch (shared repository)" |
| 147 | ( |
| 148 | set -e |
| 149 | cd shared |
| 150 | rm -rf .git/lfs/objects |
| 151 | |
| 152 | git lfs fetch 2>&1 | tee fetch.log |
| 153 | grep "Could not scan" fetch.log && exit 1 |
| 154 | assert_local_object "$contents_oid" 1 |
| 155 | |
| 156 | git lfs fsck 2>&1 | tee fsck.log |
| 157 | grep "Git LFS fsck OK" fsck.log |
| 158 | ) |
| 159 | end_test |
| 160 | |
| 161 | begin_test "fetch with remote" |
| 162 | ( |
| 163 | set -e |
| 164 | cd clone |
| 165 | rm -rf .git/lfs/objects |
| 166 | |
| 167 | git lfs fetch origin |
| 168 | assert_local_object "$contents_oid" 1 |
| 169 | refute_local_object "$b_oid" 1 |
| 170 | |
| 171 | git lfs fsck 2>&1 | tee fsck.log |
| 172 | grep "Git LFS fsck OK" fsck.log |
| 173 | ) |
| 174 | end_test |
| 175 | |
| 176 | begin_test "fetch with remote and branches" |
| 177 | ( |
| 178 | set -e |
| 179 | cd clone |
| 180 | |
| 181 | git checkout newbranch |
| 182 | git checkout main |
| 183 | |
| 184 | rm -rf .git/lfs/objects |
| 185 | |
| 186 | git lfs fetch origin main newbranch --dry-run 2>&1 | tee fetch.log |
| 187 | grep "fetch $contents_oid => a\.dat" fetch.log |
| 188 | grep "fetch $b_oid => b\.dat" fetch.log |
| 189 | refute_local_object "$contents_oid" |
| 190 | refute_local_object "$b_oid" |
| 191 | |
| 192 | git lfs fetch origin main newbranch |
| 193 | assert_local_object "$contents_oid" 1 |
| 194 | assert_local_object "$b_oid" 1 |
| 195 | |
| 196 | git lfs fsck 2>&1 | tee fsck.log |
| 197 | grep "Git LFS fsck OK" fsck.log |
| 198 | |
| 199 | git lfs fetch origin main newbranch --dry-run | tee fetch.log |
| 200 | grep "fetch .* => [ab]\.dat" fetch.log && exit 1 || true |
| 201 | |
| 202 | rm -rf .git/lfs/objects |
| 203 | |
| 204 | printf "main\nnewbranch\n" | git lfs fetch origin --stdin --dry-run 2>&1 | tee fetch.log |
| 205 | grep "fetch $contents_oid => a\.dat" fetch.log |
| 206 | grep "fetch $b_oid => b\.dat" fetch.log |
| 207 | refute_local_object "$contents_oid" |
| 208 | refute_local_object "$b_oid" |
| 209 | |
| 210 | printf "main\nnewbranch\n" | git lfs fetch origin --stdin |
| 211 | assert_local_object "$contents_oid" 1 |
| 212 | assert_local_object "$b_oid" 1 |
| 213 | |
| 214 | git lfs fsck 2>&1 | tee fsck.log |
| 215 | grep "Git LFS fsck OK" fsck.log |
| 216 | |
| 217 | git lfs fetch origin main newbranch --dry-run | tee fetch.log |
| 218 | grep "fetch .* => [ab]\.dat" fetch.log && exit 1 || true |
| 219 | ) |
| 220 | end_test |
| 221 | |
| 222 | begin_test "fetch --json with remote and branches" |
| 223 | ( |
| 224 | set -e |
| 225 | cd clone |
| 226 | |
| 227 | git checkout newbranch |
| 228 | git checkout main |
| 229 | |
| 230 | rm -rf .git/lfs/objects |
| 231 | |
| 232 | git lfs fetch origin main newbranch --json --dry-run | tee fetch-dry-run.json |
| 233 | refute_local_object "$contents_oid" |
| 234 | refute_local_object "$b_oid" |
| 235 | |
| 236 | git lfs fetch origin main newbranch --json | tee fetch.json |
| 237 | assert_local_object "$contents_oid" 1 |
| 238 | assert_local_object "$b_oid" 1 |
| 239 | |
| 240 | # Check the JSON output, without enforcing order between a.dat and b.dat |
| 241 | expected_a='{ |
| 242 | "name": "a.dat", |
| 243 | "oid": "'$contents_oid'", |
| 244 | "size": 1, |
| 245 | "actions": { |
| 246 | "download": { |
| 247 | "href": "'$GITSERVER'/storage/'$contents_oid'?r='$reponame'", |
| 248 | "expires_at": "0001-01-01T00:00:00Z" |
| 249 | } |
| 250 | }, |
| 251 | "path": "'$(native_path_escaped "$(local_object_path "$contents_oid")")'" |
| 252 | }' |
| 253 | expected_b='{ |
| 254 | "name": "b.dat", |
| 255 | "oid": "'$b_oid'", |
| 256 | "size": 1, |
| 257 | "actions": { |
| 258 | "download": { |
| 259 | "href": "'$GITSERVER'/storage/'$b_oid'?r='$reponame'", |
| 260 | "expires_at": "0001-01-01T00:00:00Z" |
| 261 | } |
| 262 | }, |
| 263 | "path": "'$(native_path_escaped "$(local_object_path "$b_oid")")'" |
| 264 | }' |
| 265 | cat > expected-a-b.json <<-EOF |
| 266 | { |
| 267 | "transfers": [ |
| 268 | $expected_a, |
| 269 | $expected_b |
| 270 | ] |
| 271 | } |
| 272 | EOF |
| 273 | cat > expected-b-a.json <<-EOF |
| 274 | { |
| 275 | "transfers": [ |
| 276 | $expected_b, |
| 277 | $expected_a |
| 278 | ] |
| 279 | } |
| 280 | EOF |
| 281 | diff -u expected-a-b.json fetch-dry-run.json || diff -u expected-b-a.json fetch-dry-run.json || exit 1 |
| 282 | diff -u expected-a-b.json fetch.json || diff -u expected-b-a.json fetch-dry-run.json || exit 1 |
| 283 | ) |
| 284 | end_test |
| 285 | |
| 286 | begin_test "fetch --refetch with remote and branches" |
| 287 | ( |
| 288 | set -e |
| 289 | cd clone |
| 290 | |
| 291 | git checkout newbranch |
| 292 | git checkout main |
| 293 | |
| 294 | rm -rf .git/lfs/objects |
| 295 | |
| 296 | git lfs fetch origin main newbranch |
| 297 | assert_local_object "$contents_oid" 1 |
| 298 | assert_local_object "$b_oid" 1 |
| 299 | |
| 300 | corrupt_local_object "$contents_oid" |
| 301 | corrupt_local_object "$b_oid" |
| 302 | refute_local_object "$contents_oid" 1 |
| 303 | refute_local_object "$b_oid" 1 |
| 304 | |
| 305 | git lfs fetch --refetch --json origin main newbranch | tee fetch.json |
| 306 | assert_local_object "$contents_oid" 1 |
| 307 | assert_local_object "$b_oid" 1 |
| 308 | |
| 309 | # check that we did not fetch a.dat twice |
| 310 | [ 1 -eq $(grep -c '"name": "a.dat"' fetch.json) ] |
| 311 | git lfs fsck 2>&1 | tee fsck.log |
| 312 | grep "Git LFS fsck OK" fsck.log |
| 313 | ) |
| 314 | end_test |
| 315 | |
| 316 | begin_test "fetch with main commit sha1" |
| 317 | ( |
| 318 | set -e |
| 319 | cd clone |
| 320 | rm -rf .git/lfs/objects |
| 321 | |
| 322 | main_sha1=$(git rev-parse main) |
| 323 | git lfs fetch origin "$main_sha1" |
| 324 | assert_local_object "$contents_oid" 1 |
| 325 | refute_local_object "$b_oid" 1 |
| 326 | |
| 327 | git lfs fsck 2>&1 | tee fsck.log |
| 328 | grep "Git LFS fsck OK" fsck.log |
| 329 | ) |
| 330 | end_test |
| 331 | |
| 332 | begin_test "fetch with newbranch commit sha1" |
| 333 | ( |
| 334 | set -e |
| 335 | cd clone |
| 336 | rm -rf .git/lfs/objects |
| 337 | |
| 338 | newbranch_sha1=$(git rev-parse newbranch) |
| 339 | git lfs fetch origin "$newbranch_sha1" |
| 340 | assert_local_object "$contents_oid" 1 |
| 341 | assert_local_object "$b_oid" 1 |
| 342 | |
| 343 | git lfs fsck 2>&1 | tee fsck.log |
| 344 | grep "Git LFS fsck OK" fsck.log |
| 345 | ) |
| 346 | end_test |
| 347 | |
| 348 | begin_test "fetch with include filters in gitconfig" |
| 349 | ( |
| 350 | set -e |
| 351 | cd clone |
| 352 | rm -rf .git/lfs/objects |
| 353 | |
| 354 | git config "lfs.fetchinclude" "a*" |
| 355 | git lfs fetch origin main newbranch |
| 356 | assert_local_object "$contents_oid" 1 |
| 357 | refute_local_object "$b_oid" |
| 358 | |
| 359 | git lfs fsck 2>&1 | tee fsck.log |
| 360 | grep "Git LFS fsck OK" fsck.log |
| 361 | ) |
| 362 | end_test |
| 363 | |
| 364 | begin_test "fetch with exclude filters in gitconfig" |
| 365 | ( |
| 366 | set -e |
| 367 | |
| 368 | cd clone |
| 369 | git config --unset "lfs.fetchinclude" |
| 370 | rm -rf .git/lfs/objects |
| 371 | |
| 372 | git config "lfs.fetchexclude" "a*" |
| 373 | git lfs fetch origin main newbranch |
| 374 | refute_local_object "$contents_oid" |
| 375 | assert_local_object "$b_oid" 1 |
| 376 | |
| 377 | git lfs fsck 2>&1 | tee fsck.log |
| 378 | grep "Git LFS fsck OK" fsck.log |
| 379 | ) |
| 380 | end_test |
| 381 | |
| 382 | begin_test "fetch with include/exclude filters in gitconfig" |
| 383 | ( |
| 384 | set -e |
| 385 | cd clone |
| 386 | rm -rf .git/lfs/objects |
| 387 | git config --unset "lfs.fetchexclude" |
| 388 | |
| 389 | git config "lfs.fetchinclude" "a*,b*" |
| 390 | git config "lfs.fetchexclude" "c*,d*" |
| 391 | git lfs fetch origin main newbranch |
| 392 | assert_local_object "$contents_oid" 1 |
| 393 | assert_local_object "$b_oid" 1 |
| 394 | |
| 395 | rm -rf .git/lfs/objects |
| 396 | git config "lfs.fetchinclude" "c*,d*" |
| 397 | git config "lfs.fetchexclude" "a*,b*" |
| 398 | git lfs fetch origin main newbranch |
| 399 | refute_local_object "$contents_oid" |
| 400 | refute_local_object "$b_oid" |
| 401 | ) |
| 402 | end_test |
| 403 | |
| 404 | begin_test "fetch with include filter in cli" |
| 405 | ( |
| 406 | set -e |
| 407 | cd clone |
| 408 | git config --unset "lfs.fetchinclude" |
| 409 | git config --unset "lfs.fetchexclude" |
| 410 | rm -rf .git/lfs/objects |
| 411 | |
| 412 | git lfs fetch --include="a*" origin main newbranch |
| 413 | assert_local_object "$contents_oid" 1 |
| 414 | refute_local_object "$b_oid" |
| 415 | ) |
| 416 | end_test |
| 417 | |
| 418 | begin_test "fetch with exclude filter in cli" |
| 419 | ( |
| 420 | set -e |
| 421 | cd clone |
| 422 | rm -rf .git/lfs/objects |
| 423 | git lfs fetch --exclude="a*" origin main newbranch |
| 424 | refute_local_object "$contents_oid" |
| 425 | assert_local_object "$b_oid" 1 |
| 426 | ) |
| 427 | end_test |
| 428 | |
| 429 | begin_test "fetch with include/exclude filters in cli" |
| 430 | ( |
| 431 | set -e |
| 432 | cd clone |
| 433 | rm -rf .git/lfs/objects |
| 434 | git lfs fetch -I "a*,b*" -X "c*,d*" origin main newbranch |
| 435 | assert_local_object "$contents_oid" 1 |
| 436 | assert_local_object "$b_oid" 1 |
| 437 | |
| 438 | rm -rf .git/lfs/objects |
| 439 | git lfs fetch --include="c*,d*" --exclude="a*,b*" origin main newbranch |
| 440 | refute_local_object "$contents_oid" |
| 441 | refute_local_object "$b_oid" |
| 442 | ) |
| 443 | end_test |
| 444 | |
| 445 | begin_test "fetch with include filter overriding exclude filter" |
| 446 | ( |
| 447 | set -e |
| 448 | cd clone |
| 449 | rm -rf .git/lfs/objects |
| 450 | git config lfs.fetchexclude "b*" |
| 451 | git lfs fetch -I "b.dat" -X "" origin main newbranch |
| 452 | assert_local_object "$b_oid" "1" |
| 453 | ) |
| 454 | end_test |
| 455 | |
| 456 | begin_test "fetch with missing object" |
| 457 | ( |
| 458 | set -e |
| 459 | cd clone |
| 460 | git config --unset lfs.fetchexclude |
| 461 | rm -rf .git/lfs/objects |
| 462 | |
| 463 | delete_server_object "$reponame" "$b_oid" |
| 464 | refute_server_object "$reponame" "$b_oid" |
| 465 | |
| 466 | # should return non-zero, but should also download all the other valid files too |
| 467 | set +e |
| 468 | git lfs fetch origin main newbranch |
| 469 | fetch_exit=$? |
| 470 | set -e |
| 471 | [ "$fetch_exit" != "0" ] |
| 472 | assert_local_object "$contents_oid" 1 |
| 473 | refute_local_object "$b_oid" |
| 474 | ) |
| 475 | end_test |
| 476 | |
| 477 | begin_test "fetch does not crash on empty key files" |
| 478 | ( |
| 479 | set -e |
| 480 | cd clone |
| 481 | rm -rf .git/lfs/objects |
| 482 | |
| 483 | git config --local http.sslKey /dev/null |
| 484 | git config --local http.sslCert /dev/null |
| 485 | |
| 486 | git lfs fetch origin main 2>&1 | tee fetch.log |
| 487 | grep "Error decoding PEM block" fetch.log |
| 488 | ) |
| 489 | end_test |
| 490 | |
| 491 | begin_test "fetch-all" |
| 492 | ( |
| 493 | set -e |
| 494 | |
| 495 | reponame="fetch-all" |
| 496 | setup_remote_repo "$reponame" |
| 497 | |
| 498 | clone_repo "$reponame" "$reponame" |
| 499 | |
| 500 | git lfs track "*.dat" 2>&1 | tee track.log |
| 501 | grep "Tracking \"\*.dat\"" track.log |
| 502 | |
| 503 | NUMFILES=12 |
| 504 | # generate content we'll use |
| 505 | for ((a=0; a < NUMFILES ; a++)) |
| 506 | do |
| 507 | content[$a]="filecontent$a" |
| 508 | oid[$a]=$(calc_oid "${content[$a]}") |
| 509 | done |
| 510 | |
| 511 | echo "[ |
| 512 | { |
| 513 | \"CommitDate\":\"$(get_date -180d)\", |
| 514 | \"Files\":[ |
| 515 | {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"}, |
| 516 | {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}] |
| 517 | }, |
| 518 | { |
| 519 | \"NewBranch\":\"branch1\", |
| 520 | \"CommitDate\":\"$(get_date -140d)\", |
| 521 | \"Files\":[ |
| 522 | {\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}] |
| 523 | }, |
| 524 | { |
| 525 | \"ParentBranches\":[\"main\"], |
| 526 | \"CommitDate\":\"$(get_date -100d)\", |
| 527 | \"Files\":[ |
| 528 | {\"Filename\":\"file1.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}] |
| 529 | }, |
| 530 | { |
| 531 | \"NewBranch\":\"remote_branch_only\", |
| 532 | \"CommitDate\":\"$(get_date -80d)\", |
| 533 | \"Files\":[ |
| 534 | {\"Filename\":\"file2.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}] |
| 535 | }, |
| 536 | { |
| 537 | \"ParentBranches\":[\"main\"], |
| 538 | \"CommitDate\":\"$(get_date -75d)\", |
| 539 | \"Files\":[ |
| 540 | {\"Filename\":\"file4.dat\",\"Size\":${#content[5]}, \"Data\":\"${content[5]}\"}] |
| 541 | }, |
| 542 | { |
| 543 | \"NewBranch\":\"tag_only\", |
| 544 | \"Tags\":[\"tag1\"], |
| 545 | \"CommitDate\":\"$(get_date -70d)\", |
| 546 | \"Files\":[ |
| 547 | {\"Filename\":\"file4.dat\",\"Size\":${#content[6]}, \"Data\":\"${content[6]}\"}] |
| 548 | }, |
| 549 | { |
| 550 | \"ParentBranches\":[\"main\"], |
| 551 | \"CommitDate\":\"$(get_date -60d)\", |
| 552 | \"Files\":[ |
| 553 | {\"Filename\":\"file1.dat\",\"Size\":${#content[7]}, \"Data\":\"${content[7]}\"}] |
| 554 | }, |
| 555 | { |
| 556 | \"NewBranch\":\"branch3\", |
| 557 | \"CommitDate\":\"$(get_date -50d)\", |
| 558 | \"Files\":[ |
| 559 | {\"Filename\":\"file4.dat\",\"Size\":${#content[8]}, \"Data\":\"${content[8]}\"}] |
| 560 | }, |
| 561 | { |
| 562 | \"CommitDate\":\"$(get_date -40d)\", |
| 563 | \"ParentBranches\":[\"main\"], |
| 564 | \"Files\":[ |
| 565 | {\"Filename\":\"file1.dat\",\"Size\":${#content[9]}, \"Data\":\"${content[9]}\"}, |
| 566 | {\"Filename\":\"file2.dat\",\"Size\":${#content[10]}, \"Data\":\"${content[10]}\"}] |
| 567 | }, |
| 568 | { |
| 569 | \"ParentBranches\":[\"main\"], |
| 570 | \"CommitDate\":\"$(get_date -30d)\", |
| 571 | \"Files\":[ |
| 572 | {\"Filename\":\"file4.dat\",\"Size\":${#content[11]}, \"Data\":\"${content[11]}\"}] |
| 573 | } |
| 574 | ]" | lfstest-testutils addcommits |
| 575 | |
| 576 | git push origin main |
| 577 | git push origin branch1 |
| 578 | git push origin branch3 |
| 579 | git push origin remote_branch_only |
| 580 | git push origin tag_only |
| 581 | git push origin tag1 |
| 582 | for ((a=0; a < NUMFILES ; a++)) |
| 583 | do |
| 584 | assert_server_object "$reponame" "${oid[$a]}" |
| 585 | done |
| 586 | |
| 587 | # delete remote_branch_only and make sure that objects are downloaded even |
| 588 | # though not checked out to a local branch (full backup always) |
| 589 | git branch -D remote_branch_only |
| 590 | |
| 591 | # delete tag_only to make sure objects are downloaded when only reachable from tag |
| 592 | git branch -D tag_only |
| 593 | |
| 594 | rm -rf .git/lfs/objects |
| 595 | |
| 596 | git lfs fetch --all origin |
| 597 | for ((a=0; a < NUMFILES ; a++)) |
| 598 | do |
| 599 | assert_local_object "${oid[$a]}" "${#content[$a]}" |
| 600 | done |
| 601 | |
| 602 | rm -rf .git/lfs/objects |
| 603 | |
| 604 | # fetch all objects reachable from the main branch only |
| 605 | git lfs fetch --all origin main |
| 606 | for a in 0 1 3 5 7 9 10 11 |
| 607 | do |
| 608 | assert_local_object "${oid[$a]}" "${#content[$a]}" |
| 609 | done |
| 610 | for a in 2 4 6 8 |
| 611 | do |
| 612 | refute_local_object "${oid[$a]}" |
| 613 | done |
| 614 | |
| 615 | rm -rf .git/lfs/objects |
| 616 | |
| 617 | # fetch all objects reachable from branch1 and tag1 only |
| 618 | git lfs fetch --all origin branch1 tag1 |
| 619 | for a in 0 1 2 3 5 6 |
| 620 | do |
| 621 | assert_local_object "${oid[$a]}" "${#content[$a]}" |
| 622 | done |
| 623 | for a in 4 7 8 9 10 11 |
| 624 | do |
| 625 | refute_local_object "${oid[$a]}" |
| 626 | done |
| 627 | |
| 628 | # Make a bare clone of the repository |
| 629 | cd .. |
| 630 | git clone --bare "$GITSERVER/$reponame" "$reponame-bare" |
| 631 | cd "$reponame-bare" |
| 632 | |
| 633 | # Perform the same assertion as above, on the same data |
| 634 | git lfs fetch --all origin |
| 635 | for ((a=0; a < NUMFILES ; a++)) |
| 636 | do |
| 637 | assert_local_object "${oid[$a]}" "${#content[$a]}" |
| 638 | done |
| 639 | |
| 640 | rm -rf lfs/objects |
| 641 | |
| 642 | # fetch all objects reachable from the main branch only |
| 643 | git lfs fetch --all origin main |
| 644 | for a in 0 1 3 5 7 9 10 11 |
| 645 | do |
| 646 | assert_local_object "${oid[$a]}" "${#content[$a]}" |
| 647 | done |
| 648 | for a in 2 4 6 8 |
| 649 | do |
| 650 | refute_local_object "${oid[$a]}" |
| 651 | done |
| 652 | |
| 653 | rm -rf lfs/objects |
| 654 | |
| 655 | echo "main" | git lfs fetch --all --stdin origin |
| 656 | for a in 0 1 3 5 7 9 10 11 |
| 657 | do |
| 658 | assert_local_object "${oid[$a]}" "${#content[$a]}" |
| 659 | done |
| 660 | for a in 2 4 6 8 |
| 661 | do |
| 662 | refute_local_object "${oid[$a]}" |
| 663 | done |
| 664 | |
| 665 | rm -rf lfs/objects |
| 666 | |
| 667 | # fetch all objects reachable from branch1 and tag1 only |
| 668 | git lfs fetch --all origin branch1 tag1 |
| 669 | for a in 0 1 2 3 5 6 |
| 670 | do |
| 671 | assert_local_object "${oid[$a]}" "${#content[$a]}" |
| 672 | done |
| 673 | for a in 4 7 8 9 10 11 |
| 674 | do |
| 675 | refute_local_object "${oid[$a]}" |
| 676 | done |
| 677 | |
| 678 | rm -rf lfs/objects |
| 679 | |
| 680 | printf "branch1\ntag1\n\n" | git lfs fetch --all --stdin origin |
| 681 | for a in 0 1 2 3 5 6 |
| 682 | do |
| 683 | assert_local_object "${oid[$a]}" "${#content[$a]}" |
| 684 | done |
| 685 | for a in 4 7 8 9 10 11 |
| 686 | do |
| 687 | refute_local_object "${oid[$a]}" |
| 688 | done |
| 689 | |
| 690 | ) |
| 691 | end_test |
| 692 | |
| 693 | begin_test "fetch: outside git repository" |
| 694 | ( |
| 695 | set +e |
| 696 | git lfs fetch 2>&1 > fetch.log |
| 697 | res=$? |
| 698 | |
| 699 | set -e |
| 700 | if [ "$res" = "0" ]; then |
| 701 | echo "Passes because $GIT_LFS_TEST_DIR is unset." |
| 702 | exit 0 |
| 703 | fi |
| 704 | [ "$res" = "128" ] |
| 705 | grep "Not in a Git repository" fetch.log |
| 706 | ) |
| 707 | end_test |
| 708 | |
| 709 | begin_test "fetch with no origin remote" |
| 710 | ( |
| 711 | set -e |
| 712 | |
| 713 | reponame="fetch-no-remote" |
| 714 | setup_remote_repo "$reponame" |
| 715 | |
| 716 | clone_repo "$reponame" no-remote-clone |
| 717 | |
| 718 | clone_repo "$reponame" no-remote-repo |
| 719 | |
| 720 | git lfs track "*.dat" 2>&1 | tee track.log |
| 721 | grep "Tracking \"\*.dat\"" track.log |
| 722 | |
| 723 | contents="a" |
| 724 | contents_oid=$(calc_oid "$contents") |
| 725 | |
| 726 | printf "%s" "$contents" > a.dat |
| 727 | git add a.dat |
| 728 | git add .gitattributes |
| 729 | git commit -m "add a.dat" 2>&1 | tee commit.log |
| 730 | grep "main (root-commit)" commit.log |
| 731 | grep "2 files changed" commit.log |
| 732 | grep "create mode 100644 a.dat" commit.log |
| 733 | grep "create mode 100644 .gitattributes" commit.log |
| 734 | |
| 735 | [ "a" = "$(cat a.dat)" ] |
| 736 | |
| 737 | assert_local_object "$contents_oid" 1 |
| 738 | |
| 739 | refute_server_object "$reponame" "$contents_oid" |
| 740 | |
| 741 | git push origin main 2>&1 | tee push.log |
| 742 | grep "Uploading LFS objects: 100% (1/1), 1 B" push.log |
| 743 | grep "main -> main" push.log |
| 744 | |
| 745 | |
| 746 | # change to the clone's working directory |
| 747 | cd ../no-remote-clone |
| 748 | |
| 749 | # pull commits & lfs |
| 750 | git pull origin main 2>&1 |
| 751 | assert_local_object "$contents_oid" 1 |
| 752 | |
| 753 | # now checkout detached HEAD so we're not tracking anything on remote |
| 754 | git checkout --detach |
| 755 | |
| 756 | # delete lfs |
| 757 | rm -rf .git/lfs |
| 758 | |
| 759 | # rename remote from 'origin' to 'something' |
| 760 | git remote rename origin something |
| 761 | |
| 762 | # fetch should still pick this remote as in the case of no tracked remote, |
| 763 | # and no origin, but only 1 remote, should pick the only one as default |
| 764 | git lfs fetch |
| 765 | assert_local_object "$contents_oid" 1 |
| 766 | ) |
| 767 | end_test |
| 768 | |
| 769 | begin_test "fetch --prune" |
| 770 | ( |
| 771 | set -e |
| 772 | |
| 773 | reponame="fetch_prune" |
| 774 | setup_remote_repo "remote_$reponame" |
| 775 | |
| 776 | clone_repo "remote_$reponame" "clone_$reponame" |
| 777 | |
| 778 | git lfs track "*.dat" 2>&1 | tee track.log |
| 779 | grep "Tracking \"\*.dat\"" track.log |
| 780 | |
| 781 | content_head="HEAD content" |
| 782 | content_commit2="Content for commit 2 (prune)" |
| 783 | content_commit1="Content for commit 1 (prune)" |
| 784 | oid_head=$(calc_oid "$content_head") |
| 785 | oid_commit2=$(calc_oid "$content_commit2") |
| 786 | oid_commit1=$(calc_oid "$content_commit1") |
| 787 | |
| 788 | echo "[ |
| 789 | { |
| 790 | \"CommitDate\":\"$(get_date -50d)\", |
| 791 | \"Files\":[ |
| 792 | {\"Filename\":\"file.dat\",\"Size\":${#content_commit1}, \"Data\":\"$content_commit1\"}] |
| 793 | }, |
| 794 | { |
| 795 | \"CommitDate\":\"$(get_date -35d)\", |
| 796 | \"Files\":[ |
| 797 | {\"Filename\":\"file.dat\",\"Size\":${#content_commit2}, \"Data\":\"$content_commit2\"}] |
| 798 | }, |
| 799 | { |
| 800 | \"CommitDate\":\"$(get_date -25d)\", |
| 801 | \"Files\":[ |
| 802 | {\"Filename\":\"file.dat\",\"Size\":${#content_head}, \"Data\":\"$content_head\"}] |
| 803 | } |
| 804 | ]" | lfstest-testutils addcommits |
| 805 | |
| 806 | # push all so no unpushed reason to not prune |
| 807 | git push origin main |
| 808 | |
| 809 | # set no recents so max ability to prune |
| 810 | git config lfs.fetchrecentrefsdays 0 |
| 811 | git config lfs.fetchrecentcommitsdays 0 |
| 812 | |
| 813 | # delete HEAD object to prove that we still download something |
| 814 | # also prune at the same time which will remove anything other than HEAD |
| 815 | delete_local_object "$oid_head" |
| 816 | git lfs fetch --prune |
| 817 | assert_local_object "$oid_head" "${#content_head}" |
| 818 | refute_local_object "$oid_commit1" |
| 819 | refute_local_object "$oid_commit2" |
| 820 | ) |
| 821 | end_test |
| 822 | |
| 823 | begin_test "fetch raw remote url" |
| 824 | ( |
| 825 | set -e |
| 826 | mkdir raw |
| 827 | cd raw |
| 828 | git init |
| 829 | git lfs install --local --skip-smudge |
| 830 | |
| 831 | git remote add origin "$GITSERVER/$reponame" |
| 832 | git pull origin main |
| 833 | |
| 834 | # LFS object not downloaded, pointer in working directory |
| 835 | refute_local_object "$contents_oid" |
| 836 | grep "$content_oid" a.dat |
| 837 | |
| 838 | git lfs fetch "$GITSERVER/$reponame" |
| 839 | |
| 840 | # LFS object downloaded, pointer still in working directory |
| 841 | assert_local_object "$contents_oid" 1 |
| 842 | grep "$content_oid" a.dat |
| 843 | ) |
| 844 | end_test |
| 845 | |
| 846 | begin_test "fetch with invalid ref" |
| 847 | ( |
| 848 | set -e |
| 849 | cd repo |
| 850 | |
| 851 | git lfs fetch origin jibberish >fetch.log 2>&1 && exit 1 |
| 852 | grep "Invalid ref argument" fetch.log |
| 853 | ) |
| 854 | end_test |
| 855 | |
| 856 | begin_test "fetch with invalid remote" |
| 857 | ( |
| 858 | set -e |
| 859 | cd repo |
| 860 | git lfs fetch not-a-remote 2>&1 | tee fetch.log |
| 861 | grep "Invalid remote name" fetch.log |
| 862 | ) |
| 863 | end_test |
| 864 | |
| 865 | begin_test "fetch fails when LFS directory has wrong permissions" |
| 866 | ( |
| 867 | set -e |
| 868 | |
| 869 | # Windows lacks POSIX permissions. |
| 870 | [ "$IS_WINDOWS" -eq 1 ] && exit 0 |
| 871 | |
| 872 | # Root is exempt from permissions. |
| 873 | [ "$(id -u)" -eq 0 ] && exit 0 |
| 874 | |
| 875 | cd shared |
| 876 | rm -rf .git/lfs/objects |
| 877 | mkdir .git/lfs/objects |
| 878 | chmod 400 .git/lfs/objects |
| 879 | |
| 880 | git lfs fetch 2>&1 | tee fetch.log |
| 881 | grep "error trying to create local storage directory" fetch.log |
| 882 | ) |
| 883 | end_test |