| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "pull" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="$(basename "$0" ".sh")" |
| 10 | setup_remote_repo "$reponame" |
| 11 | |
| 12 | clone_repo "$reponame" clone |
| 13 | clone_repo "$reponame" repo |
| 14 | |
| 15 | git lfs track "*.dat" 2>&1 | tee track.log |
| 16 | grep "Tracking \"\*.dat\"" track.log |
| 17 | |
| 18 | contents="a" |
| 19 | contents_oid=$(calc_oid "$contents") |
| 20 | contents2="A" |
| 21 | contents2_oid=$(calc_oid "$contents2") |
| 22 | contents3="dir" |
| 23 | contents3_oid=$(calc_oid "$contents3") |
| 24 | |
| 25 | mkdir -p dir1 dir2/dir3/dir4 |
| 26 | echo "*.log" > .gitignore |
| 27 | printf "%s" "$contents" > a.dat |
| 28 | printf "%s" "$contents2" > á.dat |
| 29 | printf "%s" "$contents3" > dir1/dir.dat |
| 30 | printf "%s" "$contents3" > dir2/dir3/dir4/dir.dat |
| 31 | git add . |
| 32 | git commit -m "add files" 2>&1 | tee commit.log |
| 33 | grep "main (root-commit)" commit.log |
| 34 | grep "6 files changed" commit.log |
| 35 | grep "create mode 100644 a.dat" commit.log |
| 36 | grep "create mode 100644 .gitattributes" commit.log |
| 37 | |
| 38 | [ "a" = "$(cat a.dat)" ] |
| 39 | [ "A" = "$(cat "á.dat")" ] |
| 40 | [ "dir" = "$(cat "dir1/dir.dat")" ] |
| 41 | [ "dir" = "$(cat "dir2/dir3/dir4/dir.dat")" ] |
| 42 | |
| 43 | assert_pointer "main" "a.dat" "$contents_oid" 1 |
| 44 | assert_pointer "main" "á.dat" "$contents2_oid" 1 |
| 45 | assert_pointer "main" "dir1/dir.dat" "$contents3_oid" 3 |
| 46 | |
| 47 | refute_server_object "$reponame" "$contents_oid" |
| 48 | refute_server_object "$reponame" "$contents2_oid" |
| 49 | refute_server_object "$reponame" "$contents3_oid" |
| 50 | |
| 51 | echo "initial push" |
| 52 | git push origin main 2>&1 | tee push.log |
| 53 | grep "Uploading LFS objects: 100% (3/3), 5 B" push.log |
| 54 | grep "main -> main" push.log |
| 55 | |
| 56 | assert_server_object "$reponame" "$contents_oid" |
| 57 | assert_server_object "$reponame" "$contents2_oid" |
| 58 | assert_server_object "$reponame" "$contents3_oid" |
| 59 | |
| 60 | # change to the clone's working directory |
| 61 | cd ../clone |
| 62 | |
| 63 | echo "normal pull" |
| 64 | git config branch.main.remote origin |
| 65 | git config branch.main.merge refs/heads/main |
| 66 | git pull 2>&1 |
| 67 | |
| 68 | [ "a" = "$(cat a.dat)" ] |
| 69 | [ "A" = "$(cat "á.dat")" ] |
| 70 | [ "dir" = "$(cat "dir1/dir.dat")" ] |
| 71 | [ "dir" = "$(cat "dir2/dir3/dir4/dir.dat")" ] |
| 72 | |
| 73 | assert_local_object "$contents_oid" 1 |
| 74 | assert_local_object "$contents2_oid" 1 |
| 75 | assert_local_object "$contents3_oid" 3 |
| 76 | assert_clean_status |
| 77 | |
| 78 | echo "lfs pull" |
| 79 | rm -rf a.dat á.dat dir1 dir2 # removing files makes the status dirty |
| 80 | rm -rf .git/lfs/objects |
| 81 | git lfs pull |
| 82 | [ "a" = "$(cat a.dat)" ] |
| 83 | [ "A" = "$(cat "á.dat")" ] |
| 84 | [ "dir" = "$(cat "dir1/dir.dat")" ] |
| 85 | [ "dir" = "$(cat "dir2/dir3/dir4/dir.dat")" ] |
| 86 | assert_local_object "$contents_oid" 1 |
| 87 | assert_local_object "$contents2_oid" 1 |
| 88 | assert_local_object "$contents3_oid" 3 |
| 89 | assert_clean_status |
| 90 | git lfs fsck |
| 91 | |
| 92 | echo "lfs pull with remote" |
| 93 | rm -rf a.dat á.dat dir1 dir2 |
| 94 | rm -rf .git/lfs/objects |
| 95 | git lfs pull origin |
| 96 | [ "a" = "$(cat a.dat)" ] |
| 97 | [ "A" = "$(cat "á.dat")" ] |
| 98 | [ "dir" = "$(cat "dir1/dir.dat")" ] |
| 99 | [ "dir" = "$(cat "dir2/dir3/dir4/dir.dat")" ] |
| 100 | assert_local_object "$contents_oid" 1 |
| 101 | assert_local_object "$contents2_oid" 1 |
| 102 | assert_local_object "$contents3_oid" 3 |
| 103 | assert_clean_status |
| 104 | git lfs fsck |
| 105 | |
| 106 | echo "lfs pull with local storage" |
| 107 | rm -rf a.dat á.dat dir1 dir2 |
| 108 | git lfs pull |
| 109 | [ "a" = "$(cat a.dat)" ] |
| 110 | [ "A" = "$(cat "á.dat")" ] |
| 111 | [ "dir" = "$(cat "dir1/dir.dat")" ] |
| 112 | [ "dir" = "$(cat "dir2/dir3/dir4/dir.dat")" ] |
| 113 | assert_clean_status |
| 114 | |
| 115 | echo "test pre-existing directories" |
| 116 | rm -rf dir1/dir.dat dir2/dir3/dir4 |
| 117 | git lfs pull |
| 118 | [ "dir" = "$(cat "dir1/dir.dat")" ] |
| 119 | [ "dir" = "$(cat "dir2/dir3/dir4/dir.dat")" ] |
| 120 | assert_clean_status |
| 121 | |
| 122 | echo "lfs pull with include/exclude filters in gitconfig" |
| 123 | rm -rf .git/lfs/objects |
| 124 | git config "lfs.fetchinclude" "a*" |
| 125 | git lfs pull |
| 126 | assert_local_object "$contents_oid" 1 |
| 127 | assert_clean_status |
| 128 | |
| 129 | rm -rf .git/lfs/objects |
| 130 | git config --unset "lfs.fetchinclude" |
| 131 | git config "lfs.fetchexclude" "a*" |
| 132 | git lfs pull |
| 133 | refute_local_object "$contents_oid" |
| 134 | assert_clean_status |
| 135 | |
| 136 | echo "lfs pull with include/exclude filters in command line" |
| 137 | git config --unset "lfs.fetchexclude" |
| 138 | rm -rf .git/lfs/objects |
| 139 | git lfs pull --include="a*" |
| 140 | assert_local_object "$contents_oid" 1 |
| 141 | assert_clean_status |
| 142 | |
| 143 | rm -rf .git/lfs/objects |
| 144 | git lfs pull --exclude="a*" |
| 145 | refute_local_object "$contents_oid" |
| 146 | assert_clean_status |
| 147 | |
| 148 | echo "resetting to test status" |
| 149 | git reset --hard |
| 150 | assert_clean_status |
| 151 | |
| 152 | echo "lfs pull clean status" |
| 153 | git lfs pull |
| 154 | [ "a" = "$(cat a.dat)" ] |
| 155 | [ "A" = "$(cat "á.dat")" ] |
| 156 | [ "dir" = "$(cat "dir1/dir.dat")" ] |
| 157 | [ "dir" = "$(cat "dir2/dir3/dir4/dir.dat")" ] |
| 158 | assert_local_object "$contents_oid" 1 |
| 159 | assert_local_object "$contents2_oid" 1 |
| 160 | assert_local_object "$contents3_oid" 3 |
| 161 | assert_clean_status |
| 162 | |
| 163 | echo "lfs pull with -I" |
| 164 | rm -rf .git/lfs/objects |
| 165 | rm -rf a.dat "á.dat" "dir1/dir.dat" dir2 |
| 166 | git lfs pull -I "a.*,dir1/dir.*,dir2/**" |
| 167 | [ "a" = "$(cat a.dat)" ] |
| 168 | [ ! -e "á.dat" ] |
| 169 | [ "dir" = "$(cat "dir1/dir.dat")" ] |
| 170 | [ "dir" = "$(cat "dir2/dir3/dir4/dir.dat")" ] |
| 171 | assert_local_object "$contents_oid" 1 |
| 172 | refute_local_object "$contents2_oid" |
| 173 | assert_local_object "$contents3_oid" 3 |
| 174 | assert_clean_worktree_with_exceptions '\\303\\241\.dat' |
| 175 | |
| 176 | git lfs pull -I "*.dat" |
| 177 | [ "A" = "$(cat "á.dat")" ] |
| 178 | assert_local_object "$contents2_oid" 1 |
| 179 | assert_clean_status |
| 180 | |
| 181 | echo "lfs pull with empty file" |
| 182 | touch empty.dat |
| 183 | git add empty.dat |
| 184 | git commit -m 'empty' |
| 185 | git lfs pull |
| 186 | [ -z "$(cat empty.dat)" ] |
| 187 | assert_clean_status |
| 188 | |
| 189 | echo "resetting to test status" |
| 190 | git reset --hard HEAD^ |
| 191 | assert_clean_status |
| 192 | |
| 193 | echo "lfs pull in subdir" |
| 194 | rm -rf .git/lfs/objects |
| 195 | rm -rf a.dat "á.dat" "dir1/dir.dat" dir2 |
| 196 | pushd dir1 |
| 197 | git lfs pull |
| 198 | popd |
| 199 | [ "a" = "$(cat a.dat)" ] |
| 200 | [ "A" = "$(cat "á.dat")" ] |
| 201 | [ "dir" = "$(cat "dir1/dir.dat")" ] |
| 202 | [ "dir" = "$(cat "dir2/dir3/dir4/dir.dat")" ] |
| 203 | assert_local_object "$contents_oid" 1 |
| 204 | assert_local_object "$contents2_oid" 1 |
| 205 | assert_local_object "$contents3_oid" 3 |
| 206 | assert_clean_status |
| 207 | |
| 208 | echo "lfs pull in subdir with -I" |
| 209 | rm -rf .git/lfs/objects |
| 210 | rm -rf a.dat "á.dat" "dir1/dir.dat" dir2 |
| 211 | pushd dir1 |
| 212 | git lfs pull -I "á.*,dir1/dir.dat,dir2/**" |
| 213 | popd |
| 214 | [ ! -e a.dat ] |
| 215 | [ "A" = "$(cat "á.dat")" ] |
| 216 | [ "dir" = "$(cat "dir1/dir.dat")" ] |
| 217 | [ "dir" = "$(cat "dir2/dir3/dir4/dir.dat")" ] |
| 218 | refute_local_object "$contents_oid" |
| 219 | assert_local_object "$contents2_oid" 1 |
| 220 | assert_local_object "$contents3_oid" 3 |
| 221 | assert_clean_worktree_with_exceptions "a\.dat" |
| 222 | |
| 223 | pushd dir1 |
| 224 | git lfs pull -I "*.dat" |
| 225 | popd |
| 226 | [ "a" = "$(cat a.dat)" ] |
| 227 | assert_local_object "$contents_oid" 1 |
| 228 | assert_clean_status |
| 229 | ) |
| 230 | end_test |
| 231 | |
| 232 | begin_test "pull: skip directory file conflicts" |
| 233 | ( |
| 234 | set -e |
| 235 | |
| 236 | reponame="pull-skip-dir-file-conflicts" |
| 237 | setup_remote_repo "$reponame" |
| 238 | clone_repo "$reponame" "$reponame" |
| 239 | |
| 240 | git lfs track "*.dat" |
| 241 | |
| 242 | contents="a" |
| 243 | contents_oid="$(calc_oid "$contents")" |
| 244 | mkdir -p dir1 dir2/dir3/dir4 |
| 245 | printf "%s" "$contents" >dir1/a.dat |
| 246 | printf "%s" "$contents" >dir2/dir3/dir4/a.dat |
| 247 | |
| 248 | git add .gitattributes dir1 dir2 |
| 249 | git commit -m "initial commit" |
| 250 | |
| 251 | git push origin main |
| 252 | assert_server_object "$reponame" "$contents_oid" |
| 253 | |
| 254 | cd .. |
| 255 | GIT_LFS_SKIP_SMUDGE=1 git clone "$GITSERVER/$reponame" "${reponame}-assert" |
| 256 | |
| 257 | cd "${reponame}-assert" |
| 258 | refute_local_object "$contents_oid" 1 |
| 259 | |
| 260 | rm -rf dir1 dir2/dir3 |
| 261 | touch dir1 dir2/dir3 |
| 262 | |
| 263 | git lfs pull 2>&1 | tee pull.log |
| 264 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 265 | echo >&2 "fatal: expected pull to succeed ..." |
| 266 | exit 1 |
| 267 | fi |
| 268 | grep '"dir1/a\.dat": not a directory' pull.log |
| 269 | grep '"dir2/dir3/dir4/a\.dat": not a directory' pull.log |
| 270 | |
| 271 | assert_local_object "$contents_oid" 1 |
| 272 | |
| 273 | [ -f "dir1" ] |
| 274 | [ -f "dir2/dir3" ] |
| 275 | assert_clean_index |
| 276 | |
| 277 | rm -rf .git/lfs/objects |
| 278 | |
| 279 | pushd dir2 |
| 280 | git lfs pull 2>&1 | tee pull.log |
| 281 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 282 | echo >&2 "fatal: expected pull to succeed ..." |
| 283 | exit 1 |
| 284 | fi |
| 285 | grep '"dir1/a\.dat": not a directory' pull.log |
| 286 | grep '"dir2/dir3/dir4/a\.dat": not a directory' pull.log |
| 287 | popd |
| 288 | |
| 289 | assert_local_object "$contents_oid" 1 |
| 290 | |
| 291 | [ -f "dir1" ] |
| 292 | [ -f "dir2/dir3" ] |
| 293 | assert_clean_index |
| 294 | ) |
| 295 | end_test |
| 296 | |
| 297 | begin_test "pull: skip directory symlink conflicts" |
| 298 | ( |
| 299 | set -e |
| 300 | |
| 301 | skip_if_symlinks_unsupported |
| 302 | |
| 303 | reponame="pull-skip-dir-symlink-conflicts" |
| 304 | setup_remote_repo "$reponame" |
| 305 | clone_repo "$reponame" "$reponame" |
| 306 | |
| 307 | git lfs track "*.dat" |
| 308 | |
| 309 | contents="a" |
| 310 | contents_oid="$(calc_oid "$contents")" |
| 311 | mkdir -p dir1 dir2/dir3/dir4 |
| 312 | printf "%s" "$contents" >dir1/a.dat |
| 313 | printf "%s" "$contents" >dir2/dir3/dir4/a.dat |
| 314 | |
| 315 | git add .gitattributes dir1 dir2 |
| 316 | git commit -m "initial commit" |
| 317 | |
| 318 | git push origin main |
| 319 | assert_server_object "$reponame" "$contents_oid" |
| 320 | |
| 321 | cd .. |
| 322 | GIT_LFS_SKIP_SMUDGE=1 git clone "$GITSERVER/$reponame" "${reponame}-assert" |
| 323 | |
| 324 | cd "${reponame}-assert" |
| 325 | refute_local_object "$contents_oid" 1 |
| 326 | |
| 327 | # test with symlinks to directories |
| 328 | rm -rf dir1 dir2/dir3 ../link* |
| 329 | mkdir ../link1 ../link2 |
| 330 | ln -s ../link1 dir1 |
| 331 | ln -s ../../link2 dir2/dir3 |
| 332 | |
| 333 | git lfs pull 2>&1 | tee pull.log |
| 334 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 335 | echo >&2 "fatal: expected pull to succeed ..." |
| 336 | exit 1 |
| 337 | fi |
| 338 | grep '"dir1/a\.dat": not a directory' pull.log |
| 339 | grep '"dir2/dir3/dir4/a\.dat": not a directory' pull.log |
| 340 | [ 0 -eq "$(grep -c "is beyond a symbolic link" pull.log)" ] |
| 341 | |
| 342 | assert_local_object "$contents_oid" 1 |
| 343 | |
| 344 | [ -L "dir1" ] |
| 345 | [ -L "dir2/dir3" ] |
| 346 | [ ! -e "../link1/a.dat" ] |
| 347 | [ ! -e "../link2/dir4" ] |
| 348 | assert_clean_index |
| 349 | |
| 350 | rm -rf .git/lfs/objects |
| 351 | |
| 352 | rm -rf dir1 dir2/dir3 |
| 353 | mkdir link1 link2 |
| 354 | ln -s link1 dir1 |
| 355 | ln -s ../link2 dir2/dir3 |
| 356 | |
| 357 | git lfs pull 2>&1 | tee pull.log |
| 358 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 359 | echo >&2 "fatal: expected pull to succeed ..." |
| 360 | exit 1 |
| 361 | fi |
| 362 | grep '"dir1/a\.dat": not a directory' pull.log |
| 363 | grep '"dir2/dir3/dir4/a\.dat": not a directory' pull.log |
| 364 | [ 0 -eq "$(grep -c "is beyond a symbolic link" pull.log)" ] |
| 365 | |
| 366 | assert_local_object "$contents_oid" 1 |
| 367 | |
| 368 | [ -L "dir1" ] |
| 369 | [ -L "dir2/dir3" ] |
| 370 | [ ! -e "link1/a.dat" ] |
| 371 | [ ! -e "link2/dir4" ] |
| 372 | assert_clean_index |
| 373 | |
| 374 | rm -rf .git/lfs/objects |
| 375 | |
| 376 | pushd dir2 |
| 377 | git lfs pull 2>&1 | tee pull.log |
| 378 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 379 | echo >&2 "fatal: expected pull to succeed ..." |
| 380 | exit 1 |
| 381 | fi |
| 382 | grep '"dir1/a\.dat": not a directory' pull.log |
| 383 | grep '"dir2/dir3/dir4/a\.dat": not a directory' pull.log |
| 384 | [ 0 -eq "$(grep -c "is beyond a symbolic link" pull.log)" ] |
| 385 | popd |
| 386 | |
| 387 | assert_local_object "$contents_oid" 1 |
| 388 | |
| 389 | [ -L "dir1" ] |
| 390 | [ -L "dir2/dir3" ] |
| 391 | [ ! -e "link1/a.dat" ] |
| 392 | [ ! -e "link2/dir4" ] |
| 393 | assert_clean_index |
| 394 | |
| 395 | # test with symlink to file and dangling symlink |
| 396 | rm -rf .git/lfs/objects |
| 397 | |
| 398 | rm -rf dir1 dir2/dir3 ../link* |
| 399 | touch ../link1 |
| 400 | ln -s ../link1 dir1 |
| 401 | ln -s ../../link2 dir2/dir3 |
| 402 | |
| 403 | git lfs pull 2>&1 | tee pull.log |
| 404 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 405 | echo >&2 "fatal: expected pull to succeed ..." |
| 406 | exit 1 |
| 407 | fi |
| 408 | grep '"dir1/a\.dat": not a directory' pull.log |
| 409 | grep '"dir2/dir3/dir4/a\.dat": not a directory' pull.log |
| 410 | |
| 411 | assert_local_object "$contents_oid" 1 |
| 412 | |
| 413 | [ -L "dir1" ] |
| 414 | [ -L "dir2/dir3" ] |
| 415 | [ -f "../link1" ] |
| 416 | [ ! -e "../link2" ] |
| 417 | assert_clean_index |
| 418 | |
| 419 | rm -rf .git/lfs/objects |
| 420 | |
| 421 | rm -rf dir1 dir2/dir3 link* |
| 422 | touch link1 |
| 423 | ln -s link1 dir1 |
| 424 | ln -s ../link2 dir2/dir3 |
| 425 | |
| 426 | git lfs pull 2>&1 | tee pull.log |
| 427 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 428 | echo >&2 "fatal: expected pull to succeed ..." |
| 429 | exit 1 |
| 430 | fi |
| 431 | grep '"dir1/a\.dat": not a directory' pull.log |
| 432 | grep '"dir2/dir3/dir4/a\.dat": not a directory' pull.log |
| 433 | |
| 434 | assert_local_object "$contents_oid" 1 |
| 435 | |
| 436 | [ -L "dir1" ] |
| 437 | [ -L "dir2/dir3" ] |
| 438 | [ -f "link1" ] |
| 439 | [ ! -e "link2" ] |
| 440 | assert_clean_index |
| 441 | |
| 442 | rm -rf .git/lfs/objects |
| 443 | |
| 444 | pushd dir2 |
| 445 | git lfs pull 2>&1 | tee pull.log |
| 446 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 447 | echo >&2 "fatal: expected pull to succeed ..." |
| 448 | exit 1 |
| 449 | fi |
| 450 | grep '"dir1/a\.dat": not a directory' pull.log |
| 451 | grep '"dir2/dir3/dir4/a\.dat": not a directory' pull.log |
| 452 | popd |
| 453 | |
| 454 | assert_local_object "$contents_oid" 1 |
| 455 | |
| 456 | [ -L "dir1" ] |
| 457 | [ -L "dir2/dir3" ] |
| 458 | [ -f "link1" ] |
| 459 | [ ! -e "link2" ] |
| 460 | assert_clean_index |
| 461 | ) |
| 462 | end_test |
| 463 | |
| 464 | begin_test "pull: skip file symlink conflicts" |
| 465 | ( |
| 466 | set -e |
| 467 | |
| 468 | skip_if_symlinks_unsupported |
| 469 | |
| 470 | reponame="pull-skip-file-symlink-conflicts" |
| 471 | setup_remote_repo "$reponame" |
| 472 | clone_repo "$reponame" "$reponame" |
| 473 | |
| 474 | git lfs track "*.dat" |
| 475 | |
| 476 | contents="a" |
| 477 | contents_oid="$(calc_oid "$contents")" |
| 478 | mkdir -p dir1/dir2/dir3 |
| 479 | printf "%s" "$contents" >a.dat |
| 480 | printf "%s" "$contents" >dir1/dir2/dir3/a.dat |
| 481 | |
| 482 | git add .gitattributes a.dat dir1 |
| 483 | git commit -m "initial commit" |
| 484 | |
| 485 | git push origin main |
| 486 | assert_server_object "$reponame" "$contents_oid" |
| 487 | |
| 488 | cd .. |
| 489 | GIT_LFS_SKIP_SMUDGE=1 git clone "$GITSERVER/$reponame" "${reponame}-assert" |
| 490 | |
| 491 | cd "${reponame}-assert" |
| 492 | refute_local_object "$contents_oid" 1 |
| 493 | |
| 494 | # test with symlinks to pointer files |
| 495 | rm -rf a.dat dir1/dir2/dir3/a.dat ../link* |
| 496 | contents_pointer="$(git cat-file -p ":a.dat")" |
| 497 | printf "%s" "$contents_pointer" >../link1 |
| 498 | printf "%s" "$contents_pointer" >../link2 |
| 499 | ln -s ../link1 a.dat |
| 500 | ln -s ../../../../link2 dir1/dir2/dir3/a.dat |
| 501 | |
| 502 | git lfs pull 2>&1 | tee pull.log |
| 503 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 504 | echo >&2 "fatal: expected pull to succeed ..." |
| 505 | exit 1 |
| 506 | fi |
| 507 | grep '"a\.dat": not a regular file' pull.log |
| 508 | grep '"dir1/dir2/dir3/a\.dat": not a regular file' pull.log |
| 509 | |
| 510 | assert_local_object "$contents_oid" 1 |
| 511 | |
| 512 | [ -L "a.dat" ] |
| 513 | [ -L "dir1/dir2/dir3/a.dat" ] |
| 514 | [ -f "../link1" ] |
| 515 | [ "$contents_pointer" = "$(cat ../link1)" ] |
| 516 | [ -f "../link2" ] |
| 517 | [ "$contents_pointer" = "$(cat ../link2)" ] |
| 518 | assert_clean_index |
| 519 | |
| 520 | rm -rf .git/lfs/objects |
| 521 | |
| 522 | rm -rf a.dat dir1/dir2/dir3/a.dat link* |
| 523 | printf "%s" "$contents_pointer" >link1 |
| 524 | printf "%s" "$contents_pointer" >link2 |
| 525 | ln -s link1 a.dat |
| 526 | ln -s ../../../link2 dir1/dir2/dir3/a.dat |
| 527 | |
| 528 | git lfs pull 2>&1 | tee pull.log |
| 529 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 530 | echo >&2 "fatal: expected pull to succeed ..." |
| 531 | exit 1 |
| 532 | fi |
| 533 | grep '"a\.dat": not a regular file' pull.log |
| 534 | grep '"dir1/dir2/dir3/a\.dat": not a regular file' pull.log |
| 535 | |
| 536 | assert_local_object "$contents_oid" 1 |
| 537 | |
| 538 | [ -L "a.dat" ] |
| 539 | [ -L "dir1/dir2/dir3/a.dat" ] |
| 540 | [ -f "link1" ] |
| 541 | [ "$contents_pointer" = "$(cat link1)" ] |
| 542 | [ -f "link2" ] |
| 543 | [ "$contents_pointer" = "$(cat link2)" ] |
| 544 | assert_clean_index |
| 545 | |
| 546 | rm -rf .git/lfs/objects |
| 547 | |
| 548 | pushd dir1/dir2 |
| 549 | git lfs pull 2>&1 | tee pull.log |
| 550 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 551 | echo >&2 "fatal: expected pull to succeed ..." |
| 552 | exit 1 |
| 553 | fi |
| 554 | grep '"a\.dat": not a regular file' pull.log |
| 555 | grep '"dir1/dir2/dir3/a\.dat": not a regular file' pull.log |
| 556 | popd |
| 557 | |
| 558 | assert_local_object "$contents_oid" 1 |
| 559 | |
| 560 | [ -L "a.dat" ] |
| 561 | [ -L "dir1/dir2/dir3/a.dat" ] |
| 562 | [ -f "link1" ] |
| 563 | [ "$contents_pointer" = "$(cat link1)" ] |
| 564 | [ -f "link2" ] |
| 565 | [ "$contents_pointer" = "$(cat link2)" ] |
| 566 | assert_clean_index |
| 567 | |
| 568 | # test with symlink to directory and dangling symlink |
| 569 | rm -rf .git/lfs/objects |
| 570 | |
| 571 | rm -rf a.dat dir1/dir2/dir3/a.dat ../link* |
| 572 | mkdir ../link1 |
| 573 | ln -s ../link1 a.dat |
| 574 | ln -s ../../../../link2 dir1/dir2/dir3/a.dat |
| 575 | |
| 576 | git lfs pull 2>&1 | tee pull.log |
| 577 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 578 | echo >&2 "fatal: expected pull to succeed ..." |
| 579 | exit 1 |
| 580 | fi |
| 581 | grep '"a\.dat": not a regular file' pull.log |
| 582 | grep '"dir1/dir2/dir3/a\.dat": not a regular file' pull.log |
| 583 | |
| 584 | assert_local_object "$contents_oid" 1 |
| 585 | |
| 586 | [ -L "a.dat" ] |
| 587 | [ -L "dir1/dir2/dir3/a.dat" ] |
| 588 | [ -d "../link1" ] |
| 589 | [ ! -e "../link2" ] |
| 590 | assert_clean_index |
| 591 | |
| 592 | rm -rf .git/lfs/objects |
| 593 | |
| 594 | rm -rf a.dat dir1/dir2/dir3/a.dat link* |
| 595 | mkdir link1 |
| 596 | ln -s link1 a.dat |
| 597 | ln -s ../../../link2 dir1/dir2/dir3/a.dat |
| 598 | |
| 599 | git lfs pull 2>&1 | tee pull.log |
| 600 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 601 | echo >&2 "fatal: expected pull to succeed ..." |
| 602 | exit 1 |
| 603 | fi |
| 604 | grep '"a\.dat": not a regular file' pull.log |
| 605 | grep '"dir1/dir2/dir3/a\.dat": not a regular file' pull.log |
| 606 | |
| 607 | assert_local_object "$contents_oid" 1 |
| 608 | |
| 609 | [ -L "a.dat" ] |
| 610 | [ -L "dir1/dir2/dir3/a.dat" ] |
| 611 | [ -d "link1" ] |
| 612 | [ ! -e "link2" ] |
| 613 | assert_clean_index |
| 614 | |
| 615 | rm -rf .git/lfs/objects |
| 616 | |
| 617 | pushd dir1/dir2 |
| 618 | git lfs pull 2>&1 | tee pull.log |
| 619 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 620 | echo >&2 "fatal: expected pull to succeed ..." |
| 621 | exit 1 |
| 622 | fi |
| 623 | grep '"a\.dat": not a regular file' pull.log |
| 624 | grep '"dir1/dir2/dir3/a\.dat": not a regular file' pull.log |
| 625 | popd |
| 626 | |
| 627 | assert_local_object "$contents_oid" 1 |
| 628 | |
| 629 | [ -L "a.dat" ] |
| 630 | [ -L "dir1/dir2/dir3/a.dat" ] |
| 631 | [ -d "link1" ] |
| 632 | [ ! -e "link2" ] |
| 633 | assert_clean_index |
| 634 | ) |
| 635 | end_test |
| 636 | |
| 637 | # This test applies to case-preserving but case-insensitive filesystems, |
| 638 | # such as APFS and NTFS when in their default configurations. |
| 639 | # On case-sensitive filesystems this test has no particular value and |
| 640 | # should always pass. |
| 641 | begin_test "pull: skip case-based symlink conflicts" |
| 642 | ( |
| 643 | set -e |
| 644 | |
| 645 | skip_if_symlinks_unsupported |
| 646 | |
| 647 | # Only test with Git version 2.20.0 as it introduced detection of |
| 648 | # case-insensitive filesystems to the "git clone" command, which the |
| 649 | # test depends on to determine the filesystem type. |
| 650 | ensure_git_version_isnt "$VERSION_LOWER" "2.20.0" |
| 651 | |
| 652 | reponame="pull-skip-case-symlink-conflicts" |
| 653 | setup_remote_repo "$reponame" |
| 654 | clone_repo "$reponame" "$reponame" |
| 655 | |
| 656 | mkdir dir1 |
| 657 | ln -s ../link1 A.dat |
| 658 | ln -s ../../link2 dir1/a.dat |
| 659 | ln -s ../link3 DIR3 |
| 660 | ln -s ../../link4 dir1/dir2 |
| 661 | |
| 662 | git add A.dat dir1 DIR3 |
| 663 | git commit -m "initial commit" |
| 664 | |
| 665 | rm A.dat dir1/* DIR3 |
| 666 | |
| 667 | echo "*.dat filter=lfs diff=lfs merge=lfs -text" >.gitattributes |
| 668 | |
| 669 | contents="a" |
| 670 | contents_oid="$(calc_oid "$contents")" |
| 671 | mkdir dir3 dir1/DIR2 |
| 672 | printf "%s" "$contents" >a.dat |
| 673 | printf "%s" "$contents" >dir1/A.dat |
| 674 | printf "%s" "$contents" >dir3/a.dat |
| 675 | printf "%s" "$contents" >dir1/DIR2/a.dat |
| 676 | |
| 677 | git -c core.ignoreCase=false add .gitattributes a.dat dir1/A.dat \ |
| 678 | dir3/a.dat dir1/DIR2/a.dat |
| 679 | git commit -m "case-conflicting commit" |
| 680 | |
| 681 | git push origin main |
| 682 | assert_server_object "$reponame" "$contents_oid" |
| 683 | |
| 684 | cd .. |
| 685 | GIT_LFS_SKIP_SMUDGE=1 git clone "$GITSERVER/$reponame" "${reponame}-assert" 2>&1 | tee clone.log |
| 686 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 687 | echo >&2 "fatal: expected clone to succeed ..." |
| 688 | exit 1 |
| 689 | fi |
| 690 | collision="$(grep -c "collided" clone.log)" || true |
| 691 | |
| 692 | cd "${reponame}-assert" |
| 693 | refute_local_object "$contents_oid" 1 |
| 694 | |
| 695 | rm -rf *.dat dir1 *3 ../link* |
| 696 | mkdir ../link3 ../link4 |
| 697 | |
| 698 | git lfs pull |
| 699 | |
| 700 | assert_local_object "$contents_oid" 1 |
| 701 | |
| 702 | [ -f "a.dat" ] |
| 703 | [ "$contents" = "$(cat "a.dat")" ] |
| 704 | [ -f "dir1/A.dat" ] |
| 705 | [ "$contents" = "$(cat "dir1/A.dat")" ] |
| 706 | [ -f "dir3/a.dat" ] |
| 707 | [ "$contents" = "$(cat "dir3/a.dat")" ] |
| 708 | [ -f "dir1/DIR2/a.dat" ] |
| 709 | [ "$contents" = "$(cat "dir1/DIR2/a.dat")" ] |
| 710 | [ ! -e "../link1" ] |
| 711 | [ ! -e "../link2" ] |
| 712 | [ ! -e "../link3/a.dat" ] |
| 713 | [ ! -e "../link4/a.dat" ] |
| 714 | assert_clean_index |
| 715 | |
| 716 | rm -rf a.dat dir1/A.dat dir3 dir1/DIR2 |
| 717 | git checkout -- A.dat dir1/a.dat DIR3 dir1/dir2 |
| 718 | |
| 719 | git lfs pull 2>&1 | tee pull.log |
| 720 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 721 | echo >&2 "fatal: expected pull to succeed ..." |
| 722 | exit 1 |
| 723 | fi |
| 724 | if [ "$collision" -gt "0" ]; then |
| 725 | # case-insensitive filesystem |
| 726 | grep '"a\.dat": not a regular file' pull.log |
| 727 | grep '"dir1/A\.dat": not a regular file' pull.log |
| 728 | grep '"dir3/a\.dat": not a directory' pull.log |
| 729 | grep '"dir1/DIR2/a\.dat": not a directory' pull.log |
| 730 | [ 0 -eq "$(grep -c "is beyond a symbolic link" pull.log)" ] |
| 731 | fi |
| 732 | |
| 733 | if [ "$collision" -eq "0" ]; then |
| 734 | # case-sensitive filesystem |
| 735 | [ -f "a.dat" ] |
| 736 | [ "$contents" = "$(cat "a.dat")" ] |
| 737 | [ -f "dir1/A.dat" ] |
| 738 | [ "$contents" = "$(cat "dir1/A.dat")" ] |
| 739 | [ -f "dir3/a.dat" ] |
| 740 | [ "$contents" = "$(cat "dir3/a.dat")" ] |
| 741 | [ -f "dir1/DIR2/a.dat" ] |
| 742 | [ "$contents" = "$(cat "dir1/DIR2/a.dat")" ] |
| 743 | else |
| 744 | # case-insensitive filesystem |
| 745 | [ -L "a.dat" ] |
| 746 | [ -L "dir1/A.dat" ] |
| 747 | [ -L "dir3" ] |
| 748 | [ -L "dir1/DIR2" ] |
| 749 | fi |
| 750 | [ ! -e "../link1" ] |
| 751 | [ ! -e "../link2" ] |
| 752 | [ ! -e "../link3/a.dat" ] |
| 753 | [ ! -e "../link4/a.dat" ] |
| 754 | assert_clean_index |
| 755 | ) |
| 756 | end_test |
| 757 | |
| 758 | begin_test "pull: skip changed files" |
| 759 | ( |
| 760 | set -e |
| 761 | |
| 762 | reponame="pull-skip-changed-files" |
| 763 | setup_remote_repo "$reponame" |
| 764 | clone_repo "$reponame" "$reponame" |
| 765 | |
| 766 | git lfs track "*.dat" |
| 767 | |
| 768 | contents="a" |
| 769 | contents_oid="$(calc_oid "$contents")" |
| 770 | printf "%s" "$contents" >a.dat |
| 771 | |
| 772 | git add .gitattributes a.dat |
| 773 | git commit -m "initial commit" |
| 774 | |
| 775 | git push origin main |
| 776 | assert_server_object "$reponame" "$contents_oid" |
| 777 | |
| 778 | cd .. |
| 779 | GIT_LFS_SKIP_SMUDGE=1 git clone "$GITSERVER/$reponame" "${reponame}-assert" |
| 780 | |
| 781 | cd "${reponame}-assert" |
| 782 | refute_local_object "$contents_oid" 1 |
| 783 | |
| 784 | contents_new="$contents +extra" |
| 785 | printf "%s" "$contents_new" >a.dat |
| 786 | |
| 787 | git lfs pull |
| 788 | assert_local_object "$contents_oid" 1 |
| 789 | |
| 790 | [ "$contents_new" = "$(cat a.dat)" ] |
| 791 | assert_clean_index |
| 792 | |
| 793 | rm a.dat |
| 794 | mkdir a.dat |
| 795 | |
| 796 | rm -rf .git/lfs/objects |
| 797 | git lfs pull |
| 798 | assert_local_object "$contents_oid" 1 |
| 799 | |
| 800 | [ -d "a.dat" ] |
| 801 | assert_clean_index |
| 802 | |
| 803 | rm -rf .git/lfs/objects |
| 804 | |
| 805 | pushd a.dat |
| 806 | git lfs pull |
| 807 | popd |
| 808 | |
| 809 | assert_local_object "$contents_oid" 1 |
| 810 | |
| 811 | [ -d "a.dat" ] |
| 812 | assert_clean_index |
| 813 | ) |
| 814 | end_test |
| 815 | |
| 816 | begin_test "pull: break hard links to existing files" |
| 817 | ( |
| 818 | set -e |
| 819 | |
| 820 | reponame="pull-break-file-hardlinks" |
| 821 | setup_remote_repo "$reponame" |
| 822 | clone_repo "$reponame" "$reponame" |
| 823 | |
| 824 | git lfs track "*.dat" |
| 825 | |
| 826 | contents="a" |
| 827 | contents_oid="$(calc_oid "$contents")" |
| 828 | mkdir -p dir1/dir2/dir3 |
| 829 | printf "%s" "$contents" >a.dat |
| 830 | printf "%s" "$contents" >dir1/dir2/dir3/a.dat |
| 831 | |
| 832 | git add .gitattributes a.dat dir1 |
| 833 | git commit -m "initial commit" |
| 834 | |
| 835 | git push origin main |
| 836 | assert_server_object "$reponame" "$contents_oid" |
| 837 | |
| 838 | cd .. |
| 839 | GIT_LFS_SKIP_SMUDGE=1 git clone "$GITSERVER/$reponame" "${reponame}-assert" |
| 840 | |
| 841 | cd "${reponame}-assert" |
| 842 | refute_local_object "$contents_oid" 1 |
| 843 | |
| 844 | rm -f a.dat dir1/dir2/dir3/a.dat ../link |
| 845 | pointer="$(git cat-file -p ":a.dat")" |
| 846 | echo "$pointer" >../link |
| 847 | ln ../link a.dat |
| 848 | ln ../link dir1/dir2/dir3/a.dat |
| 849 | |
| 850 | git lfs pull |
| 851 | assert_local_object "$contents_oid" 1 |
| 852 | |
| 853 | [ "$contents" = "$(cat a.dat)" ] |
| 854 | [ "$contents" = "$(cat dir1/dir2/dir3/a.dat)" ] |
| 855 | [ "$pointer" = "$(cat ../link)" ] |
| 856 | assert_clean_status |
| 857 | |
| 858 | rm a.dat dir1/dir2/dir3/a.dat |
| 859 | ln ../link a.dat |
| 860 | ln ../link dir1/dir2/dir3/a.dat |
| 861 | |
| 862 | rm -rf .git/lfs/objects |
| 863 | |
| 864 | pushd dir1/dir2 |
| 865 | git lfs pull |
| 866 | popd |
| 867 | |
| 868 | assert_local_object "$contents_oid" 1 |
| 869 | |
| 870 | [ "$contents" = "$(cat a.dat)" ] |
| 871 | [ "$contents" = "$(cat dir1/dir2/dir3/a.dat)" ] |
| 872 | [ "$pointer" = "$(cat ../link)" ] |
| 873 | assert_clean_status |
| 874 | ) |
| 875 | end_test |
| 876 | |
| 877 | begin_test "pull without clean filter" |
| 878 | ( |
| 879 | set -e |
| 880 | |
| 881 | GIT_LFS_SKIP_SMUDGE=1 git clone $GITSERVER/t-pull no-clean |
| 882 | cd no-clean |
| 883 | git lfs uninstall |
| 884 | git config --list > config.txt |
| 885 | grep "filter.lfs.clean" config.txt && { |
| 886 | echo "clean filter still configured:" |
| 887 | cat config.txt |
| 888 | exit 1 |
| 889 | } |
| 890 | |
| 891 | contents="a" |
| 892 | contents_oid=$(calc_oid "$contents") |
| 893 | |
| 894 | # LFS object not downloaded, pointer in working directory |
| 895 | grep "$contents_oid" a.dat || { |
| 896 | echo "a.dat not $contents_oid" |
| 897 | ls -al |
| 898 | cat a.dat |
| 899 | exit 1 |
| 900 | } |
| 901 | assert_local_object "$contents_oid" |
| 902 | |
| 903 | git lfs pull | tee pull.txt |
| 904 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 905 | echo >&2 "fatal: expected pull to succeed ..." |
| 906 | exit 1 |
| 907 | fi |
| 908 | grep "Git LFS is not installed" pull.txt |
| 909 | echo "pulled!" |
| 910 | |
| 911 | # LFS object downloaded, pointer unchanged |
| 912 | grep "$contents_oid" a.dat || { |
| 913 | echo "a.dat not $contents_oid" |
| 914 | ls -al |
| 915 | cat a.dat |
| 916 | exit 1 |
| 917 | } |
| 918 | assert_local_object "$contents_oid" 1 |
| 919 | ) |
| 920 | end_test |
| 921 | |
| 922 | begin_test "pull with raw remote url" |
| 923 | ( |
| 924 | set -e |
| 925 | mkdir raw |
| 926 | cd raw |
| 927 | git init |
| 928 | git lfs install --local --skip-smudge |
| 929 | |
| 930 | git remote add origin $GITSERVER/t-pull |
| 931 | git pull origin main |
| 932 | |
| 933 | contents="a" |
| 934 | contents_oid=$(calc_oid "$contents") |
| 935 | |
| 936 | # LFS object not downloaded, pointer in working directory |
| 937 | refute_local_object "$contents_oid" |
| 938 | grep "$contents_oid" a.dat |
| 939 | |
| 940 | git lfs pull "$GITSERVER/t-pull" |
| 941 | echo "pulled!" |
| 942 | |
| 943 | # LFS object downloaded and in working directory |
| 944 | assert_local_object "$contents_oid" 1 |
| 945 | [ 0 -eq "$(grep -c "$contents_oid" a.dat)" ] |
| 946 | [ "a" = "$(cat a.dat)" ] |
| 947 | ) |
| 948 | end_test |
| 949 | |
| 950 | begin_test "pull with multiple remotes" |
| 951 | ( |
| 952 | set -e |
| 953 | mkdir multiple |
| 954 | cd multiple |
| 955 | git init |
| 956 | git lfs install --local --skip-smudge |
| 957 | |
| 958 | git remote add origin "$GITSERVER/t-pull" |
| 959 | git remote add bad-remote "invalid-url" |
| 960 | git pull origin main |
| 961 | |
| 962 | contents="a" |
| 963 | contents_oid=$(calc_oid "$contents") |
| 964 | |
| 965 | # LFS object not downloaded, pointer in working directory |
| 966 | refute_local_object "$contents_oid" |
| 967 | grep "$contents_oid" a.dat |
| 968 | |
| 969 | # pull should default to origin instead of bad-remote |
| 970 | git lfs pull |
| 971 | echo "pulled!" |
| 972 | |
| 973 | # LFS object downloaded and in working directory |
| 974 | assert_local_object "$contents_oid" 1 |
| 975 | [ 0 -eq "$(grep -c "$contents_oid" a.dat)" ] |
| 976 | [ "a" = "$(cat a.dat)" ] |
| 977 | ) |
| 978 | end_test |
| 979 | |
| 980 | begin_test "pull with invalid insteadof" |
| 981 | ( |
| 982 | set -e |
| 983 | mkdir insteadof |
| 984 | cd insteadof |
| 985 | git init |
| 986 | git lfs install --local --skip-smudge |
| 987 | |
| 988 | git remote add origin "$GITSERVER/t-pull" |
| 989 | git pull origin main |
| 990 | |
| 991 | # set insteadOf to rewrite the href of downloading LFS object. |
| 992 | git config url."$GITSERVER/storage/invalid".insteadOf "$GITSERVER/storage/" |
| 993 | # Enable href rewriting explicitly. |
| 994 | git config lfs.transfer.enablehrefrewrite true |
| 995 | |
| 996 | set +e |
| 997 | git lfs pull > pull.log 2>&1 |
| 998 | res=$? |
| 999 | |
| 1000 | set -e |
| 1001 | [ "$res" = "2" ] |
| 1002 | |
| 1003 | # check rewritten href is used to download LFS object. |
| 1004 | grep "LFS: Repository or object not found: $GITSERVER/storage/invalid" pull.log |
| 1005 | |
| 1006 | # lfs-pull succeed after unsetting enableHrefRewrite config |
| 1007 | git config --unset lfs.transfer.enablehrefrewrite |
| 1008 | git lfs pull |
| 1009 | ) |
| 1010 | end_test |
| 1011 | |
| 1012 | begin_test "pull with merge conflict" |
| 1013 | ( |
| 1014 | set -e |
| 1015 | git init pull-merge-conflict |
| 1016 | cd pull-merge-conflict |
| 1017 | |
| 1018 | git lfs track "*.bin" |
| 1019 | git add . |
| 1020 | git commit -m 'gitattributes' |
| 1021 | printf abc > abc.bin |
| 1022 | git add . |
| 1023 | git commit -m 'abc' |
| 1024 | |
| 1025 | git checkout -b def |
| 1026 | printf def > abc.bin |
| 1027 | git add . |
| 1028 | git commit -m 'def' |
| 1029 | |
| 1030 | git checkout main |
| 1031 | printf ghi > abc.bin |
| 1032 | git add . |
| 1033 | git commit -m 'ghi' |
| 1034 | |
| 1035 | # This will exit nonzero because of the merge conflict. |
| 1036 | GIT_LFS_SKIP_SMUDGE=1 git merge def || true |
| 1037 | git lfs pull > pull.log 2>&1 |
| 1038 | [ ! -s pull.log ] |
| 1039 | ) |
| 1040 | end_test |
| 1041 | |
| 1042 | begin_test "pull: with missing object" |
| 1043 | ( |
| 1044 | set -e |
| 1045 | |
| 1046 | # this clone is setup in the first test in this file |
| 1047 | cd clone |
| 1048 | rm -rf .git/lfs/objects |
| 1049 | rm a.dat |
| 1050 | |
| 1051 | contents_oid=$(calc_oid "a") |
| 1052 | reponame="$(basename "$0" ".sh")" |
| 1053 | delete_server_object "$reponame" "$contents_oid" |
| 1054 | refute_server_object "$reponame" "$contents_oid" |
| 1055 | |
| 1056 | # should return non-zero, but should also download all the other valid files too |
| 1057 | git config branch.main.remote origin |
| 1058 | git config branch.main.merge refs/heads/main |
| 1059 | git lfs pull 2>&1 | tee pull.log |
| 1060 | pull_exit="${PIPESTATUS[0]}" |
| 1061 | [ "$pull_exit" != "0" ] |
| 1062 | |
| 1063 | grep "$contents_oid does not exist" pull.log |
| 1064 | |
| 1065 | contents2_oid=$(calc_oid "A") |
| 1066 | assert_local_object "$contents2_oid" 1 |
| 1067 | refute_local_object "$contents_oid" |
| 1068 | ) |
| 1069 | end_test |
| 1070 | |
| 1071 | begin_test "pull: outside git repository" |
| 1072 | ( |
| 1073 | set +e |
| 1074 | git lfs pull 2>&1 > pull.log |
| 1075 | res=$? |
| 1076 | |
| 1077 | set -e |
| 1078 | if [ "$res" = "0" ]; then |
| 1079 | echo "Passes because $GIT_LFS_TEST_DIR is unset." |
| 1080 | exit 0 |
| 1081 | fi |
| 1082 | [ "$res" = "128" ] |
| 1083 | grep "Not in a Git repository" pull.log |
| 1084 | ) |
| 1085 | end_test |
| 1086 | |
| 1087 | begin_test "pull: read-only directory" |
| 1088 | ( |
| 1089 | set -e |
| 1090 | |
| 1091 | skip_if_root_or_admin "$test_description" |
| 1092 | |
| 1093 | reponame="pull-read-only" |
| 1094 | setup_remote_repo "$reponame" |
| 1095 | clone_repo "$reponame" "$reponame" |
| 1096 | |
| 1097 | git lfs track "*.bin" |
| 1098 | |
| 1099 | contents="a" |
| 1100 | contents_oid=$(calc_oid "$contents") |
| 1101 | mkdir dir |
| 1102 | printf "%s" "$contents" > dir/a.bin |
| 1103 | |
| 1104 | git add .gitattributes dir/a.bin |
| 1105 | git commit -m "add dir/a.bin" |
| 1106 | |
| 1107 | git push origin main |
| 1108 | |
| 1109 | assert_server_object "$reponame" "$contents_oid" |
| 1110 | |
| 1111 | rm dir/a.bin |
| 1112 | delete_local_object "$contents_oid" |
| 1113 | |
| 1114 | if [ "$IS_WINDOWS" -eq 1 ]; then |
| 1115 | icacls dir /inheritance:r |
| 1116 | icacls dir /grant:r Everyone:R |
| 1117 | else |
| 1118 | chmod a-w dir |
| 1119 | fi |
| 1120 | git lfs pull 2>&1 | tee pull.log |
| 1121 | # Note that although the pull command should log an error, at present |
| 1122 | # we still expect a zero exit code. |
| 1123 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 1124 | echo >&2 "fatal: expected 'git lfs pull' to succeed ..." |
| 1125 | exit 1 |
| 1126 | fi |
| 1127 | |
| 1128 | assert_local_object "$contents_oid" 1 |
| 1129 | |
| 1130 | [ ! -e dir/a.bin ] |
| 1131 | |
| 1132 | grep 'could not check out "dir/a.bin"' pull.log |
| 1133 | grep 'could not create working directory file' pull.log |
| 1134 | grep 'permission denied' pull.log |
| 1135 | ) |
| 1136 | end_test |
| 1137 | |
| 1138 | begin_test "pull: read-only file" |
| 1139 | ( |
| 1140 | set -e |
| 1141 | |
| 1142 | reponame="pull-locked" |
| 1143 | filename="a.txt" |
| 1144 | |
| 1145 | setup_remote_repo_with_file "$reponame" "$filename" |
| 1146 | contents_oid="$(calc_oid_file "$filename")" |
| 1147 | |
| 1148 | pushd "$TRASHDIR" > /dev/null |
| 1149 | GIT_LFS_SKIP_SMUDGE=1 clone_repo "$reponame" "${reponame}-assert" |
| 1150 | |
| 1151 | chmod a-w "$filename" |
| 1152 | |
| 1153 | refute_file_writeable "$filename" |
| 1154 | assert_pointer "refs/heads/main" "$filename" "$contents_oid" 6 |
| 1155 | |
| 1156 | git lfs pull |
| 1157 | |
| 1158 | refute_file_writeable "$filename" |
| 1159 | [ "$filename" = "$(cat "$filename")" ] |
| 1160 | popd > /dev/null |
| 1161 | ) |
| 1162 | end_test |
| 1163 | |
| 1164 | begin_test "pull with empty file doesn't modify mtime" |
| 1165 | ( |
| 1166 | set -e |
| 1167 | git init pull-empty-file |
| 1168 | cd pull-empty-file |
| 1169 | |
| 1170 | git lfs track "*.bin" |
| 1171 | git add . |
| 1172 | git commit -m 'gitattributes' |
| 1173 | printf abc > abc.bin |
| 1174 | git add . |
| 1175 | git commit -m 'abc' |
| 1176 | |
| 1177 | touch foo.bin |
| 1178 | lfstest-nanomtime foo.bin >foo.mtime |
| 1179 | |
| 1180 | # This isn't necessary, but it takes a few cycles to make sure that our |
| 1181 | # timestamp changes. |
| 1182 | git add foo.bin |
| 1183 | git commit -m 'foo' |
| 1184 | |
| 1185 | git lfs pull |
| 1186 | lfstest-nanomtime foo.bin >foo.mtime2 |
| 1187 | diff -u foo.mtime foo.mtime2 |
| 1188 | ) |
| 1189 | end_test |
| 1190 | |
| 1191 | begin_test "pull: bare repository" |
| 1192 | ( |
| 1193 | set -e |
| 1194 | |
| 1195 | reponame="pull-bare" |
| 1196 | setup_remote_repo "$reponame" |
| 1197 | clone_repo "$reponame" "$reponame" |
| 1198 | |
| 1199 | git lfs track "*.dat" |
| 1200 | |
| 1201 | contents="a" |
| 1202 | contents_oid="$(calc_oid "$contents")" |
| 1203 | printf "%s" "$contents" >a.dat |
| 1204 | |
| 1205 | # The "git lfs pull" command should never check out files in a bare |
| 1206 | # repository, either into a directory within the repository or one |
| 1207 | # outside it. To verify this, we add a Git LFS pointer file whose path |
| 1208 | # inside the repository is one which, if it were instead treated as an |
| 1209 | # absolute filesystem path, corresponds to a writable directory. |
| 1210 | # The "git lfs pull" command should not check out files into either |
| 1211 | # this external directory or the bare repository. |
| 1212 | external_dir="$TRASHDIR/${reponame}-external" |
| 1213 | internal_dir="$(printf "%s" "$external_dir" | sed 's/^\/*//')" |
| 1214 | mkdir -p "$internal_dir" |
| 1215 | printf "%s" "$contents" >"$internal_dir/a.dat" |
| 1216 | |
| 1217 | git add .gitattributes a.dat "$internal_dir/a.dat" |
| 1218 | git commit -m "initial commit" |
| 1219 | |
| 1220 | git push origin main |
| 1221 | assert_server_object "$reponame" "$contents_oid" |
| 1222 | |
| 1223 | cd .. |
| 1224 | git clone --bare "$GITSERVER/$reponame" "${reponame}-assert" |
| 1225 | |
| 1226 | cd "${reponame}-assert" |
| 1227 | [ ! -e lfs ] |
| 1228 | refute_local_object "$contents_oid" |
| 1229 | |
| 1230 | git lfs pull 2>&1 | tee pull.log |
| 1231 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 1232 | echo >&2 "fatal: expected pull to succeed ..." |
| 1233 | exit 1 |
| 1234 | fi |
| 1235 | |
| 1236 | # When Git version 2.42.0 or higher is available, the "git lfs pull" |
| 1237 | # command will use the "git ls-files" command rather than the |
| 1238 | # "git ls-tree" command to list files. By default a bare repository |
| 1239 | # lacks an index, so we expect no Git LFS objects to be fetched when |
| 1240 | # "git ls-files" is used because Git v2.42.0 or higher is available. |
| 1241 | gitversion="$(git version | cut -d" " -f3)" |
| 1242 | set +e |
| 1243 | compare_version "$gitversion" '2.42.0' |
| 1244 | result=$? |
| 1245 | set -e |
| 1246 | if [ "$result" -eq "$VERSION_LOWER" ]; then |
| 1247 | grep "Downloading LFS objects" pull.log |
| 1248 | |
| 1249 | assert_local_object "$contents_oid" 1 |
| 1250 | else |
| 1251 | grep -q "Downloading LFS objects" pull.log && exit 1 |
| 1252 | |
| 1253 | refute_local_object "$contents_oid" |
| 1254 | fi |
| 1255 | |
| 1256 | [ ! -e "a.dat" ] |
| 1257 | [ ! -e "$internal_dir/a.dat" ] |
| 1258 | [ ! -e "$external_dir/a.dat" ] |
| 1259 | |
| 1260 | rm -rf lfs/objects |
| 1261 | refute_local_object "$contents_oid" |
| 1262 | |
| 1263 | # When Git version 2.42.0 or higher is available, the "git lfs pull" |
| 1264 | # command will use the "git ls-files" command rather than the |
| 1265 | # "git ls-tree" command to list files. By default a bare repository |
| 1266 | # lacks an index, so we expect no Git LFS objects to be fetched when |
| 1267 | # "git ls-files" is used because Git v2.42.0 or higher is available. |
| 1268 | # |
| 1269 | # Therefore to verify that the "git lfs pull" command never checks out |
| 1270 | # files in a bare repository, we first populate the index with Git LFS |
| 1271 | # pointer files and then retry the command. |
| 1272 | contents_git_oid="$(git ls-tree HEAD a.dat | awk '{ print $3 }')" |
| 1273 | git update-index --add --cacheinfo 100644 "$contents_git_oid" a.dat |
| 1274 | git update-index --add --cacheinfo 100644 "$contents_git_oid" "$internal_dir/a.dat" |
| 1275 | |
| 1276 | # When Git version 2.42.0 or higher is available, the "git lfs pull" |
| 1277 | # command will use the "git ls-files" command rather than the |
| 1278 | # "git ls-tree" command to list files, and does so by passing an |
| 1279 | # "attr:filter=lfs" pathspec to the "git ls-files" command so it only |
| 1280 | # lists files which match that filter attribute. |
| 1281 | # |
| 1282 | # In a bare repository, however, the "git ls-files" command will not read |
| 1283 | # attributes from ".gitattributes" files in the index, so by default it |
| 1284 | # will not list any Git LFS pointer files even if those files and the |
| 1285 | # corresponding ".gitattributes" files have been added to the index and |
| 1286 | # the pointer files would otherwise match the "attr:filter=lfs" pathspec. |
| 1287 | # |
| 1288 | # Therefore, instead of adding the ".gitattributes" file to the index, we |
| 1289 | # copy it to "info/attributes" so that the pathspec filter will match our |
| 1290 | # pointer file index entries and they will be listed by the "git ls-files" |
| 1291 | # command. This allows us to verify that with Git v2.42.0 or higher, the |
| 1292 | # "git lfs pull" command will fetch the objects for these pointer files |
| 1293 | # in the index when the command is run in a bare repository. |
| 1294 | # |
| 1295 | # Note that with older versions of Git, the "git lfs pull" command will |
| 1296 | # use the "git ls-tree" command to list the files in the tree referenced |
| 1297 | # by HEAD. The Git LFS objects for any well-formed pointer files found in |
| 1298 | # that list will then be fetched (unless local copies already exist), |
| 1299 | # regardless of whether the pointer files actually match a "filter=lfs" |
| 1300 | # attribute in any ".gitattributes" file in the index, the tree |
| 1301 | # referenced by HEAD, or the current work tree. |
| 1302 | if [ "$result" -ne "$VERSION_LOWER" ]; then |
| 1303 | mkdir -p info |
| 1304 | git show HEAD:.gitattributes >info/attributes |
| 1305 | fi |
| 1306 | |
| 1307 | git lfs pull 2>&1 | tee pull.log |
| 1308 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 1309 | echo >&2 "fatal: expected pull to succeed ..." |
| 1310 | exit 1 |
| 1311 | fi |
| 1312 | grep "Downloading LFS objects" pull.log |
| 1313 | |
| 1314 | assert_local_object "$contents_oid" 1 |
| 1315 | |
| 1316 | [ ! -e "a.dat" ] |
| 1317 | [ ! -e "$internal_dir/a.dat" ] |
| 1318 | [ ! -e "$external_dir/a.dat" ] |
| 1319 | ) |
| 1320 | end_test |
| 1321 | |
| 1322 | begin_test "pull with partial clone and sparse checkout and index" |
| 1323 | ( |
| 1324 | set -e |
| 1325 | |
| 1326 | # Only test with Git version 2.25.0 as it introduced the |
| 1327 | # "git sparse-checkout" command. (Note that this test also requires |
| 1328 | # that the "git rev-list" command support the "tree:0" filter, which |
| 1329 | # was introduced with Git version 2.20.0.) |
| 1330 | ensure_git_version_isnt "$VERSION_LOWER" "2.25.0" |
| 1331 | |
| 1332 | reponame="pull-sparse" |
| 1333 | setup_remote_repo "$reponame" |
| 1334 | clone_repo "$reponame" "$reponame" |
| 1335 | |
| 1336 | git lfs track "*.dat" |
| 1337 | |
| 1338 | contents1="a" |
| 1339 | contents1_oid=$(calc_oid "$contents1") |
| 1340 | contents2="b" |
| 1341 | contents2_oid=$(calc_oid "$contents2") |
| 1342 | contents3="c" |
| 1343 | contents3_oid=$(calc_oid "$contents3") |
| 1344 | |
| 1345 | mkdir in-dir out-dir |
| 1346 | printf "%s" "$contents1" >a.dat |
| 1347 | printf "%s" "$contents2" >in-dir/b.dat |
| 1348 | printf "%s" "$contents3" >out-dir/c.dat |
| 1349 | git add . |
| 1350 | git commit -m "add files" |
| 1351 | |
| 1352 | git push origin main |
| 1353 | |
| 1354 | assert_server_object "$reponame" "$contents1_oid" |
| 1355 | assert_server_object "$reponame" "$contents2_oid" |
| 1356 | assert_server_object "$reponame" "$contents3_oid" |
| 1357 | |
| 1358 | # Create a partial clone with a cone-mode sparse checkout of one directory |
| 1359 | # and a sparse index, which is important because otherwise the "git ls-files" |
| 1360 | # command ignores the --sparse option and lists all Git LFS files. |
| 1361 | cd .. |
| 1362 | git clone --filter=tree:0 --depth=1 --no-checkout \ |
| 1363 | "$GITSERVER/$reponame" "${reponame}-partial" |
| 1364 | |
| 1365 | cd "${reponame}-partial" |
| 1366 | git sparse-checkout init --cone --sparse-index |
| 1367 | git sparse-checkout set "in-dir" |
| 1368 | git checkout main |
| 1369 | |
| 1370 | [ -d "in-dir" ] |
| 1371 | [ ! -e "out-dir" ] |
| 1372 | |
| 1373 | assert_local_object "$contents1_oid" 1 |
| 1374 | assert_local_object "$contents2_oid" 1 |
| 1375 | refute_local_object "$contents3_oid" |
| 1376 | |
| 1377 | git lfs pull 2>&1 | tee pull.log |
| 1378 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 1379 | echo >&2 "fatal: expected pull to succeed ..." |
| 1380 | exit 1 |
| 1381 | fi |
| 1382 | |
| 1383 | # When Git version 2.42.0 or higher is available, the "git lfs pull" |
| 1384 | # command will use the "git ls-files" command rather than the |
| 1385 | # "git ls-tree" command to list files. Git v2.42.0 introduced support |
| 1386 | # in the "git ls-files" command for the "objecttype" format option and |
| 1387 | # so Git LFS can use this command to avoid pulling objects outside |
| 1388 | # the sparse cone. Otherwise, all Git LFS objects will be pulled. |
| 1389 | gitversion="$(git version | cut -d" " -f3)" |
| 1390 | set +e |
| 1391 | compare_version "$gitversion" '2.42.0' |
| 1392 | result=$? |
| 1393 | set -e |
| 1394 | if [ "$result" -eq "$VERSION_LOWER" ]; then |
| 1395 | grep "Downloading LFS objects" pull.log |
| 1396 | |
| 1397 | [ -f "out-dir/c.dat" ] |
| 1398 | [ "$contents3" = "$(cat "out-dir/c.dat")" ] |
| 1399 | |
| 1400 | assert_local_object "$contents3_oid" 1 |
| 1401 | else |
| 1402 | grep -q "Downloading LFS objects" pull.log && exit 1 |
| 1403 | |
| 1404 | [ ! -e "out-dir" ] |
| 1405 | |
| 1406 | refute_local_object "$contents3_oid" |
| 1407 | fi |
| 1408 | ) |
| 1409 | end_test |
| 1410 | |
| 1411 | begin_test "pull: pointer extension" |
| 1412 | ( |
| 1413 | set -e |
| 1414 | |
| 1415 | reponame="pull-pointer-extension" |
| 1416 | setup_remote_repo "$reponame" |
| 1417 | clone_repo "$reponame" "$reponame" |
| 1418 | |
| 1419 | git lfs track "*.dat" |
| 1420 | |
| 1421 | setup_case_inverter_extension |
| 1422 | |
| 1423 | contents="abc" |
| 1424 | inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")" |
| 1425 | mkdir dir1 |
| 1426 | printf "%s" "$contents" >dir1/abc.dat |
| 1427 | |
| 1428 | git add .gitattributes dir1 |
| 1429 | git commit -m "initial commit" |
| 1430 | |
| 1431 | git push origin main |
| 1432 | assert_server_object "$reponame" "$inverted_contents_oid" |
| 1433 | |
| 1434 | cd .. |
| 1435 | GIT_LFS_SKIP_SMUDGE=1 git clone "$GITSERVER/$reponame" "${reponame}-assert" |
| 1436 | |
| 1437 | cd "${reponame}-assert" |
| 1438 | refute_local_object "$inverted_contents_oid" |
| 1439 | |
| 1440 | setup_case_inverter_extension |
| 1441 | |
| 1442 | rm -rf dir1 "$LFSTEST_EXT_LOG" |
| 1443 | git lfs pull |
| 1444 | |
| 1445 | assert_local_object "$inverted_contents_oid" 3 |
| 1446 | |
| 1447 | [ "$contents" = "$(cat "dir1/abc.dat")" ] |
| 1448 | grep "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG" |
| 1449 | |
| 1450 | rm -rf .git/lfs/objects |
| 1451 | |
| 1452 | rm -rf dir1 "$LFSTEST_EXT_LOG" |
| 1453 | mkdir dir2 |
| 1454 | |
| 1455 | pushd dir2 |
| 1456 | git lfs pull |
| 1457 | popd |
| 1458 | |
| 1459 | [ "$contents" = "$(cat "dir1/abc.dat")" ] |
| 1460 | grep "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG" |
| 1461 | |
| 1462 | assert_local_object "$inverted_contents_oid" 3 |
| 1463 | ) |
| 1464 | end_test |