github.com/git-lfs/git-lfs@v2.5.2+incompatible/t/fixtures/migrate.sh (about) 1 #!/usr/bin/env bash 2 3 # assert_ref_unmoved ensures that the previous and current SHA1 of a given ref 4 # is equal by string comparison: 5 # 6 # assert_ref_unmoved "HEAD" "$previous_sha" "$current_sha" 7 # 8 # If the two are unequal (the ref has moved), a message is printed to stderr and 9 # the program exits. 10 assert_ref_unmoved() { 11 local name="$1" 12 local prev_sha="$2" 13 local current_sha="$3" 14 15 if [ "$prev_sha" != "$current_sha" ]; then 16 echo >&2 "$name should not have moved (from: $prev_sha, to: $current_sha)" 17 exit 1 18 fi 19 } 20 21 # setup_local_branch_with_gitattrs creates a repository as follows: 22 # 23 # A---B 24 # \ 25 # refs/heads/master 26 # 27 # - Commit 'A' has 120, in a.txt, and a corresponding entry in .gitattributes. 28 setup_local_branch_with_gitattrs() { 29 set -e 30 31 reponame="migrate-single-remote-branch-with-attrs" 32 33 remove_and_create_local_repo "$reponame" 34 35 base64 < /dev/urandom | head -c 120 > a.txt 36 37 git add a.txt 38 git commit -m "initial commit" 39 40 git lfs track "*.txt" 41 git lfs track "*.other" 42 43 git add .gitattributes 44 git commit -m "add .gitattributes" 45 } 46 47 # setup_local_branch_with_nested_gitattrs creates a repository as follows: 48 # 49 # A---B 50 # \ 51 # refs/heads/master 52 # 53 # - Commit 'A' has 120, in a.txt, and a corresponding entry in .gitattributes. There is also 54 # 140 in a.md, with no corresponding entry in .gitattributes. 55 # It also has 140 in subtree/a.md, and a corresponding entry in subtree/.gitattributes 56 setup_local_branch_with_nested_gitattrs() { 57 set -e 58 59 reponame="nested-attrs" 60 61 remove_and_create_local_repo "$reponame" 62 63 mkdir b 64 65 base64 < /dev/urandom | head -c 120 > a.txt 66 base64 < /dev/urandom | head -c 140 > a.md 67 base64 < /dev/urandom | head -c 140 > b/a.md 68 69 git add a.txt a.md b/a.md 70 git commit -m "initial commit" 71 72 git lfs track "*.txt" 73 74 git add .gitattributes 75 git commit -m "add .gitattributes" 76 77 cd b 78 79 git lfs track "*.md" 80 81 cd .. 82 83 git add b/.gitattributes 84 git commit -m "add nested .gitattributes" 85 } 86 87 # setup_single_local_branch_tracked creates a repository as follows: 88 # 89 # A---B 90 # \ 91 # refs/heads/master 92 # 93 # - Commit 'A' has 120, in a.txt and 140 in a.md, with both files tracked as 94 # pointers in Git LFS 95 setup_single_local_branch_tracked() { 96 set -e 97 98 reponame="migrate-single-remote-branch-with-attrs" 99 100 remove_and_create_local_repo "$reponame" 101 102 git lfs track "*.txt" "*.md" 103 104 git add .gitattributes 105 git commit -m "initial commit" 106 107 base64 < /dev/urandom | head -c 120 > a.txt 108 base64 < /dev/urandom | head -c 140 > a.md 109 110 git add a.txt a.md 111 git commit -m "add a.{txt,md}" 112 } 113 114 # setup_single_local_branch_complex_tracked creates a repository as follows: 115 # 116 # A 117 # \ 118 # refs/heads/master 119 # 120 # - Commit 'A' has 1 byte of text in a.txt and dir/b.txt. According to the 121 # .gitattributes files, a.txt should be tracked using Git LFS, but b.txt should 122 # not be. 123 setup_single_local_branch_complex_tracked() { 124 set -e 125 126 reponame="migrate-single-local-branch-complex-tracked" 127 128 remove_and_create_local_repo "$reponame" 129 130 mkdir -p dir 131 echo "*.txt filter=lfs diff=lfs merge=lfs -text" > .gitattributes 132 echo "*.txt !filter !diff !merge" > dir/.gitattributes 133 134 printf "a" > a.txt 135 printf "b" > dir/b.txt 136 137 git lfs uninstall 138 139 git add .gitattributes dir/.gitattributes a.txt dir/b.txt 140 git commit -m "initial commit" 141 142 git lfs install 143 } 144 145 # setup_single_local_branch_tracked_corrupt creates a repository as follows: 146 # 147 # A 148 # \ 149 # refs/heads/master 150 # 151 # - Commit 'A' has 120 bytes of random data in a.txt, and tracks *.txt under Git 152 # LFS, but a.txt is not stored as an LFS object. 153 setup_single_local_branch_tracked_corrupt() { 154 set -e 155 156 reponame="migrate-single-locla-branch-with-attrs-corrupt" 157 158 remove_and_create_local_repo "$reponame" 159 160 git lfs track "*.txt" 161 git lfs uninstall 162 163 base64 < /dev/urandom | head -c 120 > a.txt 164 165 git add .gitattributes a.txt 166 git commit -m "initial commit" 167 168 git lfs install 169 } 170 171 # setup_multiple_local_branches creates a repository as follows: 172 # 173 # B 174 # / \ 175 # A refs/heads/my-feature 176 # \ 177 # refs/heads/master 178 # 179 # - Commit 'A' has 120, 140 bytes of data in a.txt, and a.md, respectively. 180 # 181 # - Commit 'B' has 30 bytes of data in a.md, and includes commit 'A' as a 182 # parent. 183 setup_multiple_local_branches() { 184 set -e 185 186 reponame="migrate-info-multiple-local-branches" 187 188 remove_and_create_local_repo "$reponame" 189 190 base64 < /dev/urandom | head -c 120 > a.txt 191 base64 < /dev/urandom | head -c 140 > a.md 192 193 git add a.txt a.md 194 git commit -m "initial commit" 195 196 git checkout -b my-feature 197 198 base64 < /dev/urandom | head -c 30 > a.md 199 200 git add a.md 201 git commit -m "add an additional 30 bytes to a.md" 202 203 git checkout master 204 } 205 206 # setup_multiple_local_branches_with_gitattrs creates a repository in the same way 207 # as setup_multiple_local_branches, but also adds relevant lfs filters to the 208 # .gitattributes file in the master branch 209 setup_multiple_local_branches_with_gitattrs() { 210 set -e 211 212 setup_multiple_local_branches 213 214 git lfs track *.txt 215 git lfs track *.md 216 217 git add .gitattributes 218 git commit -m "add .gitattributes" 219 } 220 221 # setup_multiple_local_branches_non_standard creates a repository as follows: 222 # 223 # refs/pull/1/head 224 # / 225 # | 226 # B 227 # / \ 228 # A refs/heads/my-feature 229 # |\ 230 # | refs/heads/master 231 # \ 232 # refs/pull/1/base 233 # 234 # With the same contents in 'A' and 'B' as setup_multiple_local_branches. 235 setup_multiple_local_branches_non_standard() { 236 set -e 237 238 setup_multiple_local_branches 239 240 git update-ref refs/pull/1/head "$(git rev-parse my-feature)" 241 git update-ref refs/pull/1/base "$(git rev-parse master)" 242 } 243 244 # setup_multiple_local_branches_tracked creates a repo with exactly the same 245 # structure as in setup_multiple_local_branches, but with all files tracked by 246 # Git LFS 247 setup_multiple_local_branches_tracked() { 248 set -e 249 250 reponame="migrate-info-multiple-local-branches" 251 252 remove_and_create_local_repo "$reponame" 253 254 git lfs track "*.txt" "*.md" 255 git add .gitattributes 256 git commit -m "initial commit" 257 258 base64 < /dev/urandom | head -c 120 > a.txt 259 base64 < /dev/urandom | head -c 140 > a.md 260 261 git add a.txt a.md 262 git commit -m "add a.{txt,md}" 263 264 git checkout -b my-feature 265 266 base64 < /dev/urandom | head -c 30 > a.md 267 268 git add a.md 269 git commit -m "add an additional 30 bytes to a.md" 270 271 git checkout master 272 } 273 274 # setup_local_branch_with_space creates a repository as follows: 275 # 276 # A 277 # \ 278 # refs/heads/master 279 # 280 # - Commit 'A' has 50 bytes in a file named "a file.txt". 281 setup_local_branch_with_space() { 282 set -e 283 284 reponame="migrate-local-branch-with-space" 285 filename="a file.txt" 286 287 remove_and_create_local_repo "$reponame" 288 289 base64 < /dev/urandom | head -c 50 > "$filename" 290 291 git add "$filename" 292 git commit -m "initial commit" 293 } 294 295 # setup_single_remote_branch creates a repository as follows: 296 # 297 # A---B 298 # \ \ 299 # \ refs/heads/master 300 # \ 301 # refs/remotes/origin/master 302 # 303 # - Commit 'A' has 120, 140 bytes of data in a.txt, and a.md, respectively. It 304 # is the latest commit pushed to the remote 'origin'. 305 # 306 # - Commit 'B' has 30, 50 bytes of data in a.txt, and a.md, respectively. 307 setup_single_remote_branch() { 308 set -e 309 310 reponame="migrate-info-single-remote-branch" 311 312 remove_and_create_remote_repo "$reponame" 313 314 base64 < /dev/urandom | head -c 120 > a.txt 315 base64 < /dev/urandom | head -c 140 > a.md 316 317 git add a.txt a.md 318 git commit -m "initial commit" 319 320 git push origin master 321 322 base64 < /dev/urandom | head -c 30 > a.txt 323 base64 < /dev/urandom | head -c 50 > a.md 324 325 git add a.md a.txt 326 git commit -m "add an additional 30, 50 bytes to a.{txt,md}" 327 } 328 329 setup_single_remote_branch_with_gitattrs() { 330 set -e 331 332 setup_single_remote_branch 333 334 git lfs track *.txt 335 git lfs track *.md 336 337 git add .gitattributes 338 git commit -m "add .gitattributes" 339 } 340 341 # Creates a repo identical to setup_single_remote_branch, except with *.md and 342 # *.txt files tracked by Git LFS 343 setup_single_remote_branch_tracked() { 344 set -e 345 346 reponame="migrate-info-single-remote-branch" 347 348 remove_and_create_remote_repo "$reponame" 349 350 git lfs track "*.md" "*.txt" 351 git add .gitattributes 352 git commit -m "initial commit" 353 354 base64 < /dev/urandom | head -c 120 > a.txt 355 base64 < /dev/urandom | head -c 140 > a.md 356 357 git add a.txt a.md 358 git commit -m "add a.{txt,md}" 359 360 git push origin master 361 362 base64 < /dev/urandom | head -c 30 > a.txt 363 base64 < /dev/urandom | head -c 50 > a.md 364 365 git add a.md a.txt 366 git commit -m "add an additional 30, 50 bytes to a.{txt,md}" 367 } 368 369 # setup_multiple_remote_branches creates a repository as follows: 370 # 371 # C 372 # / \ 373 # A---B refs/heads/my-feature 374 # \ \ 375 # \ refs/heads/master 376 # \ 377 # refs/remotes/origin/master 378 # 379 # - Commit 'A' has 10, 11 bytes of data in a.txt, and a.md, respectively. It is 380 # the latest commit pushed to the remote 'origin'. 381 # 382 # - Commit 'B' has 20, 21 bytes of data in a.txt, and a.md, respectively. 383 # 384 # - Commit 'C' has 30, 31 bytes of data in a.txt, and a.md, respectively. It is 385 # the latest commit on refs/heads/my-feature. 386 setup_multiple_remote_branches() { 387 set -e 388 389 reponame="migrate-info-exclude-remote-refs-given-branch" 390 391 remove_and_create_remote_repo "$reponame" 392 393 base64 < /dev/urandom | head -c 10 > a.txt 394 base64 < /dev/urandom | head -c 11 > a.md 395 git add a.txt a.md 396 git commit -m "add 10, 11 bytes, a.{txt,md}" 397 398 git push origin master 399 400 base64 < /dev/urandom | head -c 20 > a.txt 401 base64 < /dev/urandom | head -c 21 > a.md 402 git add a.txt a.md 403 git commit -m "add 20, 21 bytes, a.{txt,md}" 404 405 git checkout -b my-feature 406 407 base64 < /dev/urandom | head -c 30 > a.txt 408 base64 < /dev/urandom | head -c 31 > a.md 409 git add a.txt a.md 410 git commit -m "add 30, 31 bytes, a.{txt,md}" 411 412 git checkout master 413 } 414 415 # Creates a repo identical to that in setup_multiple_remote_branches(), but 416 # with all files tracked by Git LFS 417 setup_multiple_remote_branches_gitattrs() { 418 set -e 419 420 reponame="migrate-info-exclude-remote-refs-given-branch" 421 422 remove_and_create_remote_repo "$reponame" 423 424 git lfs track "*.txt" "*.md" 425 git add .gitattributes 426 git commit -m "initial commit" 427 428 base64 < /dev/urandom | head -c 10 > a.txt 429 base64 < /dev/urandom | head -c 11 > a.md 430 git add a.txt a.md 431 git commit -m "add 10, 11 bytes, a.{txt,md}" 432 433 git push origin master 434 435 base64 < /dev/urandom | head -c 20 > a.txt 436 base64 < /dev/urandom | head -c 21 > a.md 437 git add a.txt a.md 438 git commit -m "add 20, 21 bytes, a.{txt,md}" 439 440 git checkout -b my-feature 441 442 base64 < /dev/urandom | head -c 30 > a.txt 443 base64 < /dev/urandom | head -c 31 > a.md 444 git add a.txt a.md 445 git commit -m "add 30, 31 bytes, a.{txt,md}" 446 447 git checkout master 448 } 449 450 # setup_single_local_branch_with_tags creates a repository as follows: 451 # 452 # A---B 453 # |\ 454 # | refs/heads/master 455 # | 456 # \ 457 # refs/tags/v1.0.0 458 # 459 # - Commit 'A' has 1 byte of data in 'a.txt' 460 # - Commit 'B' has 2 bytes of data in 'a.txt', and is tagged at 'v1.0.0'. 461 setup_single_local_branch_with_tags() { 462 set -e 463 464 reponame="migrate-single-local-branch-tags" 465 466 remove_and_create_local_repo "$reponame" 467 468 base64 < /dev/urandom | head -c 1 > a.txt 469 470 git add a.txt 471 git commit -m "initial commit" 472 473 base64 < /dev/urandom | head -c 2 > a.txt 474 475 git add a.txt 476 git commit -m "secondary commit" 477 git tag "v1.0.0" 478 } 479 480 # setup_single_local_branch_with_annotated_tags creates a repository as follows: 481 # 482 # A---B 483 # |\ 484 # | refs/heads/master 485 # | 486 # \ 487 # refs/tags/v1.0.0 (annotated) 488 # 489 # - Commit 'A' has 1 byte of data in 'a.txt' 490 # - Commit 'B' has 2 bytes of data in 'a.txt', and is tagged (with annotation) 491 # at 'v1.0.0'. 492 setup_single_local_branch_with_annotated_tags() { 493 set -e 494 495 reponame="migrate-single-local-branch-annotated-tags" 496 497 remove_and_create_local_repo "$reponame" 498 499 base64 < /dev/urandom | head -c 1 > a.txt 500 501 git add a.txt 502 git commit -m "initial commit" 503 504 base64 < /dev/urandom | head -c 2 > a.txt 505 506 git add a.txt 507 git commit -m "secondary commit" 508 git tag "v1.0.0" -m "v1.0.0" 509 } 510 511 setup_multiple_remotes() { 512 set -e 513 514 reponame="migrate-multiple-remotes" 515 remove_and_create_remote_repo "$reponame" 516 517 forkname="$(git remote -v \ 518 | head -n1 \ 519 | cut -d ' ' -f 1 \ 520 | sed -e 's/^.*\///g')-fork" 521 ( setup_remote_repo "$forkname" ) 522 523 git remote add fork "$GITSERVER/$forkname" 524 525 base64 < /dev/urandom | head -c 16 > a.txt 526 git add a.txt 527 git commit -m "initial commit" 528 git push origin master 529 530 base64 < /dev/urandom | head -c 16 > a.txt 531 git add a.txt 532 git commit -m "another commit" 533 git push fork master 534 } 535 536 # setup_single_local_branch_deep_trees creates a repository as follows: 537 # 538 # A 539 # \ 540 # refs/heads/master 541 # 542 # - Commit 'A' has 120 bytes of data in 'foo/bar/baz/a.txt'. 543 setup_single_local_branch_deep_trees() { 544 set -e 545 546 reponame="migrate-single-local-branch-with-deep-trees" 547 remove_and_create_local_repo "$reponame" 548 549 mkdir -p foo/bar/baz 550 base64 < /dev/urandom | head -c 120 > foo/bar/baz/a.txt 551 552 git add foo/bar/baz/a.txt 553 git commit -m "initial commit" 554 } 555 556 # setup_local_branch_with_symlink creates a repository as follows: 557 # 558 # A 559 # \ 560 # refs/heads/master 561 # 562 # - Commit 'A' has 120, in a.txt, and a symbolic link link.txt to a.txt. 563 setup_local_branch_with_symlink() { 564 set -e 565 566 reponame="migrate-single-local-branch-with-symlink" 567 568 remove_and_create_local_repo "$reponame" 569 570 base64 < /dev/urandom | head -c 120 > a.txt 571 572 git add a.txt 573 git commit -m "initial commit" 574 575 add_symlink "a.txt" "link.txt" 576 git commit -m "add symlink" 577 } 578 579 # setup_local_branch_with_dirty_copy creates a repository as follows: 580 # 581 # A 582 # \ 583 # refs/heads/master 584 # 585 # - Commit 'A' has the contents "a.txt in a.txt, and marks a.txt as unclean 586 # in the working copy. 587 setup_local_branch_with_dirty_copy() { 588 set -e 589 590 reponame="migrate-single-local-branch-with-dirty-copy" 591 remove_and_create_local_repo "$reponame" 592 593 printf "a.txt" > a.txt 594 595 git add a.txt 596 git commit -m "initial commit" 597 598 printf "2" >> a.txt 599 } 600 601 # make_bare converts the existing full checkout of a repository into a bare one, 602 # and then `cd`'s into it. 603 make_bare() { 604 reponame=$(basename "$(pwd)") 605 mv .git "../$reponame.git" 606 607 cd .. 608 609 rm -rf "$reponame" 610 cd "$reponame.git" 611 612 git config --bool core.bare true 613 } 614 615 # remove_and_create_local_repo removes, creates, and checks out a local 616 # repository given by a particular name: 617 # 618 # remove_and_create_local_repo "$reponame" 619 remove_and_create_local_repo() { 620 local reponame="$(base64 < /dev/urandom | head -c 8 | $SHASUM | cut -f 1 -d ' ')-$1" 621 622 git init "$reponame" 623 cd "$reponame" 624 } 625 626 # remove_and_create_remote_repo removes, creates, and checks out a remote 627 # repository both locally and on the gitserver, given by a particular name: 628 # 629 # remove_and_create_remote_repo "$reponame" 630 remove_and_create_remote_repo() { 631 local reponame="$(base64 < /dev/urandom | head -c 8 | $SHASUM | cut -f 1 -d ' ')-$1" 632 633 setup_remote_repo "$reponame" 634 clone_repo "$reponame" "$reponame" 635 636 rm clone.log 637 }