| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "track" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | # no need to setup a remote repo, since this test doesn't need to push or pull |
| 10 | |
| 11 | mkdir track |
| 12 | cd track |
| 13 | git init |
| 14 | |
| 15 | echo "############################################################################### |
| 16 | # Set default behavior to automatically normalize line endings. |
| 17 | ############################################################################### |
| 18 | * text=auto |
| 19 | |
| 20 | #*.cs diff=csharp" > .gitattributes |
| 21 | |
| 22 | # track *.jpg once |
| 23 | git lfs track "*.jpg" | grep "Tracking \"\*.jpg\"" |
| 24 | assert_attributes_count "jpg" "filter=lfs" 1 |
| 25 | |
| 26 | # track *.jpg again |
| 27 | git lfs track "*.jpg" | grep "\"*.jpg\" already supported" |
| 28 | assert_attributes_count "jpg" "filter=lfs" 1 |
| 29 | |
| 30 | mkdir -p a/b .git/info |
| 31 | |
| 32 | echo "*.mov filter=lfs -text" > .git/info/attributes |
| 33 | echo "*.gif filter=lfs -text" > a/.gitattributes |
| 34 | echo "*.png filter=lfs -text" > a/b/.gitattributes |
| 35 | |
| 36 | git lfs track | tee track.log |
| 37 | grep "Listing tracked patterns" track.log |
| 38 | grep "*.mov ($(native_path_escaped ".git/info/attributes"))" track.log |
| 39 | grep "*.jpg (.gitattributes)" track.log |
| 40 | grep "*.gif ($(native_path_escaped "a/.gitattributes"))" track.log |
| 41 | grep "*.png ($(native_path_escaped "a/b/.gitattributes"))" track.log |
| 42 | |
| 43 | grep "Set default behavior" .gitattributes |
| 44 | grep "############" .gitattributes |
| 45 | grep "* text=auto" .gitattributes |
| 46 | grep "diff=csharp" .gitattributes |
| 47 | grep "*.jpg" .gitattributes |
| 48 | |
| 49 | echo "*.gif -filter -text" >> a/b/.gitattributes |
| 50 | echo "*.mov -filter -text" >> a/b/.gitattributes |
| 51 | |
| 52 | git lfs track | tee track.log |
| 53 | tail -n 3 track.log | head -n 1 | grep "Listing excluded patterns" |
| 54 | tail -n 3 track.log | grep "*.gif ($(native_path_escaped "a/b/.gitattributes"))" |
| 55 | tail -n 3 track.log | grep "*.mov ($(native_path_escaped "a/b/.gitattributes"))" |
| 56 | ) |
| 57 | end_test |
| 58 | |
| 59 | begin_test "track --no-excluded" |
| 60 | ( |
| 61 | set -e |
| 62 | |
| 63 | reponame="track_no_excluded" |
| 64 | mkdir "$reponame" |
| 65 | cd "$reponame" |
| 66 | git init |
| 67 | |
| 68 | mkdir -p a/b .git/info |
| 69 | |
| 70 | echo "*.mov filter=lfs -text" > .git/info/attributes |
| 71 | echo "*.gif filter=lfs -text" > a/.gitattributes |
| 72 | echo "*.png filter=lfs -text" > a/b/.gitattributes |
| 73 | echo "*.gif -filter -text" >> a/b/.gitattributes |
| 74 | echo "*.mov -filter=lfs -text" >> a/b/.gitattributes |
| 75 | |
| 76 | git lfs track --no-excluded | tee track.log |
| 77 | grep "Listing excluded patterns" track.log && exit 1 |
| 78 | true |
| 79 | ) |
| 80 | end_test |
| 81 | |
| 82 | begin_test "track --verbose" |
| 83 | ( |
| 84 | set -e |
| 85 | |
| 86 | reponame="track_verbose_logs" |
| 87 | mkdir "$reponame" |
| 88 | cd "$reponame" |
| 89 | git init |
| 90 | |
| 91 | touch foo.dat |
| 92 | git add foo.dat |
| 93 | |
| 94 | git lfs track --verbose "foo.dat" 2>&1 > track.log |
| 95 | grep "Touching \"foo.dat\"" track.log |
| 96 | ) |
| 97 | end_test |
| 98 | |
| 99 | begin_test "track --dry-run" |
| 100 | ( |
| 101 | set -e |
| 102 | |
| 103 | reponame="track_dry_run" |
| 104 | mkdir "$reponame" |
| 105 | cd "$reponame" |
| 106 | git init |
| 107 | |
| 108 | touch foo.dat |
| 109 | git add foo.dat |
| 110 | |
| 111 | git lfs track --dry-run "foo.dat" 2>&1 > track.log |
| 112 | grep "Tracking \"foo.dat\"" track.log |
| 113 | grep "Touching \"foo.dat\"" track.log |
| 114 | |
| 115 | git status --porcelain 2>&1 > status.log |
| 116 | grep "A foo.dat" status.log |
| 117 | ) |
| 118 | end_test |
| 119 | |
| 120 | begin_test "track directory" |
| 121 | ( |
| 122 | set -e |
| 123 | mkdir dir |
| 124 | cd dir |
| 125 | git init |
| 126 | |
| 127 | if [ "$IS_WINDOWS" -eq 1 ] |
| 128 | then |
| 129 | git lfs track "foo bar\\*" | tee track.txt |
| 130 | else |
| 131 | git lfs track "foo bar/*" | tee track.txt |
| 132 | fi |
| 133 | [ "foo[[:space:]]bar/* filter=lfs diff=lfs merge=lfs -text" = "$(cat .gitattributes)" ] |
| 134 | [ "Tracking \"foo bar/*\"" = "$(cat track.txt)" ] |
| 135 | |
| 136 | mkdir "foo bar" |
| 137 | echo "a" > "foo bar/a" |
| 138 | echo "b" > "foo bar/b" |
| 139 | git add foo\ bar |
| 140 | git commit -am "add foo bar" |
| 141 | |
| 142 | assert_pointer "main" "foo bar/a" "87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7" 2 |
| 143 | assert_pointer "main" "foo bar/b" "0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f" 2 |
| 144 | ) |
| 145 | end_test |
| 146 | |
| 147 | begin_test "track without trailing linebreak" |
| 148 | ( |
| 149 | set -e |
| 150 | |
| 151 | mkdir no-linebreak |
| 152 | cd no-linebreak |
| 153 | git init |
| 154 | |
| 155 | printf "*.mov filter=lfs -text" > .gitattributes |
| 156 | [ "*.mov filter=lfs -text" = "$(cat .gitattributes)" ] |
| 157 | |
| 158 | git lfs track "*.gif" |
| 159 | expected="*.mov filter=lfs -text$(cat_end) |
| 160 | *.gif filter=lfs diff=lfs merge=lfs -text$(cat_end)" |
| 161 | [ "$expected" = "$(cat -e .gitattributes)" ] |
| 162 | ) |
| 163 | end_test |
| 164 | |
| 165 | begin_test "track with existing crlf" |
| 166 | ( |
| 167 | set -e |
| 168 | |
| 169 | mkdir existing-crlf |
| 170 | cd existing-crlf |
| 171 | git init |
| 172 | |
| 173 | git config core.autocrlf true |
| 174 | git lfs track "*.mov" |
| 175 | git lfs track "*.gif" |
| 176 | expected="*.mov filter=lfs diff=lfs merge=lfs -text^M$ |
| 177 | *.gif filter=lfs diff=lfs merge=lfs -text^M$" |
| 178 | [ "$expected" = "$(cat -e .gitattributes)" ] |
| 179 | |
| 180 | git config core.autocrlf false |
| 181 | git lfs track "*.jpg" |
| 182 | expected="*.mov filter=lfs diff=lfs merge=lfs -text^M$ |
| 183 | *.gif filter=lfs diff=lfs merge=lfs -text^M$ |
| 184 | *.jpg filter=lfs diff=lfs merge=lfs -text^M$" |
| 185 | [ "$expected" = "$(cat -e .gitattributes)" ] |
| 186 | ) |
| 187 | end_test |
| 188 | |
| 189 | begin_test "track with autocrlf=true" |
| 190 | ( |
| 191 | set -e |
| 192 | |
| 193 | mkdir autocrlf-true |
| 194 | cd autocrlf-true |
| 195 | git init |
| 196 | git config core.autocrlf true |
| 197 | |
| 198 | printf "*.mov filter=lfs -text" > .gitattributes |
| 199 | [ "*.mov filter=lfs -text" = "$(cat .gitattributes)" ] |
| 200 | |
| 201 | git lfs track "*.gif" |
| 202 | expected="*.mov filter=lfs -text^M$ |
| 203 | *.gif filter=lfs diff=lfs merge=lfs -text^M$" |
| 204 | [ "$expected" = "$(cat -e .gitattributes)" ] |
| 205 | ) |
| 206 | end_test |
| 207 | |
| 208 | begin_test "track with autocrlf=input" |
| 209 | ( |
| 210 | set -e |
| 211 | |
| 212 | mkdir autocrlf-input |
| 213 | cd autocrlf-input |
| 214 | git init |
| 215 | git config core.autocrlf input |
| 216 | |
| 217 | printf "*.mov filter=lfs -text" > .gitattributes |
| 218 | [ "*.mov filter=lfs -text" = "$(cat .gitattributes)" ] |
| 219 | |
| 220 | git lfs track "*.gif" |
| 221 | if [ $IS_WINDOWS -eq 1 ] |
| 222 | then |
| 223 | [ 2 -eq "$(cat -e .gitattributes | grep -c '\^M\$')" ] |
| 224 | else |
| 225 | [ 0 -eq "$(cat -e .gitattributes | grep -c '\^M')" ] |
| 226 | fi |
| 227 | ) |
| 228 | end_test |
| 229 | |
| 230 | begin_test "track outside git repo" |
| 231 | ( |
| 232 | set -e |
| 233 | |
| 234 | git lfs track "*.foo" || { |
| 235 | # this fails if it's run outside of a git repo using GIT_LFS_TEST_DIR |
| 236 | |
| 237 | # git itself returns an exit status of 128 |
| 238 | # $ git show |
| 239 | # fatal: Not a git repository (or any of the parent directories): .git |
| 240 | # $ echo "$?" |
| 241 | # 128 |
| 242 | |
| 243 | [ "$?" = "128" ] |
| 244 | exit 0 |
| 245 | } |
| 246 | |
| 247 | if [ -n "$GIT_LFS_TEST_DIR" ]; then |
| 248 | echo "GIT_LFS_TEST_DIR should be set outside of any Git repository" |
| 249 | exit 1 |
| 250 | fi |
| 251 | |
| 252 | git init track-outside |
| 253 | cd track-outside |
| 254 | |
| 255 | git lfs track "*.file" |
| 256 | |
| 257 | git lfs track "../*.foo" || { |
| 258 | |
| 259 | # git itself returns an exit status of 128 |
| 260 | # $ git add ../test.foo |
| 261 | # fatal: ../test.foo: '../test.foo' is outside repository |
| 262 | # $ echo "$?" |
| 263 | # 128 |
| 264 | |
| 265 | [ "$?" = "128" ] |
| 266 | exit 0 |
| 267 | } |
| 268 | exit 1 |
| 269 | ) |
| 270 | end_test |
| 271 | |
| 272 | begin_test "track representation" |
| 273 | ( |
| 274 | set -e |
| 275 | |
| 276 | git init track-representation |
| 277 | cd track-representation |
| 278 | |
| 279 | git lfs track "*.jpg" |
| 280 | |
| 281 | mkdir a |
| 282 | git lfs track "a/test.file" |
| 283 | cd a |
| 284 | out3=$(git lfs track "test.file") |
| 285 | |
| 286 | if [ "$out3" != "\"test.file\" already supported" ]; then |
| 287 | echo "Track didn't recognize duplicate path" |
| 288 | cat .gitattributes |
| 289 | exit 1 |
| 290 | fi |
| 291 | |
| 292 | git lfs track "file.bin" |
| 293 | cd .. |
| 294 | out4=$(git lfs track "a/file.bin") |
| 295 | if [ "$out4" != "\"a/file.bin\" already supported" ]; then |
| 296 | echo "Track didn't recognize duplicate path" |
| 297 | cat .gitattributes |
| 298 | exit 1 |
| 299 | fi |
| 300 | ) |
| 301 | end_test |
| 302 | |
| 303 | begin_test "track absolute" |
| 304 | ( |
| 305 | # MinGW bash intercepts '/images' and passes 'C:/Program Files/Git/images' as arg! |
| 306 | if [[ $(uname) == *"MINGW"* ]]; then |
| 307 | echo "Skipping track absolute on Windows" |
| 308 | exit 0 |
| 309 | fi |
| 310 | |
| 311 | set -e |
| 312 | |
| 313 | git init track-absolute |
| 314 | cd track-absolute |
| 315 | |
| 316 | git lfs track "/images" |
| 317 | cat .gitattributes |
| 318 | grep "^/images" .gitattributes |
| 319 | ) |
| 320 | end_test |
| 321 | |
| 322 | begin_test "track in gitDir" |
| 323 | ( |
| 324 | set -e |
| 325 | |
| 326 | git init track-in-dot-git |
| 327 | cd track-in-dot-git |
| 328 | |
| 329 | echo "some content" > test.file |
| 330 | |
| 331 | cd .git |
| 332 | git lfs track "../test.file" || { |
| 333 | # this fails if it's run inside a .git directory |
| 334 | |
| 335 | # git itself returns an exit status of 128 |
| 336 | # $ git add ../test.file |
| 337 | # fatal: This operation must be run in a work tree |
| 338 | # $ echo "$?" |
| 339 | # 128 |
| 340 | |
| 341 | [ "$?" = "128" ] |
| 342 | exit 0 |
| 343 | } |
| 344 | |
| 345 | # fail if track passed |
| 346 | exit 1 |
| 347 | ) |
| 348 | end_test |
| 349 | |
| 350 | begin_test "track in symlinked dir" |
| 351 | ( |
| 352 | set -e |
| 353 | |
| 354 | git init track-symlinkdst |
| 355 | ln -s track-symlinkdst track-symlinksrc |
| 356 | cd track-symlinksrc |
| 357 | |
| 358 | git lfs track "*.png" |
| 359 | grep "^*.png" .gitattributes || { |
| 360 | echo ".gitattributes doesn't contain the expected relative path *.png:" |
| 361 | cat .gitattributes |
| 362 | exit 1 |
| 363 | } |
| 364 | ) |
| 365 | end_test |
| 366 | |
| 367 | begin_test "track blocklisted files by name" |
| 368 | ( |
| 369 | set -e |
| 370 | |
| 371 | repo="track_blocklisted_by_name" |
| 372 | mkdir "$repo" |
| 373 | cd "$repo" |
| 374 | git init |
| 375 | |
| 376 | touch .gitattributes |
| 377 | git add .gitattributes |
| 378 | git commit -m 'Initial commit' |
| 379 | |
| 380 | git lfs track .gitattributes 2>&1 > track.log && exit 1 |
| 381 | grep "Pattern '.gitattributes' matches forbidden file '.gitattributes'" track.log |
| 382 | [ 0 -eq "$(git status --porcelain | grep -c -v '^??')" ] |
| 383 | ) |
| 384 | end_test |
| 385 | |
| 386 | begin_test "track blocklisted files with glob" |
| 387 | ( |
| 388 | set -e |
| 389 | |
| 390 | repo="track_blocklisted_glob" |
| 391 | mkdir "$repo" |
| 392 | cd "$repo" |
| 393 | git init |
| 394 | |
| 395 | touch .gitattributes |
| 396 | git add .gitattributes |
| 397 | git commit -m 'Initial commit' |
| 398 | |
| 399 | git lfs track ".git*" 2>&1 > track.log && exit 1 |
| 400 | grep "Pattern '.git\*' matches forbidden file" track.log |
| 401 | [ 0 -eq "$(git status --porcelain | grep -c -v '^??')" ] |
| 402 | |
| 403 | git lfs track "*" 2>&1 > track.log && exit 1 |
| 404 | grep "Pattern '\*' matches forbidden file" track.log |
| 405 | [ 0 -eq "$(git status --porcelain | grep -c -v '^??')" ] |
| 406 | ) |
| 407 | end_test |
| 408 | |
| 409 | begin_test "track lockable" |
| 410 | ( |
| 411 | set -e |
| 412 | |
| 413 | repo="track_lockable" |
| 414 | mkdir "$repo" |
| 415 | cd "$repo" |
| 416 | git init |
| 417 | |
| 418 | # track *.jpg once, lockable |
| 419 | git lfs track --lockable "*.jpg" | grep "Tracking \"\*.jpg\"" |
| 420 | assert_attributes_count "jpg" "lockable" 1 |
| 421 | # track *.jpg again, don't change anything. Should retain lockable |
| 422 | git lfs track "*.jpg" | grep "\"*.jpg\" already supported" |
| 423 | assert_attributes_count "jpg" "lockable" 1 |
| 424 | |
| 425 | |
| 426 | # track *.png once, not lockable yet |
| 427 | git lfs track "*.png" | grep "Tracking \"\*.png\"" |
| 428 | assert_attributes_count "png" "filter=lfs" 1 |
| 429 | assert_attributes_count "png" "lockable" 0 |
| 430 | |
| 431 | # track png again, enable lockable, should replace |
| 432 | git lfs track --lockable "*.png" | grep "Tracking \"\*.png\"" |
| 433 | assert_attributes_count "png" "filter=lfs" 1 |
| 434 | assert_attributes_count "png" "lockable" 1 |
| 435 | |
| 436 | # track png again, disable lockable, should replace |
| 437 | git lfs track --not-lockable "*.png" | grep "Tracking \"\*.png\"" |
| 438 | assert_attributes_count "png" "filter=lfs" 1 |
| 439 | assert_attributes_count "png" "lockable" 0 |
| 440 | |
| 441 | # check output reflects lockable |
| 442 | out=$(git lfs track) |
| 443 | echo "$out" | grep "Listing tracked patterns" |
| 444 | echo "$out" | grep "*.jpg \[lockable\] (.gitattributes)" |
| 445 | echo "$out" | grep "*.png (.gitattributes)" |
| 446 | ) |
| 447 | end_test |
| 448 | |
| 449 | begin_test "track lockable read-only/read-write" |
| 450 | ( |
| 451 | set -e |
| 452 | |
| 453 | repo="track_lockable_ro_rw" |
| 454 | mkdir "$repo" |
| 455 | cd "$repo" |
| 456 | git init |
| 457 | |
| 458 | echo "blah blah" > test.bin |
| 459 | echo "foo bar" > test.dat |
| 460 | mkdir subfolder |
| 461 | echo "sub blah blah" > subfolder/test.bin |
| 462 | echo "sub foo bar" > subfolder/test.dat |
| 463 | git add *.bin *.dat subfolder |
| 464 | # should start writeable |
| 465 | assert_file_writeable test.bin |
| 466 | assert_file_writeable test.dat |
| 467 | assert_file_writeable subfolder/test.bin |
| 468 | assert_file_writeable subfolder/test.dat |
| 469 | |
| 470 | # track *.bin, not lockable yet |
| 471 | git lfs track "*.bin" | grep "Tracking \"\*.bin\"" |
| 472 | # track *.dat, lockable immediately |
| 473 | git lfs track --lockable "*.dat" | grep "Tracking \"\*.dat\"" |
| 474 | |
| 475 | # bin should remain writeable, dat should have been made read-only |
| 476 | |
| 477 | assert_file_writeable test.bin |
| 478 | refute_file_writeable test.dat |
| 479 | assert_file_writeable subfolder/test.bin |
| 480 | refute_file_writeable subfolder/test.dat |
| 481 | |
| 482 | git add .gitattributes test.bin test.dat |
| 483 | git commit -m "First commit" |
| 484 | |
| 485 | # bin should still be writeable |
| 486 | assert_file_writeable test.bin |
| 487 | assert_file_writeable subfolder/test.bin |
| 488 | # now make bin lockable |
| 489 | git lfs track --lockable "*.bin" | grep "Tracking \"\*.bin\"" |
| 490 | # bin should now be read-only |
| 491 | refute_file_writeable test.bin |
| 492 | refute_file_writeable subfolder/test.bin |
| 493 | |
| 494 | # remove lockable again |
| 495 | git lfs track --not-lockable "*.bin" | grep "Tracking \"\*.bin\"" |
| 496 | # bin should now be writeable again |
| 497 | assert_file_writeable test.bin |
| 498 | assert_file_writeable subfolder/test.bin |
| 499 | ) |
| 500 | end_test |
| 501 | |
| 502 | begin_test "track escaped pattern" |
| 503 | ( |
| 504 | set -e |
| 505 | |
| 506 | reponame="track-escaped-pattern" |
| 507 | git init "$reponame" |
| 508 | cd "$reponame" |
| 509 | |
| 510 | git lfs track " " | grep "Tracking \" \"" |
| 511 | assert_attributes_count "[[:space:]]" "filter=lfs" 1 |
| 512 | |
| 513 | git lfs track "#" | grep "Tracking \"#\"" |
| 514 | assert_attributes_count "\\#" "filter=lfs" 1 |
| 515 | ) |
| 516 | end_test |
| 517 | |
| 518 | begin_test "track (symlinked repository)" |
| 519 | ( |
| 520 | set -e |
| 521 | |
| 522 | reponame="tracked-symlinked-repository" |
| 523 | git init "$reponame" |
| 524 | cd "$reponame" |
| 525 | |
| 526 | touch a.dat |
| 527 | |
| 528 | pushd .. > /dev/null |
| 529 | dir="tracked-symlinked-repository-tmp" |
| 530 | |
| 531 | mkdir -p "$dir" |
| 532 | |
| 533 | ln -s "../$reponame" "./$dir" |
| 534 | |
| 535 | cd "$dir/$reponame" |
| 536 | |
| 537 | [ "Tracking \"a.dat\"" = "$(git lfs track "a.dat")" ] |
| 538 | [ "\"a.dat\" already supported" = "$(git lfs track "a.dat")" ] |
| 539 | popd > /dev/null |
| 540 | ) |
| 541 | end_test |
| 542 | |
| 543 | begin_test "track (\$GIT_LFS_TRACK_NO_INSTALL_HOOKS)" |
| 544 | ( |
| 545 | set -e |
| 546 | |
| 547 | reponame="track-no-setup-hooks" |
| 548 | git init "$reponame" |
| 549 | cd "$reponame" |
| 550 | |
| 551 | [ ! -f .git/hooks/pre-push ] |
| 552 | [ ! -f .git/hooks/post-checkout ] |
| 553 | [ ! -f .git/hooks/post-commit ] |
| 554 | [ ! -f .git/hooks/post-merge ] |
| 555 | |
| 556 | GIT_LFS_TRACK_NO_INSTALL_HOOKS=1 git lfs track |
| 557 | |
| 558 | [ ! -f .git/hooks/pre-push ] |
| 559 | [ ! -f .git/hooks/post-checkout ] |
| 560 | [ ! -f .git/hooks/post-commit ] |
| 561 | [ ! -f .git/hooks/post-merge ] |
| 562 | ) |
| 563 | end_test |
| 564 | |
| 565 | begin_test "track (with comments)" |
| 566 | ( |
| 567 | set -e |
| 568 | |
| 569 | reponame="track-with=comments" |
| 570 | git init "$reponame" |
| 571 | cd "$reponame" |
| 572 | |
| 573 | echo "*.jpg filter=lfs diff=lfs merge=lfs -text" >> .gitattributes |
| 574 | echo "# *.png filter=lfs diff=lfs merge=lfs -text" >> .gitattributes |
| 575 | echo "*.pdf filter=lfs diff=lfs merge=lfs -text" >> .gitattributes |
| 576 | |
| 577 | git add .gitattributes |
| 578 | git commit -m "initial commit" |
| 579 | |
| 580 | git lfs track 2>&1 | tee track.log |
| 581 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 582 | echo >&2 "expected \`git lfs track\` command to exit cleanly, didn't" |
| 583 | exit 1 |
| 584 | fi |
| 585 | |
| 586 | [ "1" -eq "$(grep -c "\.jpg" track.log)" ] |
| 587 | [ "1" -eq "$(grep -c "\.pdf" track.log)" ] |
| 588 | [ "0" -eq "$(grep -c "\.png" track.log)" ] |
| 589 | ) |
| 590 | end_test |
| 591 | |
| 592 | begin_test "track (with current-directory prefix)" |
| 593 | ( |
| 594 | set -e |
| 595 | |
| 596 | reponame="track-with-current-directory-prefix" |
| 597 | git init "$reponame" |
| 598 | cd "$reponame" |
| 599 | |
| 600 | git lfs track "./a.dat" |
| 601 | printf "a" > a.dat |
| 602 | |
| 603 | git add .gitattributes a.dat |
| 604 | git commit -m "initial commit" |
| 605 | |
| 606 | grep -e "^a.dat" .gitattributes |
| 607 | ) |
| 608 | end_test |
| 609 | |
| 610 | begin_test "track (global gitattributes)" |
| 611 | ( |
| 612 | set -e |
| 613 | |
| 614 | reponame="track-global-gitattributes" |
| 615 | git init "$reponame" |
| 616 | cd "$reponame" |
| 617 | |
| 618 | global="$(cd .. && pwd)/gitattributes-global" |
| 619 | |
| 620 | echo "*.dat filter=lfs diff=lfs merge=lfs -text" > "$global" |
| 621 | git config --local core.attributesfile "$global" |
| 622 | |
| 623 | git lfs track 2>&1 | tee track.log |
| 624 | grep "*.dat" track.log |
| 625 | ) |
| 626 | end_test |
| 627 | |
| 628 | begin_test "track (system gitattributes)" |
| 629 | ( |
| 630 | set -e |
| 631 | gitversion=$(git version | cut -d" " -f3) |
| 632 | set +e |
| 633 | compare_version "$gitversion" 2.42.0 |
| 634 | result=$? |
| 635 | set -e |
| 636 | # We no longer read the PREFIX variable as of Git 2.42.0. |
| 637 | [ "$result" -ne "$VERSION_LOWER" ] && exit 0 |
| 638 | |
| 639 | reponame="track-system-gitattributes" |
| 640 | git init "$reponame" |
| 641 | cd "$reponame" |
| 642 | |
| 643 | pushd "$TRASHDIR" > /dev/null |
| 644 | mkdir -p "prefix/${reponame}/etc" |
| 645 | cd "prefix/${reponame}/etc" |
| 646 | echo "*.dat filter=lfs diff=lfs merge=lfs -text" > gitattributes |
| 647 | popd > /dev/null |
| 648 | |
| 649 | PREFIX="${TRASHDIR}/prefix/${reponame}" git lfs track 2>&1 | tee track.log |
| 650 | grep "*.dat" track.log |
| 651 | ) |
| 652 | end_test |
| 653 | |
| 654 | begin_test "track: escaped pattern in .gitattributes" |
| 655 | ( |
| 656 | set -e |
| 657 | |
| 658 | reponame="track-escaped" |
| 659 | git init "$reponame" |
| 660 | cd "$reponame" |
| 661 | |
| 662 | filename="file with spaces.#" |
| 663 | |
| 664 | echo "I need escaping" > "$filename" |
| 665 | |
| 666 | [ "Tracking \"$filename\"" = "$(git lfs track "$filename")" ] |
| 667 | [ "\"$filename\" already supported" = "$(git lfs track "$filename")" ] |
| 668 | |
| 669 | #changing flags should track the file again |
| 670 | [ "Tracking \"$filename\"" = "$(git lfs track -l "$filename")" ] |
| 671 | |
| 672 | if [ 1 -ne "$(wc -l .gitattributes | awk '{ print $1 }')" ]; then |
| 673 | echo >&2 "changing flag for an existing tracked file shouldn't add another line" |
| 674 | exit 1 |
| 675 | fi |
| 676 | |
| 677 | [ "Tracking \"foo/bar/$filename\"" = "$(git lfs track "foo/bar/$filename")" ] |
| 678 | [ "\"foo/bar/$filename\" already supported" = "$(git lfs track "foo/bar/$filename")" ] |
| 679 | ) |
| 680 | end_test |
| 681 | |
| 682 | begin_test "track: escaped glob pattern in .gitattributes" |
| 683 | ( |
| 684 | set -e |
| 685 | |
| 686 | reponame="track-escaped-glob" |
| 687 | git init "$reponame" |
| 688 | cd "$reponame" |
| 689 | |
| 690 | filename='[foo]bar.txt' |
| 691 | contents='I need escaping' |
| 692 | contents_oid=$(calc_oid "$contents") |
| 693 | |
| 694 | git lfs track --filename "$filename" |
| 695 | git lfs track --filename "$filename" | grep 'already supported' |
| 696 | git add . |
| 697 | cat .gitattributes |
| 698 | |
| 699 | printf "%s" "$contents" > "$filename" |
| 700 | git add . |
| 701 | git commit -m 'Add unusually named file' |
| 702 | |
| 703 | # If Git understood our escaping, we'll have a pointer. Otherwise, we won't. |
| 704 | assert_pointer "main" "$filename" "$contents_oid" 15 |
| 705 | ) |
| 706 | end_test |
| 707 | |
| 708 | begin_test "track: escaped glob pattern with spaces in .gitattributes" |
| 709 | ( |
| 710 | set -e |
| 711 | |
| 712 | # None of these characters are valid in the Win32 subsystem. |
| 713 | [ "$IS_WINDOWS" -eq 1 ] && exit 0 |
| 714 | |
| 715 | reponame="track-escaped-glob-spaces" |
| 716 | git init "$reponame" |
| 717 | cd "$reponame" |
| 718 | |
| 719 | # Note that the \n is literally just that; it is not a newline. |
| 720 | filename='*[foo] \n bar?.txt' |
| 721 | contents='I need escaping' |
| 722 | contents_oid=$(calc_oid "$contents") |
| 723 | |
| 724 | git lfs track --filename "$filename" >output 2>&1 |
| 725 | # This error would occur if `git ls-files` didn't handle the backslash |
| 726 | # properly. |
| 727 | grep 'Error marking' output && exit 1 |
| 728 | rm -f output |
| 729 | git add . |
| 730 | cat .gitattributes |
| 731 | |
| 732 | printf "%s" "$contents" > "$filename" |
| 733 | git add . |
| 734 | git commit -m 'Add unusually named file' |
| 735 | |
| 736 | # If Git understood our escaping, we'll have a pointer. Otherwise, we won't. |
| 737 | assert_pointer "main" "$filename" "$contents_oid" 15 |
| 738 | ) |
| 739 | end_test |
| 740 | |
| 741 | begin_test "track: verbose logging" |
| 742 | ( |
| 743 | set -e |
| 744 | |
| 745 | reponame="track-verbose-logging" |
| 746 | git init "$reponame" |
| 747 | cd "$reponame" |
| 748 | |
| 749 | filename='[foo]bar.bin' |
| 750 | contents='I need escaping' |
| 751 | contents_oid=$(calc_oid "$contents") |
| 752 | |
| 753 | printf "%s" "$contents" > "$filename" |
| 754 | |
| 755 | printf 'Hello, world!\n' > a.txt |
| 756 | git add a.txt "$filename" |
| 757 | git commit -m 'some files' |
| 758 | |
| 759 | git lfs track -v "*.txt" 2>&1 | tee output |
| 760 | grep "Found 1 files previously added to Git matching pattern:" output |
| 761 | |
| 762 | git lfs track -v --filename "$filename" 2>&1 | tee output |
| 763 | grep "Found 1 files previously added to Git matching pattern:" output |
| 764 | ) |
| 765 | end_test |
| 766 | |
| 767 | begin_test "--json output" |
| 768 | ( |
| 769 | set -e |
| 770 | |
| 771 | reponame="track-json" |
| 772 | git init "$reponame" |
| 773 | cd "$reponame" |
| 774 | |
| 775 | git lfs track '*.dat' |
| 776 | git lfs track --lockable '*.bin' |
| 777 | echo 'a.dat !filter' >>.gitattributes |
| 778 | |
| 779 | git lfs track --json > actual |
| 780 | cat >expected <<-EOF |
| 781 | { |
| 782 | "patterns": [ |
| 783 | { |
| 784 | "pattern": "*.dat", |
| 785 | "source": ".gitattributes", |
| 786 | "lockable": false, |
| 787 | "tracked": true |
| 788 | }, |
| 789 | { |
| 790 | "pattern": "*.bin", |
| 791 | "source": ".gitattributes", |
| 792 | "lockable": true, |
| 793 | "tracked": true |
| 794 | }, |
| 795 | { |
| 796 | "pattern": "a.dat", |
| 797 | "source": ".gitattributes", |
| 798 | "lockable": false, |
| 799 | "tracked": false |
| 800 | } |
| 801 | ] |
| 802 | } |
| 803 | EOF |
| 804 | diff -u actual expected |
| 805 | ) |
| 806 | end_test |