1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
|
#!/usr/bin/env bash
# assert_ref_unmoved ensures that the previous and current SHA1 of a given ref
# is equal by string comparison:
#
# assert_ref_unmoved "HEAD" "$previous_sha" "$current_sha"
#
# If the two are unequal (the ref has moved), a message is printed to stderr and
# the program exits.
assert_ref_unmoved() {
local name="$1"
local prev_sha="$2"
local current_sha="$3"
if [ "$prev_sha" != "$current_sha" ]; then
echo >&2 "$name should not have moved (from: $prev_sha, to: $current_sha)"
exit 1
fi
}
# setup_local_branch_with_gitattrs creates a repository as follows:
#
# A---B
# \
# refs/heads/main
#
# - Commit 'A' has 120, in a.txt, and a corresponding entry in .gitattributes.
#
# If "0755" is passed as an argument, the .gitattributes file is created
# with that permissions mode.
# If "link" is passed as an argument, the .gitattributes file is created
# as a symlink to a gitattrs file.
setup_local_branch_with_gitattrs() {
set -e
reponame="migrate-single-local-branch-with-attrs"
remove_and_create_local_repo "$reponame"
lfstest-genrandom --base64 120 >a.txt
git add a.txt
git commit -m "initial commit"
git lfs track "*.txt"
git lfs track "*.other"
if [[ $1 == "0755" ]]; then
chmod +x .gitattributes
elif [[ $1 == "link" ]]; then
mv .gitattributes gitattrs
add_symlink gitattrs .gitattributes
git add gitattrs
fi
git add .gitattributes
git commit -m "add .gitattributes"
}
# setup_local_branch_with_nested_gitattrs creates a repository as follows:
#
# A---B
# \
# refs/heads/main
#
# - Commit 'A' has 120, in a.txt, and a corresponding entry in .gitattributes. There is also
# 140 in a.md, with no corresponding entry in .gitattributes.
# It also has 140 in subtree/a.md, and a corresponding entry in subtree/.gitattributes
setup_local_branch_with_nested_gitattrs() {
set -e
reponame="migrate-single-local-branch-nested-attrs"
remove_and_create_local_repo "$reponame"
mkdir b
lfstest-genrandom --base64 120 >a.txt
lfstest-genrandom --base64 140 >a.md
lfstest-genrandom --base64 140 >b/a.md
git add a.txt a.md b/a.md
git commit -m "initial commit"
git lfs track "*.txt"
git add .gitattributes
git commit -m "add .gitattributes"
cd b
git lfs track "*.md"
cd ..
git add b/.gitattributes
git commit -m "add nested .gitattributes"
}
# setup_single_local_branch_untracked creates a repository as follows:
#
# A---B
# \
# refs/heads/main
#
# - Commit 'A' has 120, in a.txt and 140 in a.md, with neither files tracked as
# pointers in Git LFS
setup_single_local_branch_untracked() {
set -e
local name="${1:-a.md}"
reponame="migrate-single-local-branch-untracked"
remove_and_create_local_repo "$reponame"
git commit --allow-empty -m "initial commit"
lfstest-genrandom --base64 120 >a.txt
lfstest-genrandom --base64 140 >"$name"
git add a.txt "$name"
git commit -m "add a.txt and $name"
}
# setup_single_local_branch_tracked creates a repository as follows:
#
# A---B
# \
# refs/heads/main
#
# - Commit 'A' has 120, in a.txt and 140 in a.md, with both files tracked as
# pointers in Git LFS
#
# If "0755" is passed as an argument, the .gitattributes file is created
# with that permissions mode.
# If "link" is passed as an argument, the .gitattributes file is created
# as a symlink to a gitattrs file.
setup_single_local_branch_tracked() {
set -e
reponame="migrate-single-local-branch-tracked"
remove_and_create_local_repo "$reponame"
echo "*.txt filter=lfs diff=lfs merge=lfs -text" > .gitattributes
echo "*.md filter=lfs diff=lfs merge=lfs -text" >> .gitattributes
if [[ $1 == "0755" ]]; then
chmod +x .gitattributes
fi
git add .gitattributes
git commit -m "initial commit"
lfstest-genrandom --base64 120 >a.txt
lfstest-genrandom --base64 140 >a.md
git add a.txt a.md
git commit -m "add a.{txt,md}"
if [[ $1 == "link" ]]; then
git mv .gitattributes gitattrs
add_symlink gitattrs .gitattributes
git commit -m "link .gitattributes"
fi
}
# setup_single_local_branch_complex_tracked creates a repository as follows:
#
# A
# \
# refs/heads/main
#
# - Commit 'A' has 1 byte of text in a.txt and dir/b.txt. According to the
# .gitattributes files, a.txt should be tracked using Git LFS, but b.txt should
# not be.
setup_single_local_branch_complex_tracked() {
set -e
reponame="migrate-single-local-branch-complex-tracked"
remove_and_create_local_repo "$reponame"
mkdir -p dir
echo "*.txt filter=lfs diff=lfs merge=lfs -text" > .gitattributes
echo "*.txt !filter !diff !merge" > dir/.gitattributes
printf "a" > a.txt
printf "b" > dir/b.txt
git lfs uninstall
git add .gitattributes dir/.gitattributes a.txt dir/b.txt
git commit -m "initial commit"
git lfs install
}
# setup_single_local_branch_tracked_corrupt creates a repository as follows:
#
# A
# \
# refs/heads/main
#
# - Commit 'A' has 120 bytes of random data in a.txt, and tracks *.txt under Git
# LFS, but a.txt is not stored as an LFS object.
#
# If "lfsmacro" is passed as an argument, a macro attribute definition
# which sets the LFS filter attribute is added to the .gitattributes file,
# and then referenced by the test file pattern attribute.
# If "macro" is passed as an argument, a macro attribute definition is
# added to the .gitattributes file.
# If "link" is passed as an argument, the .gitattributes file is created
# as a symlink to a gitattrs file.
setup_single_local_branch_tracked_corrupt() {
set -e
reponame="migrate-single-local-branch-with-attrs-corrupt"
remove_and_create_local_repo "$reponame"
git lfs uninstall
lfstest-genrandom --base64 120 >a.txt
if [[ $1 == "lfsmacro" ]]; then
printf '[attr]lfs filter=lfs diff=lfs merge=lfs -text\n*.txt lfs\n' \
>.gitattributes
else
echo "*.txt filter=lfs diff=lfs merge=lfs -text" > .gitattributes
if [[ $1 == "macro" ]]; then
echo "[attr]foo foo" >>.gitattributes
elif [[ $1 == "link" ]]; then
mv .gitattributes gitattrs
add_symlink gitattrs .gitattributes
fi
fi
git add .gitattributes a.txt
git commit -m "initial commit"
git lfs install
}
# setup_multiple_local_branches creates a repository as follows:
#
# B
# / \
# A refs/heads/my-feature
# \
# refs/heads/main
#
# - Commit 'A' has 120, 140 bytes of data in a.txt, and a.md, respectively.
#
# - Commit 'B' has 30 bytes of data in a.md, and includes commit 'A' as a
# parent.
setup_multiple_local_branches() {
set -e
reponame="migrate-info-multiple-local-branches"
remove_and_create_local_repo "$reponame"
lfstest-genrandom --base64 120 >a.txt
lfstest-genrandom --base64 140 >a.md
git add a.txt a.md
git commit -m "initial commit"
git checkout -b my-feature
lfstest-genrandom --base64 30 >a.md
git add a.md
git commit -m "add an additional 30 bytes to a.md"
git checkout main
}
# setup_multiple_local_branches_with_alternate_names performs the same task
# as setup_multiple_local_branches, but creates a file with no extension.
setup_multiple_local_branches_with_alternate_names() {
set -e
reponame="migrate-info-multiple-local-branches"
remove_and_create_local_repo "$reponame"
lfstest-genrandom --base64 120 >no_extension
lfstest-genrandom --base64 140 >a.txt
git add no_extension a.txt
git commit -m "initial commit"
git checkout -b my-feature
lfstest-genrandom --base64 30 >a.txt
lfstest-genrandom --base64 100 >no_extension
git add no_extension a.txt
git commit -m "add an additional 30 bytes to a.txt"
git checkout main
}
# setup_multiple_local_branches_with_gitattrs creates a repository in the same way
# as setup_multiple_local_branches, but also adds relevant lfs filters to the
# .gitattributes file in the main branch
setup_multiple_local_branches_with_gitattrs() {
set -e
setup_multiple_local_branches
git lfs track *.txt
git lfs track *.md
git add .gitattributes
git commit -m "add .gitattributes"
}
# setup_multiple_local_branches_non_standard creates a repository as follows:
#
# refs/pull/1/head
# /
# |
# B
# / \
# A refs/heads/my-feature
# |\
# | refs/heads/main
# \
# refs/pull/1/base
#
# With the same contents in 'A' and 'B' as setup_multiple_local_branches.
setup_multiple_local_branches_non_standard() {
set -e
setup_multiple_local_branches
git update-ref refs/pull/1/head "$(git rev-parse my-feature)"
git update-ref refs/pull/1/base "$(git rev-parse main)"
}
# setup_multiple_local_branches_tracked creates a repo with exactly the same
# structure as in setup_multiple_local_branches, but with all files tracked by
# Git LFS
setup_multiple_local_branches_tracked() {
set -e
reponame="migrate-info-multiple-local-branches"
remove_and_create_local_repo "$reponame"
echo "*.txt filter=lfs diff=lfs merge=lfs -text" > .gitattributes
echo "*.md filter=lfs diff=lfs merge=lfs -text" >> .gitattributes
git add .gitattributes
git commit -m "initial commit"
lfstest-genrandom --base64 120 >a.txt
lfstest-genrandom --base64 140 >a.md
git add a.txt a.md
git commit -m "add a.{txt,md}"
git checkout -b my-feature
lfstest-genrandom --base64 30 >a.md
git add a.md
git commit -m "add an additional 30 bytes to a.md"
git checkout main
}
# setup_local_branch_with_space creates a repository as follows:
#
# A
# \
# refs/heads/main
#
# - Commit 'A' has 50 bytes in a file named "a file.txt".
setup_local_branch_with_space() {
set -e
reponame="migrate-local-branch-with-space"
filename="a file.txt"
remove_and_create_local_repo "$reponame"
lfstest-genrandom --base64 50 >"$filename"
git add "$filename"
git commit -m "initial commit"
}
# setup_single_remote_branch creates a repository as follows:
#
# A---B
# \ \
# \ refs/heads/main
# \
# refs/remotes/origin/main
#
# - Commit 'A' has 120, 140 bytes of data in a.txt, and a.md, respectively. It
# is the latest commit pushed to the remote 'origin'.
#
# - Commit 'B' has 30, 50 bytes of data in a.txt, and a.md, respectively.
setup_single_remote_branch() {
set -e
reponame="migrate-info-single-remote-branch"
remove_and_create_remote_repo "$reponame"
lfstest-genrandom --base64 120 >a.txt
lfstest-genrandom --base64 140 >a.md
git add a.txt a.md
git commit -m "initial commit"
git push origin main
lfstest-genrandom --base64 30 >a.txt
lfstest-genrandom --base64 50 >a.md
git add a.md a.txt
git commit -m "add an additional 30, 50 bytes to a.{txt,md}"
}
setup_single_remote_branch_with_gitattrs() {
set -e
setup_single_remote_branch
git lfs track *.txt
git lfs track *.md
git add .gitattributes
git commit -m "add .gitattributes"
}
# Creates a repo identical to setup_single_remote_branch, except with *.md and
# *.txt files tracked by Git LFS
setup_single_remote_branch_tracked() {
set -e
reponame="migrate-info-single-remote-branch"
remove_and_create_remote_repo "$reponame"
git lfs track "*.md" "*.txt"
git add .gitattributes
git commit -m "initial commit"
lfstest-genrandom --base64 120 >a.txt
lfstest-genrandom --base64 140 >a.md
git add a.txt a.md
git commit -m "add a.{txt,md}"
git push origin main
lfstest-genrandom --base64 30 >a.txt
lfstest-genrandom --base64 50 >a.md
git add a.md a.txt
git commit -m "add an additional 30, 50 bytes to a.{txt,md}"
}
# setup_multiple_remote_branches creates a repository as follows:
#
# C
# / \
# A---B refs/heads/my-feature
# \ \
# \ refs/heads/main
# \
# refs/remotes/origin/main
#
# - Commit 'A' has 10, 11 bytes of data in a.txt, and a.md, respectively. It is
# the latest commit pushed to the remote 'origin'.
#
# - Commit 'B' has 20, 21 bytes of data in a.txt, and a.md, respectively.
#
# - Commit 'C' has 30, 31 bytes of data in a.txt, and a.md, respectively. It is
# the latest commit on refs/heads/my-feature.
setup_multiple_remote_branches() {
set -e
reponame="migrate-info-exclude-remote-refs-given-branch"
remove_and_create_remote_repo "$reponame"
lfstest-genrandom --base64 10 >a.txt
lfstest-genrandom --base64 11 >a.md
git add a.txt a.md
git commit -m "add 10, 11 bytes, a.{txt,md}"
git push origin main
lfstest-genrandom --base64 20 >a.txt
lfstest-genrandom --base64 21 >a.md
git add a.txt a.md
git commit -m "add 20, 21 bytes, a.{txt,md}"
git checkout -b my-feature
lfstest-genrandom --base64 30 >a.txt
lfstest-genrandom --base64 31 >a.md
git add a.txt a.md
git commit -m "add 30, 31 bytes, a.{txt,md}"
git checkout main
}
# Creates a repo identical to that in setup_multiple_remote_branches(), but
# with all files tracked by Git LFS
setup_multiple_remote_branches_gitattrs() {
set -e
reponame="migrate-info-exclude-remote-refs-given-branch"
remove_and_create_remote_repo "$reponame"
git lfs track "*.txt" "*.md"
git add .gitattributes
git commit -m "initial commit"
lfstest-genrandom --base64 10 >a.txt
lfstest-genrandom --base64 11 >a.md
git add a.txt a.md
git commit -m "add 10, 11 bytes, a.{txt,md}"
git push origin main
lfstest-genrandom --base64 20 >a.txt
lfstest-genrandom --base64 21 >a.md
git add a.txt a.md
git commit -m "add 20, 21 bytes, a.{txt,md}"
git checkout -b my-feature
lfstest-genrandom --base64 30 >a.txt
lfstest-genrandom --base64 31 >a.md
git add a.txt a.md
git commit -m "add 30, 31 bytes, a.{txt,md}"
git checkout main
}
# setup_single_local_branch_with_tags creates a repository as follows:
#
# A---B
# |\
# | refs/heads/main
# |
# \
# refs/tags/v1.0.0
#
# - Commit 'A' has 1 byte of data in 'a.txt'
# - Commit 'B' has 2 bytes of data in 'a.txt', and is tagged at 'v1.0.0'.
setup_single_local_branch_with_tags() {
set -e
reponame="migrate-single-local-branch-tags"
remove_and_create_local_repo "$reponame"
lfstest-genrandom --base64 1 >a.txt
git add a.txt
git commit -m "initial commit"
lfstest-genrandom --base64 2 >a.txt
git add a.txt
git commit -m "secondary commit"
git tag "v1.0.0"
}
# setup_single_local_branch_with_annotated_tags creates a repository as follows:
#
# A---B
# |\
# | refs/heads/main
# |
# \
# refs/tags/v1.0.0 (annotated)
#
# - Commit 'A' has 1 byte of data in 'a.txt'
# - Commit 'B' has 2 bytes of data in 'a.txt', and is tagged (with annotation)
# at 'v1.0.0'.
setup_single_local_branch_with_annotated_tags() {
set -e
reponame="migrate-single-local-branch-annotated-tags"
remove_and_create_local_repo "$reponame"
lfstest-genrandom --base64 1 >a.txt
git add a.txt
git commit -m "initial commit"
lfstest-genrandom --base64 2 >a.txt
git add a.txt
git commit -m "secondary commit"
git tag "v1.0.0" -m "v1.0.0"
}
setup_multiple_remotes() {
set -e
reponame="migrate-multiple-remotes"
remove_and_create_remote_repo "$reponame"
forkname="$(git remote -v \
| head -n1 \
| cut -d ' ' -f 1 \
| sed -e 's/^.*\///g')-fork"
( setup_remote_repo "$forkname" )
git remote add fork "$GITSERVER/$forkname"
lfstest-genrandom --base64 16 >a.txt
git add a.txt
git commit -m "initial commit"
git push origin main
lfstest-genrandom --base64 16 >a.txt
git add a.txt
git commit -m "another commit"
git push fork main
}
# setup_single_local_branch_deep_trees creates a repository as follows:
#
# A
# \
# refs/heads/main
#
# - Commit 'A' has 120 bytes of data in 'foo/bar/baz/a.txt'.
setup_single_local_branch_deep_trees() {
set -e
reponame="migrate-single-local-branch-with-deep-trees"
remove_and_create_local_repo "$reponame"
mkdir -p foo/bar/baz
lfstest-genrandom --base64 120 >foo/bar/baz/a.txt
git add foo/bar/baz/a.txt
git commit -m "initial commit"
}
# setup_single_local_branch_same_file_tree_ext creates a repository as follows:
#
# A
# \
# refs/heads/main
#
# - Commit 'A' has 120 bytes of data in each of 'a.txt`, `foo/a.txt',
# `bar.txt/b.md`, and `bar.txt/b.txt`.
setup_single_local_branch_same_file_tree_ext() {
set -e
reponame="migrate-single-local-branch-with-same-file-tree-ext"
remove_and_create_local_repo "$reponame"
mkdir -p foo bar.txt
lfstest-genrandom --base64 120 >a.txt
lfstest-genrandom --base64 120 >foo/a.txt
lfstest-genrandom --base64 120 >bar.txt/b.md
lfstest-genrandom --base64 120 >bar.txt/b.txt
git add a.txt foo bar.txt
git commit -m "initial commit"
}
# setup_local_branch_with_symlink creates a repository as follows:
#
# A
# \
# refs/heads/main
#
# - Commit 'A' has 120, in a.txt, and a symbolic link link.txt to a.txt.
setup_local_branch_with_symlink() {
set -e
reponame="migrate-single-local-branch-with-symlink"
remove_and_create_local_repo "$reponame"
lfstest-genrandom --base64 120 >a.txt
git add a.txt
git commit -m "initial commit"
add_symlink "a.txt" "link.txt"
git commit -m "add symlink"
}
# setup_local_branch_with_dirty_copy creates a repository as follows:
#
# A
# \
# refs/heads/main
#
# - Commit 'A' has the contents "a.txt in a.txt, and marks a.txt as unclean
# in the working copy.
setup_local_branch_with_dirty_copy() {
set -e
reponame="migrate-single-local-branch-with-dirty-copy"
remove_and_create_local_repo "$reponame"
printf "a.txt" > a.txt
git add a.txt
git commit -m "initial commit"
printf "2" >> a.txt
}
# setup_local_branch_with_copied_file creates a repository as follows:
#
# A
# \
# refs/heads/main
#
# - Commit 'A' has the contents "a.txt" in a.txt, and another identical file
# (same name and content) in another directory.
setup_local_branch_with_copied_file() {
set -e
reponame="migrate-single-local-branch-with-copied-file"
remove_and_create_local_repo "$reponame"
printf "a.txt" > a.txt
mkdir dir
cp a.txt dir/
git add a.txt dir/a.txt
git commit -m "initial commit"
}
# setup_local_branch_with_special_character_files creates a repository as follows:
#
# A
# \
# refs/heads/main
#
# - Commit 'A' has binary files with special characters
setup_local_branch_with_special_character_files() {
set -e
reponame="migrate-single-local-branch-with-special-filenames"
remove_and_create_local_repo "$reponame"
lfstest-genrandom 80 >'./test - special.bin'
lfstest-genrandom 100 >'./test (test2) special.bin'
# Windows does not allow creation of files with '*'
[ "$IS_WINDOWS" -eq '1' ] || lfstest-genrandom 120 >'./test * ** special.bin'
git add *.bin
git commit -m "initial commit"
}
# make_bare converts the existing full checkout of a repository into a bare one,
# and then `cd`'s into it.
make_bare() {
reponame=$(basename "$(pwd)")
mv .git "../$reponame.git"
cd ..
rm -rf "$reponame"
cd "$reponame.git"
git config --bool core.bare true
}
# remove_and_create_local_repo removes, creates, and checks out a local
# repository given by a particular name:
#
# remove_and_create_local_repo "$reponame"
remove_and_create_local_repo() {
local reponame="$1-$(lfstest-genrandom --base64url 32)"
git init "$reponame"
cd "$reponame"
}
# remove_and_create_remote_repo removes, creates, and checks out a remote
# repository both locally and on the gitserver, given by a particular name:
#
# remove_and_create_remote_repo "$reponame"
remove_and_create_remote_repo() {
local reponame="$1-$(lfstest-genrandom --base64url 32)"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
rm clone.log
}
|