| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "checkout" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="$(basename "$0" ".sh")" |
| 10 | setup_remote_repo "$reponame" |
| 11 | |
| 12 | clone_repo "$reponame" repo |
| 13 | rm -f clone.log |
| 14 | |
| 15 | git lfs track "*.dat" 2>&1 | tee track.log |
| 16 | grep "Tracking \"\*.dat\"" track.log |
| 17 | rm -f track.log |
| 18 | |
| 19 | contents="something something" |
| 20 | contentsize=19 |
| 21 | contents_oid=$(calc_oid "$contents") |
| 22 | |
| 23 | # Same content everywhere is ok, just one object in lfs db |
| 24 | printf "%s" "$contents" > file1.dat |
| 25 | printf "%s" "$contents" > file2.dat |
| 26 | printf "%s" "$contents" > file3.dat |
| 27 | mkdir -p folder1 folder2/folder3/folder4 |
| 28 | printf "%s" "$contents" > folder1/nested.dat |
| 29 | printf "%s" "$contents" > folder2/folder3/folder4/nested.dat |
| 30 | git add file1.dat file2.dat file3.dat folder1 folder2 |
| 31 | git add .gitattributes |
| 32 | git commit -m "add files" |
| 33 | |
| 34 | [ "$contents" = "$(cat file1.dat)" ] |
| 35 | [ "$contents" = "$(cat file2.dat)" ] |
| 36 | [ "$contents" = "$(cat file3.dat)" ] |
| 37 | [ "$contents" = "$(cat folder1/nested.dat)" ] |
| 38 | [ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ] |
| 39 | |
| 40 | assert_pointer "main" "file1.dat" "$contents_oid" $contentsize |
| 41 | |
| 42 | # Remove the working directory |
| 43 | rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2 |
| 44 | |
| 45 | echo "checkout should replace all" |
| 46 | GIT_TRACE=1 git lfs checkout 2>&1 | tee checkout.log |
| 47 | [ "$contents" = "$(cat file1.dat)" ] |
| 48 | [ "$contents" = "$(cat file2.dat)" ] |
| 49 | [ "$contents" = "$(cat file3.dat)" ] |
| 50 | [ "$contents" = "$(cat folder1/nested.dat)" ] |
| 51 | [ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ] |
| 52 | grep "Checking out LFS objects: 100% (5/5), 95 B" checkout.log |
| 53 | grep 'accepting "file1.dat"' checkout.log |
| 54 | grep 'rejecting "file1.dat"' checkout.log && exit 1 |
| 55 | rm -f checkout.log |
| 56 | assert_clean_status |
| 57 | |
| 58 | git rm file1.dat |
| 59 | |
| 60 | echo "checkout should skip replacing files deleted in index" |
| 61 | git lfs checkout |
| 62 | [ ! -f file1.dat ] |
| 63 | assert_clean_worktree_with_exceptions "file1\.dat" |
| 64 | |
| 65 | git reset --hard |
| 66 | |
| 67 | # Remove the working directory |
| 68 | rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2 |
| 69 | |
| 70 | echo "checkout with filters" |
| 71 | git lfs checkout file2.dat |
| 72 | [ "$contents" = "$(cat file2.dat)" ] |
| 73 | [ ! -f file1.dat ] |
| 74 | [ ! -f file3.dat ] |
| 75 | [ ! -f folder1/nested.dat ] |
| 76 | [ ! -e folder2 ] |
| 77 | assert_clean_worktree_with_exceptions "(file[13]|nested)\.dat" |
| 78 | |
| 79 | echo "quotes to avoid shell globbing" |
| 80 | git lfs checkout "file*.dat" |
| 81 | [ "$contents" = "$(cat file1.dat)" ] |
| 82 | [ "$contents" = "$(cat file3.dat)" ] |
| 83 | [ ! -f folder1/nested.dat ] |
| 84 | [ ! -e folder2 ] |
| 85 | assert_clean_worktree_with_exceptions "nested\.dat" |
| 86 | |
| 87 | echo "test subdir context" |
| 88 | rm file1.dat |
| 89 | pushd folder1 |
| 90 | git lfs checkout nested.dat |
| 91 | [ "$contents" = "$(cat nested.dat)" ] |
| 92 | [ ! -f ../file1.dat ] |
| 93 | [ ! -e ../folder2 ] |
| 94 | assert_clean_worktree_with_exceptions "(file1|folder4/nested)\.dat" |
| 95 | |
| 96 | # test '.' in current dir |
| 97 | rm nested.dat |
| 98 | git lfs checkout . |
| 99 | [ "$contents" = "$(cat nested.dat)" ] |
| 100 | [ ! -f ../file1.dat ] |
| 101 | [ ! -e ../folder2 ] |
| 102 | assert_clean_worktree_with_exceptions "(file1|folder4/nested)\.dat" |
| 103 | |
| 104 | # test '..' in current dir |
| 105 | git lfs checkout .. |
| 106 | [ "$contents" = "$(cat ../file1.dat)" ] |
| 107 | [ "$contents" = "$(cat ../folder2/folder3/folder4/nested.dat)" ] |
| 108 | assert_clean_status |
| 109 | |
| 110 | # test glob match with '..' in current dir |
| 111 | rm -rf ../folder2 |
| 112 | git lfs checkout '../folder2/**' |
| 113 | [ "$contents" = "$(cat ../folder2/folder3/folder4/nested.dat)" ] |
| 114 | assert_clean_status |
| 115 | popd |
| 116 | |
| 117 | echo "test folder param" |
| 118 | rm -rf folder2 |
| 119 | git lfs checkout folder2 |
| 120 | [ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ] |
| 121 | assert_clean_status |
| 122 | |
| 123 | echo "test folder param with pre-existing directory" |
| 124 | rm -rf folder2 |
| 125 | mkdir folder2 |
| 126 | git lfs checkout folder2 |
| 127 | [ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ] |
| 128 | assert_clean_status |
| 129 | |
| 130 | echo "test folder param with glob match" |
| 131 | rm -rf folder2 |
| 132 | git lfs checkout 'folder2/**' |
| 133 | [ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ] |
| 134 | assert_clean_status |
| 135 | |
| 136 | echo "test '.' in current dir" |
| 137 | rm -rf file1.dat file2.dat file3.dat folder1 folder2 |
| 138 | git lfs checkout . |
| 139 | [ "$contents" = "$(cat file1.dat)" ] |
| 140 | [ "$contents" = "$(cat file2.dat)" ] |
| 141 | [ "$contents" = "$(cat file3.dat)" ] |
| 142 | [ "$contents" = "$(cat folder1/nested.dat)" ] |
| 143 | [ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ] |
| 144 | assert_clean_status |
| 145 | |
| 146 | echo "test pre-existing directories" |
| 147 | rm -rf folder1/nested.dat folder2/folder3/folder4 |
| 148 | git lfs checkout |
| 149 | [ "$contents" = "$(cat folder1/nested.dat)" ] |
| 150 | [ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ] |
| 151 | assert_clean_status |
| 152 | |
| 153 | echo "test checkout with missing data doesn't fail" |
| 154 | git push origin main |
| 155 | rm -rf .git/lfs/objects |
| 156 | rm file*.dat |
| 157 | git lfs checkout |
| 158 | [ "$(pointer $contents_oid $contentsize)" = "$(cat file1.dat)" ] |
| 159 | [ "$(pointer $contents_oid $contentsize)" = "$(cat file2.dat)" ] |
| 160 | [ "$(pointer $contents_oid $contentsize)" = "$(cat file3.dat)" ] |
| 161 | [ "$contents" = "$(cat folder1/nested.dat)" ] |
| 162 | [ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ] |
| 163 | assert_clean_worktree_with_exceptions "file[123]\.dat" |
| 164 | ) |
| 165 | end_test |
| 166 | |
| 167 | begin_test "checkout: skip directory file conflicts" |
| 168 | ( |
| 169 | set -e |
| 170 | |
| 171 | reponame="checkout-skip-dir-file-conflicts" |
| 172 | setup_remote_repo "$reponame" |
| 173 | clone_repo "$reponame" "$reponame" |
| 174 | |
| 175 | git lfs track "*.dat" |
| 176 | |
| 177 | contents="a" |
| 178 | contents_oid="$(calc_oid "$contents")" |
| 179 | mkdir -p dir1 dir2/dir3/dir4 |
| 180 | printf "%s" "$contents" >dir1/a.dat |
| 181 | printf "%s" "$contents" >dir2/dir3/dir4/a.dat |
| 182 | |
| 183 | git add .gitattributes dir1 dir2 |
| 184 | git commit -m "initial commit" |
| 185 | |
| 186 | rm -rf dir1 dir2/dir3 |
| 187 | touch dir1 dir2/dir3 |
| 188 | |
| 189 | git lfs checkout 2>&1 | tee checkout.log |
| 190 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 191 | echo >&2 "fatal: expected checkout to succeed ..." |
| 192 | exit 1 |
| 193 | fi |
| 194 | grep '"dir1/a\.dat": not a directory' checkout.log |
| 195 | grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log |
| 196 | |
| 197 | [ -f "dir1" ] |
| 198 | [ -f "dir2/dir3" ] |
| 199 | assert_clean_index |
| 200 | |
| 201 | pushd dir2 |
| 202 | git lfs checkout 2>&1 | tee checkout.log |
| 203 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 204 | echo >&2 "fatal: expected checkout to succeed ..." |
| 205 | exit 1 |
| 206 | fi |
| 207 | grep '"dir1/a\.dat": not a directory' checkout.log |
| 208 | grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log |
| 209 | popd |
| 210 | |
| 211 | [ -f "dir1" ] |
| 212 | [ -f "dir2/dir3" ] |
| 213 | assert_clean_index |
| 214 | ) |
| 215 | end_test |
| 216 | |
| 217 | begin_test "checkout: skip directory symlink conflicts" |
| 218 | ( |
| 219 | set -e |
| 220 | |
| 221 | skip_if_symlinks_unsupported |
| 222 | |
| 223 | reponame="checkout-skip-dir-symlink-conflicts" |
| 224 | setup_remote_repo "$reponame" |
| 225 | clone_repo "$reponame" "$reponame" |
| 226 | |
| 227 | git lfs track "*.dat" |
| 228 | |
| 229 | contents="a" |
| 230 | contents_oid="$(calc_oid "$contents")" |
| 231 | mkdir -p dir1 dir2/dir3/dir4 |
| 232 | printf "%s" "$contents" >dir1/a.dat |
| 233 | printf "%s" "$contents" >dir2/dir3/dir4/a.dat |
| 234 | |
| 235 | git add .gitattributes dir1 dir2 |
| 236 | git commit -m "initial commit" |
| 237 | |
| 238 | # test with symlinks to directories |
| 239 | rm -rf dir1 dir2/dir3 ../link* |
| 240 | mkdir ../link1 ../link2 |
| 241 | ln -s ../link1 dir1 |
| 242 | ln -s ../../link2 dir2/dir3 |
| 243 | |
| 244 | git lfs checkout 2>&1 | tee checkout.log |
| 245 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 246 | echo >&2 "fatal: expected checkout to succeed ..." |
| 247 | exit 1 |
| 248 | fi |
| 249 | grep '"dir1/a\.dat": not a directory' checkout.log |
| 250 | grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log |
| 251 | [ 0 -eq "$(grep -c "is beyond a symbolic link" checkout.log)" ] |
| 252 | |
| 253 | [ -L "dir1" ] |
| 254 | [ -L "dir2/dir3" ] |
| 255 | [ ! -e "../link1/a.dat" ] |
| 256 | [ ! -e "../link2/dir4" ] |
| 257 | assert_clean_index |
| 258 | |
| 259 | rm -rf dir1 dir2/dir3 |
| 260 | mkdir link1 link2 |
| 261 | ln -s link1 dir1 |
| 262 | ln -s ../link2 dir2/dir3 |
| 263 | |
| 264 | git lfs checkout 2>&1 | tee checkout.log |
| 265 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 266 | echo >&2 "fatal: expected checkout to succeed ..." |
| 267 | exit 1 |
| 268 | fi |
| 269 | grep '"dir1/a\.dat": not a directory' checkout.log |
| 270 | grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log |
| 271 | [ 0 -eq "$(grep -c "is beyond a symbolic link" checkout.log)" ] |
| 272 | |
| 273 | [ -L "dir1" ] |
| 274 | [ -L "dir2/dir3" ] |
| 275 | [ ! -e "link1/a.dat" ] |
| 276 | [ ! -e "link2/dir4" ] |
| 277 | assert_clean_index |
| 278 | |
| 279 | pushd dir2 |
| 280 | git lfs checkout 2>&1 | tee checkout.log |
| 281 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 282 | echo >&2 "fatal: expected checkout to succeed ..." |
| 283 | exit 1 |
| 284 | fi |
| 285 | grep '"dir1/a\.dat": not a directory' checkout.log |
| 286 | grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log |
| 287 | [ 0 -eq "$(grep -c "is beyond a symbolic link" checkout.log)" ] |
| 288 | popd |
| 289 | |
| 290 | [ -L "dir1" ] |
| 291 | [ -L "dir2/dir3" ] |
| 292 | [ ! -e "link1/a.dat" ] |
| 293 | [ ! -e "link2/dir4" ] |
| 294 | assert_clean_index |
| 295 | |
| 296 | # test with symlink to file and dangling symlink |
| 297 | rm -rf dir1 dir2/dir3 ../link* |
| 298 | touch ../link1 |
| 299 | ln -s ../link1 dir1 |
| 300 | ln -s ../../link2 dir2/dir3 |
| 301 | |
| 302 | git lfs checkout 2>&1 | tee checkout.log |
| 303 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 304 | echo >&2 "fatal: expected checkout to succeed ..." |
| 305 | exit 1 |
| 306 | fi |
| 307 | grep '"dir1/a\.dat": not a directory' checkout.log |
| 308 | grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log |
| 309 | |
| 310 | [ -L "dir1" ] |
| 311 | [ -L "dir2/dir3" ] |
| 312 | [ -f "../link1" ] |
| 313 | [ ! -e "../link2" ] |
| 314 | assert_clean_index |
| 315 | |
| 316 | rm -rf dir1 dir2/dir3 link* |
| 317 | touch link1 |
| 318 | ln -s link1 dir1 |
| 319 | ln -s ../link2 dir2/dir3 |
| 320 | |
| 321 | git lfs checkout 2>&1 | tee checkout.log |
| 322 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 323 | echo >&2 "fatal: expected checkout to succeed ..." |
| 324 | exit 1 |
| 325 | fi |
| 326 | grep '"dir1/a\.dat": not a directory' checkout.log |
| 327 | grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log |
| 328 | |
| 329 | [ -L "dir1" ] |
| 330 | [ -L "dir2/dir3" ] |
| 331 | [ -f "link1" ] |
| 332 | [ ! -e "link2" ] |
| 333 | assert_clean_index |
| 334 | |
| 335 | pushd dir2 |
| 336 | git lfs checkout 2>&1 | tee checkout.log |
| 337 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 338 | echo >&2 "fatal: expected checkout to succeed ..." |
| 339 | exit 1 |
| 340 | fi |
| 341 | grep '"dir1/a\.dat": not a directory' checkout.log |
| 342 | grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log |
| 343 | popd |
| 344 | |
| 345 | [ -L "dir1" ] |
| 346 | [ -L "dir2/dir3" ] |
| 347 | [ -f "link1" ] |
| 348 | [ ! -e "link2" ] |
| 349 | assert_clean_index |
| 350 | ) |
| 351 | end_test |
| 352 | |
| 353 | begin_test "checkout: skip file symlink conflicts" |
| 354 | ( |
| 355 | set -e |
| 356 | |
| 357 | skip_if_symlinks_unsupported |
| 358 | |
| 359 | reponame="checkout-skip-file-symlink-conflicts" |
| 360 | setup_remote_repo "$reponame" |
| 361 | clone_repo "$reponame" "$reponame" |
| 362 | |
| 363 | git lfs track "*.dat" |
| 364 | |
| 365 | contents="a" |
| 366 | contents_oid="$(calc_oid "$contents")" |
| 367 | mkdir -p dir1/dir2/dir3 |
| 368 | printf "%s" "$contents" >a.dat |
| 369 | printf "%s" "$contents" >dir1/dir2/dir3/a.dat |
| 370 | |
| 371 | git add .gitattributes a.dat dir1 |
| 372 | git commit -m "initial commit" |
| 373 | |
| 374 | # test with symlinks to pointer files |
| 375 | rm -rf a.dat dir1/dir2/dir3/a.dat ../link* |
| 376 | contents_pointer="$(git cat-file -p ":a.dat")" |
| 377 | printf "%s" "$contents_pointer" >../link1 |
| 378 | printf "%s" "$contents_pointer" >../link2 |
| 379 | ln -s ../link1 a.dat |
| 380 | ln -s ../../../../link2 dir1/dir2/dir3/a.dat |
| 381 | |
| 382 | git lfs checkout 2>&1 | tee checkout.log |
| 383 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 384 | echo >&2 "fatal: expected checkout to succeed ..." |
| 385 | exit 1 |
| 386 | fi |
| 387 | grep '"a\.dat": not a regular file' checkout.log |
| 388 | grep '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log |
| 389 | |
| 390 | [ -L "a.dat" ] |
| 391 | [ -L "dir1/dir2/dir3/a.dat" ] |
| 392 | [ -f "../link1" ] |
| 393 | [ "$contents_pointer" = "$(cat ../link1)" ] |
| 394 | [ -f "../link2" ] |
| 395 | [ "$contents_pointer" = "$(cat ../link2)" ] |
| 396 | assert_clean_index |
| 397 | |
| 398 | rm -rf a.dat dir1/dir2/dir3/a.dat link* |
| 399 | printf "%s" "$contents_pointer" >link1 |
| 400 | printf "%s" "$contents_pointer" >link2 |
| 401 | ln -s link1 a.dat |
| 402 | ln -s ../../../link2 dir1/dir2/dir3/a.dat |
| 403 | |
| 404 | git lfs checkout 2>&1 | tee checkout.log |
| 405 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 406 | echo >&2 "fatal: expected checkout to succeed ..." |
| 407 | exit 1 |
| 408 | fi |
| 409 | grep '"a\.dat": not a regular file' checkout.log |
| 410 | grep '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log |
| 411 | |
| 412 | [ -L "a.dat" ] |
| 413 | [ -L "dir1/dir2/dir3/a.dat" ] |
| 414 | [ -f "link1" ] |
| 415 | [ "$contents_pointer" = "$(cat link1)" ] |
| 416 | [ -f "link2" ] |
| 417 | [ "$contents_pointer" = "$(cat link2)" ] |
| 418 | assert_clean_index |
| 419 | |
| 420 | pushd dir1/dir2 |
| 421 | git lfs checkout 2>&1 | tee checkout.log |
| 422 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 423 | echo >&2 "fatal: expected checkout to succeed ..." |
| 424 | exit 1 |
| 425 | fi |
| 426 | grep '"a\.dat": not a regular file' checkout.log |
| 427 | grep '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log |
| 428 | popd |
| 429 | |
| 430 | [ -L "a.dat" ] |
| 431 | [ -L "dir1/dir2/dir3/a.dat" ] |
| 432 | [ -f "link1" ] |
| 433 | [ "$contents_pointer" = "$(cat link1)" ] |
| 434 | [ -f "link2" ] |
| 435 | [ "$contents_pointer" = "$(cat link2)" ] |
| 436 | assert_clean_index |
| 437 | |
| 438 | # test with symlink to directory and dangling symlink |
| 439 | rm -rf a.dat dir1/dir2/dir3/a.dat ../link* |
| 440 | mkdir ../link1 |
| 441 | ln -s ../link1 a.dat |
| 442 | ln -s ../../../../link2 dir1/dir2/dir3/a.dat |
| 443 | |
| 444 | git lfs checkout 2>&1 | tee checkout.log |
| 445 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 446 | echo >&2 "fatal: expected checkout to succeed ..." |
| 447 | exit 1 |
| 448 | fi |
| 449 | grep '"a\.dat": not a regular file' checkout.log |
| 450 | grep '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log |
| 451 | |
| 452 | [ -L "a.dat" ] |
| 453 | [ -L "dir1/dir2/dir3/a.dat" ] |
| 454 | [ -d "../link1" ] |
| 455 | [ ! -e "../link2" ] |
| 456 | assert_clean_index |
| 457 | |
| 458 | rm -rf a.dat dir1/dir2/dir3/a.dat link* |
| 459 | mkdir link1 |
| 460 | ln -s link1 a.dat |
| 461 | ln -s ../../../link2 dir1/dir2/dir3/a.dat |
| 462 | |
| 463 | git lfs checkout 2>&1 | tee checkout.log |
| 464 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 465 | echo >&2 "fatal: expected checkout to succeed ..." |
| 466 | exit 1 |
| 467 | fi |
| 468 | grep '"a\.dat": not a regular file' checkout.log |
| 469 | grep '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log |
| 470 | |
| 471 | [ -L "a.dat" ] |
| 472 | [ -L "dir1/dir2/dir3/a.dat" ] |
| 473 | [ -d "link1" ] |
| 474 | [ ! -e "link2" ] |
| 475 | assert_clean_index |
| 476 | |
| 477 | pushd dir1/dir2 |
| 478 | git lfs checkout 2>&1 | tee checkout.log |
| 479 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 480 | echo >&2 "fatal: expected checkout to succeed ..." |
| 481 | exit 1 |
| 482 | fi |
| 483 | grep '"a\.dat": not a regular file' checkout.log |
| 484 | grep '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log |
| 485 | popd |
| 486 | |
| 487 | [ -L "a.dat" ] |
| 488 | [ -L "dir1/dir2/dir3/a.dat" ] |
| 489 | [ -d "link1" ] |
| 490 | [ ! -e "link2" ] |
| 491 | assert_clean_index |
| 492 | ) |
| 493 | end_test |
| 494 | |
| 495 | # This test applies to case-preserving but case-insensitive filesystems, |
| 496 | # such as APFS and NTFS when in their default configurations. |
| 497 | # On case-sensitive filesystems this test has no particular value and |
| 498 | # should always pass. |
| 499 | begin_test "checkout: skip case-based symlink conflicts" |
| 500 | ( |
| 501 | set -e |
| 502 | |
| 503 | skip_if_symlinks_unsupported |
| 504 | |
| 505 | # Only test with Git version 2.20.0 as it introduced detection of |
| 506 | # case-insensitive filesystems to the "git clone" command, which the |
| 507 | # test depends on to determine the filesystem type. |
| 508 | ensure_git_version_isnt "$VERSION_LOWER" "2.20.0" |
| 509 | |
| 510 | reponame="checkout-skip-case-symlink-conflicts" |
| 511 | setup_remote_repo "$reponame" |
| 512 | clone_repo "$reponame" "$reponame" |
| 513 | |
| 514 | mkdir dir1 |
| 515 | ln -s ../link1 A.dat |
| 516 | ln -s ../../link2 dir1/a.dat |
| 517 | ln -s ../link3 DIR3 |
| 518 | ln -s ../../link4 dir1/dir2 |
| 519 | |
| 520 | git add A.dat dir1 DIR3 |
| 521 | git commit -m "initial commit" |
| 522 | |
| 523 | rm A.dat dir1/* DIR3 |
| 524 | |
| 525 | echo "*.dat filter=lfs diff=lfs merge=lfs -text" >.gitattributes |
| 526 | |
| 527 | contents="a" |
| 528 | contents_oid="$(calc_oid "$contents")" |
| 529 | mkdir dir3 dir1/DIR2 |
| 530 | printf "%s" "$contents" >a.dat |
| 531 | printf "%s" "$contents" >dir1/A.dat |
| 532 | printf "%s" "$contents" >dir3/a.dat |
| 533 | printf "%s" "$contents" >dir1/DIR2/a.dat |
| 534 | |
| 535 | git -c core.ignoreCase=false add .gitattributes a.dat dir1/A.dat \ |
| 536 | dir3/a.dat dir1/DIR2/a.dat |
| 537 | git commit -m "case-conflicting commit" |
| 538 | |
| 539 | git push origin main |
| 540 | assert_server_object "$reponame" "$contents_oid" |
| 541 | |
| 542 | cd .. |
| 543 | GIT_LFS_SKIP_SMUDGE=1 git clone "$GITSERVER/$reponame" "${reponame}-assert" 2>&1 | tee clone.log |
| 544 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 545 | echo >&2 "fatal: expected clone to succeed ..." |
| 546 | exit 1 |
| 547 | fi |
| 548 | collision="$(grep -c "collided" clone.log)" || true |
| 549 | |
| 550 | cd "${reponame}-assert" |
| 551 | git lfs fetch origin main |
| 552 | |
| 553 | assert_local_object "$contents_oid" 1 |
| 554 | |
| 555 | rm -rf *.dat dir1 *3 ../link* |
| 556 | mkdir ../link3 ../link4 |
| 557 | |
| 558 | git lfs checkout 2>&1 | tee checkout.log |
| 559 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 560 | echo >&2 "fatal: expected checkout to succeed ..." |
| 561 | exit 1 |
| 562 | fi |
| 563 | grep -q 'Checking out LFS objects: 100% (4/4), 4 B' checkout.log |
| 564 | |
| 565 | [ -f "a.dat" ] |
| 566 | [ "$contents" = "$(cat "a.dat")" ] |
| 567 | [ -f "dir1/A.dat" ] |
| 568 | [ "$contents" = "$(cat "dir1/A.dat")" ] |
| 569 | [ -f "dir3/a.dat" ] |
| 570 | [ "$contents" = "$(cat "dir3/a.dat")" ] |
| 571 | [ -f "dir1/DIR2/a.dat" ] |
| 572 | [ "$contents" = "$(cat "dir1/DIR2/a.dat")" ] |
| 573 | [ ! -e "../link1" ] |
| 574 | [ ! -e "../link2" ] |
| 575 | [ ! -e "../link3/a.dat" ] |
| 576 | [ ! -e "../link4/a.dat" ] |
| 577 | assert_clean_index |
| 578 | |
| 579 | rm -rf a.dat dir1/A.dat dir3 dir1/DIR2 |
| 580 | git checkout -- A.dat dir1/a.dat DIR3 dir1/dir2 |
| 581 | |
| 582 | git lfs checkout 2>&1 | tee checkout.log |
| 583 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 584 | echo >&2 "fatal: expected checkout to succeed ..." |
| 585 | exit 1 |
| 586 | fi |
| 587 | if [ "$collision" -eq "0" ]; then |
| 588 | # case-sensitive filesystem |
| 589 | grep -q 'Checking out LFS objects: 100% (4/4), 4 B' checkout.log |
| 590 | else |
| 591 | # case-insensitive filesystem |
| 592 | grep '"a\.dat": not a regular file' checkout.log |
| 593 | grep '"dir1/A\.dat": not a regular file' checkout.log |
| 594 | grep '"dir3/a\.dat": not a directory' checkout.log |
| 595 | grep '"dir1/DIR2/a\.dat": not a directory' checkout.log |
| 596 | [ 0 -eq "$(grep -c "is beyond a symbolic link" checkout.log)" ] |
| 597 | fi |
| 598 | |
| 599 | if [ "$collision" -eq "0" ]; then |
| 600 | # case-sensitive filesystem |
| 601 | [ -f "a.dat" ] |
| 602 | [ "$contents" = "$(cat "a.dat")" ] |
| 603 | [ -f "dir1/A.dat" ] |
| 604 | [ "$contents" = "$(cat "dir1/A.dat")" ] |
| 605 | [ -f "dir3/a.dat" ] |
| 606 | [ "$contents" = "$(cat "dir3/a.dat")" ] |
| 607 | [ -f "dir1/DIR2/a.dat" ] |
| 608 | [ "$contents" = "$(cat "dir1/DIR2/a.dat")" ] |
| 609 | else |
| 610 | # case-insensitive filesystem |
| 611 | [ -L "a.dat" ] |
| 612 | [ -L "dir1/A.dat" ] |
| 613 | [ -L "dir3" ] |
| 614 | [ -L "dir1/DIR2" ] |
| 615 | fi |
| 616 | [ ! -e "../link1" ] |
| 617 | [ ! -e "../link2" ] |
| 618 | [ ! -e "../link3/a.dat" ] |
| 619 | [ ! -e "../link4/a.dat" ] |
| 620 | assert_clean_index |
| 621 | ) |
| 622 | end_test |
| 623 | |
| 624 | begin_test "checkout: skip changed files" |
| 625 | ( |
| 626 | set -e |
| 627 | |
| 628 | reponame="checkout-skip-changed-files" |
| 629 | setup_remote_repo "$reponame" |
| 630 | clone_repo "$reponame" "$reponame" |
| 631 | |
| 632 | git lfs track "*.dat" |
| 633 | |
| 634 | contents="a" |
| 635 | contents_oid="$(calc_oid "$contents")" |
| 636 | printf "%s" "$contents" >a.dat |
| 637 | |
| 638 | git add .gitattributes a.dat |
| 639 | git commit -m "initial commit" |
| 640 | |
| 641 | contents_new="$contents +extra" |
| 642 | printf "%s" "$contents_new" >a.dat |
| 643 | |
| 644 | git lfs checkout |
| 645 | |
| 646 | [ "$contents_new" = "$(cat a.dat)" ] |
| 647 | assert_clean_index |
| 648 | |
| 649 | rm a.dat |
| 650 | mkdir a.dat |
| 651 | |
| 652 | git lfs checkout |
| 653 | |
| 654 | [ -d "a.dat" ] |
| 655 | assert_clean_index |
| 656 | |
| 657 | pushd a.dat |
| 658 | git lfs checkout |
| 659 | popd |
| 660 | |
| 661 | [ -d "a.dat" ] |
| 662 | assert_clean_index |
| 663 | ) |
| 664 | end_test |
| 665 | |
| 666 | begin_test "checkout: break hard links to existing files" |
| 667 | ( |
| 668 | set -e |
| 669 | |
| 670 | reponame="checkout-break-file-hardlinks" |
| 671 | setup_remote_repo "$reponame" |
| 672 | clone_repo "$reponame" "$reponame" |
| 673 | |
| 674 | git lfs track "*.dat" |
| 675 | |
| 676 | contents="a" |
| 677 | contents_oid="$(calc_oid "$contents")" |
| 678 | mkdir -p dir1/dir2/dir3 |
| 679 | printf "%s" "$contents" >a.dat |
| 680 | printf "%s" "$contents" >dir1/dir2/dir3/a.dat |
| 681 | |
| 682 | git add .gitattributes a.dat dir1 |
| 683 | git commit -m "initial commit" |
| 684 | |
| 685 | git push origin main |
| 686 | assert_server_object "$reponame" "$contents_oid" |
| 687 | |
| 688 | cd .. |
| 689 | GIT_LFS_SKIP_SMUDGE=1 git clone "$GITSERVER/$reponame" "${reponame}-assert" |
| 690 | |
| 691 | cd "${reponame}-assert" |
| 692 | git lfs fetch origin main |
| 693 | |
| 694 | assert_local_object "$contents_oid" 1 |
| 695 | |
| 696 | rm -f a.dat dir1/dir2/dir3/a.dat ../link |
| 697 | pointer="$(git cat-file -p ":a.dat")" |
| 698 | echo "$pointer" >../link |
| 699 | ln ../link a.dat |
| 700 | ln ../link dir1/dir2/dir3/a.dat |
| 701 | |
| 702 | git lfs checkout |
| 703 | |
| 704 | [ "$contents" = "$(cat a.dat)" ] |
| 705 | [ "$contents" = "$(cat dir1/dir2/dir3/a.dat)" ] |
| 706 | [ "$pointer" = "$(cat ../link)" ] |
| 707 | assert_clean_status |
| 708 | |
| 709 | rm a.dat dir1/dir2/dir3/a.dat |
| 710 | ln ../link a.dat |
| 711 | ln ../link dir1/dir2/dir3/a.dat |
| 712 | |
| 713 | pushd dir1/dir2 |
| 714 | git lfs checkout |
| 715 | popd |
| 716 | |
| 717 | [ "$contents" = "$(cat a.dat)" ] |
| 718 | [ "$contents" = "$(cat dir1/dir2/dir3/a.dat)" ] |
| 719 | [ "$pointer" = "$(cat ../link)" ] |
| 720 | assert_clean_status |
| 721 | ) |
| 722 | end_test |
| 723 | |
| 724 | begin_test "checkout: without clean filter" |
| 725 | ( |
| 726 | set -e |
| 727 | |
| 728 | reponame="$(basename "$0" ".sh")" |
| 729 | git lfs uninstall |
| 730 | |
| 731 | git clone "$GITSERVER/$reponame" checkout-without-clean |
| 732 | cd checkout-without-clean |
| 733 | |
| 734 | echo "checkout without clean filter" |
| 735 | git lfs uninstall |
| 736 | git config --list > config.txt |
| 737 | grep "filter.lfs.clean" config.txt && { |
| 738 | echo "clean filter still configured:" |
| 739 | cat config.txt |
| 740 | exit 1 |
| 741 | } |
| 742 | ls -al |
| 743 | |
| 744 | git lfs checkout | tee checkout.txt |
| 745 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 746 | echo >&2 "fatal: expected checkout to succeed ..." |
| 747 | exit 1 |
| 748 | fi |
| 749 | grep "Git LFS is not installed" checkout.txt |
| 750 | |
| 751 | contentsize=19 |
| 752 | contents_oid=$(calc_oid "something something") |
| 753 | [ "$(pointer $contents_oid $contentsize)" = "$(cat file1.dat)" ] |
| 754 | [ "$(pointer $contents_oid $contentsize)" = "$(cat file2.dat)" ] |
| 755 | [ "$(pointer $contents_oid $contentsize)" = "$(cat file3.dat)" ] |
| 756 | [ "$(pointer $contents_oid $contentsize)" = "$(cat folder1/nested.dat)" ] |
| 757 | [ "$(pointer $contents_oid $contentsize)" = "$(cat folder2/folder3/folder4/nested.dat)" ] |
| 758 | ) |
| 759 | end_test |
| 760 | |
| 761 | begin_test "checkout: outside git repository" |
| 762 | ( |
| 763 | set +e |
| 764 | git lfs checkout 2>&1 > checkout.log |
| 765 | res=$? |
| 766 | |
| 767 | set -e |
| 768 | if [ "$res" = "0" ]; then |
| 769 | echo "Passes because $GIT_LFS_TEST_DIR is unset." |
| 770 | exit 0 |
| 771 | fi |
| 772 | [ "$res" = "128" ] |
| 773 | grep "Not in a Git repository" checkout.log |
| 774 | ) |
| 775 | end_test |
| 776 | |
| 777 | begin_test "checkout: read-only directory" |
| 778 | ( |
| 779 | set -e |
| 780 | |
| 781 | skip_if_root_or_admin "$test_description" |
| 782 | |
| 783 | reponame="checkout-read-only" |
| 784 | git init "$reponame" |
| 785 | cd "$reponame" |
| 786 | |
| 787 | git lfs track "*.bin" |
| 788 | |
| 789 | contents="a" |
| 790 | contents_oid=$(calc_oid "$contents") |
| 791 | mkdir dir |
| 792 | printf "%s" "$contents" > dir/a.bin |
| 793 | |
| 794 | git add .gitattributes dir/a.bin |
| 795 | git commit -m "add dir/a.bin" |
| 796 | |
| 797 | rm dir/a.bin |
| 798 | |
| 799 | if [ "$IS_WINDOWS" -eq 1 ]; then |
| 800 | icacls dir /inheritance:r |
| 801 | icacls dir /grant:r Everyone:R |
| 802 | else |
| 803 | chmod a-w dir |
| 804 | fi |
| 805 | git lfs checkout 2>&1 | tee checkout.log |
| 806 | # Note that although the checkout command should log an error, at present |
| 807 | # we still expect a zero exit code. |
| 808 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 809 | echo >&2 "fatal: expected 'git lfs checkout' to succeed ..." |
| 810 | exit 1 |
| 811 | fi |
| 812 | |
| 813 | assert_local_object "$contents_oid" 1 |
| 814 | |
| 815 | [ ! -e dir/a.bin ] |
| 816 | |
| 817 | grep 'could not check out "dir/a.bin"' checkout.log |
| 818 | grep 'could not create working directory file' checkout.log |
| 819 | grep 'permission denied' checkout.log |
| 820 | ) |
| 821 | end_test |
| 822 | |
| 823 | begin_test "checkout: read-only file" |
| 824 | ( |
| 825 | set -e |
| 826 | |
| 827 | reponame="checkout-locked" |
| 828 | filename="a.txt" |
| 829 | |
| 830 | setup_remote_repo_with_file "$reponame" "$filename" |
| 831 | contents_oid="$(calc_oid_file "$filename")" |
| 832 | |
| 833 | pushd "$TRASHDIR" > /dev/null |
| 834 | GIT_LFS_SKIP_SMUDGE=1 clone_repo "$reponame" "${reponame}-assert" |
| 835 | |
| 836 | chmod a-w "$filename" |
| 837 | |
| 838 | refute_file_writeable "$filename" |
| 839 | assert_pointer "refs/heads/main" "$filename" "$contents_oid" 6 |
| 840 | |
| 841 | git lfs fetch |
| 842 | git lfs checkout "$filename" |
| 843 | |
| 844 | refute_file_writeable "$filename" |
| 845 | [ "$filename" = "$(cat "$filename")" ] |
| 846 | popd > /dev/null |
| 847 | ) |
| 848 | end_test |
| 849 | |
| 850 | begin_test "checkout with empty file doesn't modify mtime" |
| 851 | ( |
| 852 | set -e |
| 853 | git init checkout-empty-file |
| 854 | cd checkout-empty-file |
| 855 | |
| 856 | git lfs track "*.bin" |
| 857 | git add . |
| 858 | git commit -m 'gitattributes' |
| 859 | printf abc > abc.bin |
| 860 | git add . |
| 861 | git commit -m 'abc' |
| 862 | |
| 863 | touch foo.bin |
| 864 | lfstest-nanomtime foo.bin >foo.mtime |
| 865 | |
| 866 | # This isn't necessary, but it takes a few cycles to make sure that our |
| 867 | # timestamp changes. |
| 868 | git add foo.bin |
| 869 | git commit -m 'foo' |
| 870 | |
| 871 | git lfs checkout |
| 872 | lfstest-nanomtime foo.bin >foo.mtime2 |
| 873 | diff -u foo.mtime foo.mtime2 |
| 874 | ) |
| 875 | end_test |
| 876 | |
| 877 | begin_test "checkout: conflicts" |
| 878 | ( |
| 879 | set -e |
| 880 | |
| 881 | reponame="checkout-conflicts" |
| 882 | filename="file1.dat" |
| 883 | |
| 884 | setup_remote_repo_with_file "$reponame" "$filename" |
| 885 | |
| 886 | pushd "$TRASHDIR" > /dev/null |
| 887 | clone_repo "$reponame" "${reponame}_checkout" |
| 888 | |
| 889 | git tag base |
| 890 | git checkout -b first |
| 891 | echo "abc123" > file1.dat |
| 892 | git add -u |
| 893 | echo "first" > other.txt |
| 894 | git add other.txt |
| 895 | git commit -m "first" |
| 896 | |
| 897 | git lfs checkout --to base.txt 2>&1 | tee output.txt |
| 898 | grep -- '--to and exactly one of --theirs, --ours, and --base must be used together' output.txt |
| 899 | |
| 900 | git lfs checkout --base 2>&1 | tee output.txt |
| 901 | grep -- '--to and exactly one of --theirs, --ours, and --base must be used together' output.txt |
| 902 | |
| 903 | git lfs checkout --to base.txt --ours --theirs 2>&1 | tee output.txt |
| 904 | grep -- 'at most one of --base, --theirs, and --ours is allowed' output.txt |
| 905 | |
| 906 | git lfs checkout --to base.txt --base 2>&1 | tee output.txt |
| 907 | grep -- '--to requires exactly one Git LFS object file path' output.txt |
| 908 | |
| 909 | git lfs checkout --to base.txt --base 2>&1 abc def | tee output.txt |
| 910 | grep -- '--to requires exactly one Git LFS object file path' output.txt |
| 911 | |
| 912 | git lfs checkout --to base.txt --base file1.dat 2>&1 | tee output.txt |
| 913 | grep 'Could not checkout.*not in the middle of a merge' output.txt |
| 914 | |
| 915 | git checkout -b second main |
| 916 | echo "def456" > file1.dat |
| 917 | git add -u |
| 918 | echo "second" > other.txt |
| 919 | git add other.txt |
| 920 | git commit -m "second" |
| 921 | |
| 922 | # This will cause a conflict. |
| 923 | git merge first && exit 1 |
| 924 | |
| 925 | abs_assert_dir="$(canonical_path "$TRASHDIR/${reponame}-assert")" |
| 926 | abs_theirs_file="$abs_assert_dir/dir1/dir2/theirs.txt" |
| 927 | |
| 928 | rm -rf "$abs_assert_dir" |
| 929 | |
| 930 | git lfs checkout --to base.txt --base file1.dat |
| 931 | git lfs checkout --to ../ours.txt --ours file1.dat |
| 932 | git lfs checkout --to "$abs_theirs_file" --theirs file1.dat |
| 933 | |
| 934 | echo "file1.dat" | cmp - base.txt |
| 935 | echo "def456" | cmp - ../ours.txt |
| 936 | echo "abc123" | cmp - "$abs_theirs_file" |
| 937 | |
| 938 | rm -rf base.txt ../ours.txt "$abs_assert_dir" |
| 939 | mkdir -p dir1/dir2 |
| 940 | |
| 941 | pushd dir1/dir2 |
| 942 | git lfs checkout --to base.txt --base ../../file1.dat |
| 943 | git lfs checkout --to ../../../ours.txt --ours ../../file1.dat |
| 944 | git lfs checkout --to "$abs_theirs_file" --theirs ../../file1.dat |
| 945 | popd |
| 946 | |
| 947 | echo "file1.dat" | cmp - dir1/dir2/base.txt |
| 948 | echo "def456" | cmp - ../ours.txt |
| 949 | echo "abc123" | cmp - "$abs_theirs_file" |
| 950 | |
| 951 | has_native_symlinks && { |
| 952 | rm -rf "$abs_assert_dir" |
| 953 | mkdir -p "$abs_assert_dir/link1" |
| 954 | ln -s link1 "$abs_assert_dir/dir1" |
| 955 | |
| 956 | git lfs checkout --to "$abs_theirs_file" --theirs file1.dat |
| 957 | |
| 958 | [ -L "$abs_assert_dir/dir1" ] |
| 959 | echo "abc123" | cmp - "$abs_assert_dir/link1/dir2/theirs.txt" |
| 960 | |
| 961 | rm -f base.txt link1 ../ours.txt ../link2 |
| 962 | ln -s link1 base.txt |
| 963 | ln -s link2 ../ours.txt |
| 964 | |
| 965 | git lfs checkout --to base.txt --base file1.dat |
| 966 | git lfs checkout --to ../ours.txt --ours file1.dat |
| 967 | |
| 968 | [ ! -L "base.txt" ] |
| 969 | [ ! -L "../ours.txt" ] |
| 970 | [ ! -e "link1" ] |
| 971 | [ ! -e "../link2" ] |
| 972 | echo "file1.dat" | cmp - base.txt |
| 973 | echo "def456" | cmp - ../ours.txt |
| 974 | } |
| 975 | |
| 976 | rm -f base.txt link1 ../ours.txt ../link2 |
| 977 | printf "link1" >link1 |
| 978 | printf "link2" >../link2 |
| 979 | ln link1 base.txt |
| 980 | ln ../link2 ../ours.txt |
| 981 | |
| 982 | git lfs checkout --to base.txt --base file1.dat |
| 983 | git lfs checkout --to ../ours.txt --ours file1.dat |
| 984 | |
| 985 | [ -f "link1" ] |
| 986 | [ -f "../link2" ] |
| 987 | [ "link1" = "$(cat link1)" ] |
| 988 | [ "link2" = "$(cat ../link2)" ] |
| 989 | echo "file1.dat" | cmp - base.txt |
| 990 | echo "def456" | cmp - ../ours.txt |
| 991 | |
| 992 | git lfs checkout --to base.txt --ours other.txt 2>&1 | tee output.txt |
| 993 | grep 'Could not find decoder pointer for object' output.txt |
| 994 | |
| 995 | git lfs checkout --to base.txt --ours . 2>&1 | tee output.txt |
| 996 | grep "Could not checkout .*: Git can't resolve ref: \":2:\.\"" output.txt |
| 997 | popd > /dev/null |
| 998 | ) |
| 999 | end_test |
| 1000 | |
| 1001 | begin_test "checkout: GIT_WORK_TREE" |
| 1002 | ( |
| 1003 | set -e |
| 1004 | |
| 1005 | reponame="checkout-work-tree" |
| 1006 | remotename="$(basename "$0" ".sh")" |
| 1007 | export GIT_WORK_TREE="$reponame" GIT_DIR="$reponame-git" |
| 1008 | mkdir "$GIT_WORK_TREE" "$GIT_DIR" |
| 1009 | git init |
| 1010 | git remote add origin "$GITSERVER/$remotename" |
| 1011 | |
| 1012 | git lfs uninstall --skip-repo |
| 1013 | |
| 1014 | git fetch origin |
| 1015 | git checkout -B main origin/main |
| 1016 | |
| 1017 | git lfs install |
| 1018 | git lfs fetch |
| 1019 | git lfs checkout |
| 1020 | |
| 1021 | contents="something something" |
| 1022 | [ "$contents" = "$(cat "$reponame/file1.dat")" ] |
| 1023 | ) |
| 1024 | end_test |
| 1025 | |
| 1026 | begin_test "checkout: bare repository" |
| 1027 | ( |
| 1028 | set -e |
| 1029 | |
| 1030 | reponame="checkout-bare" |
| 1031 | git init --bare "$reponame" |
| 1032 | cd "$reponame" |
| 1033 | |
| 1034 | git lfs checkout 2>&1 | tee checkout.log |
| 1035 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 1036 | echo >&2 "fatal: expected checkout to succeed ..." |
| 1037 | exit 1 |
| 1038 | fi |
| 1039 | [ "This operation must be run in a work tree." = "$(cat checkout.log)" ] |
| 1040 | ) |
| 1041 | end_test |
| 1042 | |
| 1043 | begin_test "checkout: sparse with partial clone and sparse index" |
| 1044 | ( |
| 1045 | set -e |
| 1046 | |
| 1047 | # Only test with Git version 2.25.0 as it introduced the |
| 1048 | # "git sparse-checkout" command. (Note that this test also requires |
| 1049 | # that the "git rev-list" command support the "tree:0" filter, which |
| 1050 | # was introduced with Git version 2.20.0.) |
| 1051 | ensure_git_version_isnt "$VERSION_LOWER" "2.25.0" |
| 1052 | |
| 1053 | reponame="checkout-sparse" |
| 1054 | setup_remote_repo "$reponame" |
| 1055 | clone_repo "$reponame" "$reponame" |
| 1056 | |
| 1057 | git lfs track "*.dat" |
| 1058 | |
| 1059 | contents1="a" |
| 1060 | contents1_oid=$(calc_oid "$contents1") |
| 1061 | contents2="b" |
| 1062 | contents2_oid=$(calc_oid "$contents2") |
| 1063 | contents3="c" |
| 1064 | contents3_oid=$(calc_oid "$contents3") |
| 1065 | |
| 1066 | mkdir in-dir out-dir |
| 1067 | printf "%s" "$contents1" >a.dat |
| 1068 | printf "%s" "$contents2" >in-dir/b.dat |
| 1069 | printf "%s" "$contents3" >out-dir/c.dat |
| 1070 | git add . |
| 1071 | git commit -m "add files" |
| 1072 | |
| 1073 | git push origin main |
| 1074 | |
| 1075 | assert_server_object "$reponame" "$contents1_oid" |
| 1076 | assert_server_object "$reponame" "$contents2_oid" |
| 1077 | assert_server_object "$reponame" "$contents3_oid" |
| 1078 | |
| 1079 | # Create a partial clone with a cone-mode sparse checkout of one directory |
| 1080 | # and a sparse index, which is important because otherwise the "git ls-files" |
| 1081 | # command ignores the --sparse option and lists all Git LFS files. |
| 1082 | cd .. |
| 1083 | git clone --filter=tree:0 --depth=1 --no-checkout \ |
| 1084 | "$GITSERVER/$reponame" "${reponame}-partial" |
| 1085 | |
| 1086 | cd "${reponame}-partial" |
| 1087 | git sparse-checkout init --cone --sparse-index |
| 1088 | git sparse-checkout set "in-dir" |
| 1089 | git checkout main |
| 1090 | |
| 1091 | [ -d "in-dir" ] |
| 1092 | [ ! -e "out-dir" ] |
| 1093 | |
| 1094 | assert_local_object "$contents1_oid" 1 |
| 1095 | assert_local_object "$contents2_oid" 1 |
| 1096 | refute_local_object "$contents3_oid" |
| 1097 | |
| 1098 | git lfs checkout 2>&1 | tee checkout.log |
| 1099 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 1100 | echo >&2 "fatal: expected checkout to succeed ..." |
| 1101 | exit 1 |
| 1102 | fi |
| 1103 | |
| 1104 | # When Git version 2.42.0 or higher is available, the "git lfs checkout" |
| 1105 | # command will use the "git ls-files" command rather than the |
| 1106 | # "git ls-tree" command to list files. Git v2.42.0 introduced support |
| 1107 | # in the "git ls-files" command for the "objecttype" format option and |
| 1108 | # so Git LFS can use this command to avoid checking out objects outside |
| 1109 | # the sparse cone. Otherwise, all Git LFS objects will be checked out. |
| 1110 | gitversion="$(git version | cut -d" " -f3)" |
| 1111 | set +e |
| 1112 | compare_version "$gitversion" '2.42.0' |
| 1113 | result=$? |
| 1114 | set -e |
| 1115 | if [ "$result" -eq "$VERSION_LOWER" ]; then |
| 1116 | grep 'Skipped checkout for "out-dir/c.dat"' checkout.log |
| 1117 | |
| 1118 | [ -f "out-dir/c.dat" ] |
| 1119 | [ "$(pointer $contents3_oid 1)" = "$(cat "out-dir/c.dat")" ] |
| 1120 | else |
| 1121 | grep -q 'Skipped checkout for "out-dir/c.dat"' checkout.log && exit 1 |
| 1122 | |
| 1123 | [ ! -e "out-dir/c.dat" ] |
| 1124 | fi |
| 1125 | |
| 1126 | # Fetch all Git LFS objects, including those outside the sparse cone. |
| 1127 | git lfs fetch origin main |
| 1128 | |
| 1129 | assert_local_object "$contents3_oid" 1 |
| 1130 | |
| 1131 | git lfs checkout 2>&1 | tee checkout.log |
| 1132 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 1133 | echo >&2 "fatal: expected checkout to succeed ..." |
| 1134 | exit 1 |
| 1135 | fi |
| 1136 | |
| 1137 | if [ "$result" -eq "$VERSION_LOWER" ]; then |
| 1138 | grep 'Checking out LFS objects: 100% (3/3), 3 B' checkout.log |
| 1139 | |
| 1140 | [ -f "out-dir/c.dat" ] |
| 1141 | [ "$contents3" = "$(cat "out-dir/c.dat")" ] |
| 1142 | else |
| 1143 | grep -q 'Checking out LFS objects: 100% (3/3), 3 B' checkout.log && exit 1 |
| 1144 | |
| 1145 | [ ! -e "out-dir/c.dat" ] |
| 1146 | fi |
| 1147 | ) |
| 1148 | end_test |
| 1149 | |
| 1150 | begin_test "checkout: pointer extension" |
| 1151 | ( |
| 1152 | set -e |
| 1153 | |
| 1154 | reponame="checkout-pointer-extension" |
| 1155 | setup_remote_repo "$reponame" |
| 1156 | clone_repo "$reponame" "$reponame" |
| 1157 | |
| 1158 | git lfs track "*.dat" |
| 1159 | |
| 1160 | setup_case_inverter_extension |
| 1161 | |
| 1162 | contents="abc" |
| 1163 | inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")" |
| 1164 | mkdir dir1 |
| 1165 | printf "%s" "$contents" >dir1/abc.dat |
| 1166 | |
| 1167 | git add .gitattributes dir1 |
| 1168 | git commit -m "initial commit" |
| 1169 | |
| 1170 | assert_local_object "$inverted_contents_oid" 3 |
| 1171 | |
| 1172 | rm -rf dir1 "$LFSTEST_EXT_LOG" |
| 1173 | git lfs checkout |
| 1174 | |
| 1175 | [ "$contents" = "$(cat "dir1/abc.dat")" ] |
| 1176 | grep "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG" |
| 1177 | |
| 1178 | rm -rf dir1 "$LFSTEST_EXT_LOG" |
| 1179 | mkdir dir2 |
| 1180 | |
| 1181 | pushd dir2 |
| 1182 | git lfs checkout |
| 1183 | popd |
| 1184 | |
| 1185 | [ "$contents" = "$(cat "dir1/abc.dat")" ] |
| 1186 | grep "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG" |
| 1187 | ) |
| 1188 | end_test |
| 1189 | |
| 1190 | begin_test "checkout: pointer extension with conflict" |
| 1191 | ( |
| 1192 | set -e |
| 1193 | |
| 1194 | reponame="checkout-pointer-extension-conflict" |
| 1195 | setup_remote_repo "$reponame" |
| 1196 | clone_repo "$reponame" "$reponame" |
| 1197 | |
| 1198 | git lfs track "*.dat" |
| 1199 | |
| 1200 | setup_case_inverter_extension |
| 1201 | |
| 1202 | contents="abc" |
| 1203 | inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")" |
| 1204 | mkdir dir1 |
| 1205 | printf "%s" "$contents" >dir1/abc.dat |
| 1206 | |
| 1207 | git add .gitattributes dir1 |
| 1208 | git commit -m "initial commit" |
| 1209 | |
| 1210 | assert_local_object "$inverted_contents_oid" 3 |
| 1211 | |
| 1212 | git checkout -b theirs |
| 1213 | contents_theirs="Abc" |
| 1214 | printf "%s" "$contents_theirs" >dir1/abc.dat |
| 1215 | git add dir1 |
| 1216 | git commit -m "theirs" |
| 1217 | |
| 1218 | git checkout main |
| 1219 | contents_ours="aBc" |
| 1220 | printf "%s" "$contents_ours" >dir1/abc.dat |
| 1221 | git add dir1 |
| 1222 | git commit -m "ours" |
| 1223 | |
| 1224 | git merge theirs && exit 1 |
| 1225 | |
| 1226 | rm -f "$LFSTEST_EXT_LOG" |
| 1227 | |
| 1228 | git lfs checkout --to base.txt --base dir1/abc.dat |
| 1229 | |
| 1230 | printf "%s" "$contents" | cmp - base.txt |
| 1231 | grep "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG" |
| 1232 | |
| 1233 | rm -f "$LFSTEST_EXT_LOG" |
| 1234 | |
| 1235 | pushd dir1 |
| 1236 | git lfs checkout --to ../ours.txt --ours abc.dat |
| 1237 | popd |
| 1238 | |
| 1239 | printf "%s" "$contents_ours" | cmp - ours.txt |
| 1240 | grep "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG" |
| 1241 | |
| 1242 | abs_assert_dir="$TRASHDIR/${reponame}-assert" |
| 1243 | abs_theirs_file="$(canonical_path "$abs_assert_dir/dir1/dir2/theirs.txt")" |
| 1244 | |
| 1245 | rm -rf "$abs_assert_dir" "$LFSTEST_EXT_LOG" |
| 1246 | mkdir dir2 |
| 1247 | |
| 1248 | pushd dir2 |
| 1249 | git lfs checkout --to "$abs_theirs_file" --theirs ../dir1/abc.dat |
| 1250 | popd |
| 1251 | |
| 1252 | printf "%s" "$contents_theirs" | cmp - "$abs_theirs_file" |
| 1253 | grep "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG" |
| 1254 | ) |
| 1255 | end_test |