| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "alternates (single)" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="alternates-single-alternate" |
| 10 | setup_remote_repo_with_file "$reponame" "a.txt" |
| 11 | |
| 12 | pushd "$TRASHDIR" > /dev/null |
| 13 | clone_repo "$reponame" "${reponame}_alternate" |
| 14 | popd > /dev/null |
| 15 | |
| 16 | rm -rf .git/lfs/objects |
| 17 | |
| 18 | alternate="$TRASHDIR/${reponame}_alternate/.git/objects" |
| 19 | echo "$(native_path "$alternate")" > .git/objects/info/alternates |
| 20 | |
| 21 | GIT_TRACE=1 git lfs fetch origin main 2>&1 | tee fetch.log |
| 22 | [ "0" -eq "$(grep -c "sending batch of size 1" fetch.log)" ] |
| 23 | ) |
| 24 | end_test |
| 25 | |
| 26 | begin_test "alternates (multiple)" |
| 27 | ( |
| 28 | set -e |
| 29 | |
| 30 | reponame="alternates-multiple-alternates" |
| 31 | setup_remote_repo_with_file "$reponame" "a.txt" |
| 32 | |
| 33 | pushd "$TRASHDIR" > /dev/null |
| 34 | clone_repo "$reponame" "${reponame}_alternate_stale" |
| 35 | rm -rf .git/lfs/objects |
| 36 | popd > /dev/null |
| 37 | pushd "$TRASHDIR" > /dev/null |
| 38 | clone_repo "$reponame" "${reponame}_alternate" |
| 39 | popd > /dev/null |
| 40 | |
| 41 | rm -rf .git/lfs/objects |
| 42 | |
| 43 | alternate_stale="$TRASHDIR/${reponame}_alternate_stale/.git/objects" |
| 44 | alternate="$TRASHDIR/${reponame}_alternate/.git/objects" |
| 45 | echo "$(native_path "$alternate")" > .git/objects/info/alternates |
| 46 | echo "$(native_path "$alternate_stale")" >> .git/objects/info/alternates |
| 47 | |
| 48 | GIT_TRACE=1 git lfs fetch origin main 2>&1 | tee fetch.log |
| 49 | [ "0" -eq "$(grep -c "sending batch of size 1" fetch.log)" ] |
| 50 | ) |
| 51 | end_test |
| 52 | |
| 53 | begin_test "alternates (commented)" |
| 54 | ( |
| 55 | set -e |
| 56 | |
| 57 | reponame="alternates-commented-alternate" |
| 58 | setup_remote_repo_with_file "$reponame" "a.txt" |
| 59 | |
| 60 | pushd "$TRASHDIR" > /dev/null |
| 61 | clone_repo "$reponame" "${reponame}_alternate" |
| 62 | popd > /dev/null |
| 63 | |
| 64 | rm -rf .git/lfs/objects |
| 65 | |
| 66 | alternate="$TRASHDIR/${reponame}_alternate/.git/objects" |
| 67 | echo "# $alternate" > .git/objects/info/alternates |
| 68 | |
| 69 | GIT_TRACE=1 git lfs fetch origin main 2>&1 | tee fetch.log |
| 70 | [ "1" -eq "$(grep -c "sending batch of size 1" fetch.log)" ] |
| 71 | ) |
| 72 | end_test |
| 73 | |
| 74 | begin_test "alternates (quoted)" |
| 75 | ( |
| 76 | set -e |
| 77 | |
| 78 | reponame="alternates-quoted-alternate" |
| 79 | setup_remote_repo_with_file "$reponame" "a.txt" |
| 80 | |
| 81 | pushd "$TRASHDIR" > /dev/null |
| 82 | clone_repo "$reponame" "${reponame}_alternate" |
| 83 | popd > /dev/null |
| 84 | |
| 85 | rm -rf .git/lfs/objects |
| 86 | |
| 87 | # Normally, a plain native_path call would be sufficient here, but when we |
| 88 | # use a quoted alternate, Git interprets backslash escapes, and Windows path |
| 89 | # names look like backslash escapes. As a consequence, we switch to forward |
| 90 | # slashes to avoid misinterpretation. |
| 91 | alternate=$(native_path "$TRASHDIR/${reponame}_alternate/.git/objects" | sed -e 's,\\,/,g') |
| 92 | echo "\"$alternate\"" > .git/objects/info/alternates |
| 93 | |
| 94 | GIT_TRACE=1 git lfs fetch origin main 2>&1 | tee fetch.log |
| 95 | [ "0" -eq "$(grep -c "sending batch of size 1" fetch.log)" ] |
| 96 | ) |
| 97 | end_test |
| 98 | |
| 99 | begin_test "alternates (OS environment, single)" |
| 100 | ( |
| 101 | set -e |
| 102 | |
| 103 | reponame="alternates-environment-single-alternate" |
| 104 | setup_remote_repo_with_file "$reponame" "a.txt" |
| 105 | |
| 106 | pushd "$TRASHDIR" > /dev/null |
| 107 | clone_repo "$reponame" "${reponame}_alternate" |
| 108 | popd > /dev/null |
| 109 | |
| 110 | rm -rf .git/lfs/objects |
| 111 | rm -rf .git/objects/* |
| 112 | git init |
| 113 | |
| 114 | alternate="$(native_path "$TRASHDIR/${reponame}_alternate/.git/objects")" |
| 115 | |
| 116 | GIT_ALTERNATE_OBJECT_DIRECTORIES="$alternate" \ |
| 117 | GIT_TRACE=1 \ |
| 118 | git lfs fetch origin main 2>&1 | tee fetch.log |
| 119 | [ "0" -eq "$(grep -c "sending batch of size 1" fetch.log)" ] |
| 120 | GIT_ALTERNATE_OBJECT_DIRECTORIES="$alternate" \ |
| 121 | git lfs push "$(git config remote.origin.url)" main |
| 122 | ) |
| 123 | end_test |
| 124 | |
| 125 | begin_test "alternates (OS environment, multiple)" |
| 126 | ( |
| 127 | set -e |
| 128 | |
| 129 | reponame="alternates-environment-multiple-alternates" |
| 130 | setup_remote_repo_with_file "$reponame" "a.txt" |
| 131 | |
| 132 | pushd "$TRASHDIR" > /dev/null |
| 133 | clone_repo "$reponame" "${reponame}_alternate_stale" |
| 134 | rm -rf .git/lfs/objects |
| 135 | popd > /dev/null |
| 136 | pushd "$TRASHDIR" > /dev/null |
| 137 | clone_repo "$reponame" "${reponame}_alternate" |
| 138 | popd > /dev/null |
| 139 | |
| 140 | rm -rf .git/lfs/objects |
| 141 | rm -rf .git/objects/* |
| 142 | git init |
| 143 | |
| 144 | alternate_stale="$(native_path "$TRASHDIR/${reponame}_alternate_stale/.git/objects")" |
| 145 | alternate="$(native_path "$TRASHDIR/${reponame}_alternate/.git/objects")" |
| 146 | sep="$(native_path_list_separator)" |
| 147 | |
| 148 | GIT_ALTERNATE_OBJECT_DIRECTORIES="$alternate_stale$sep$alternate" \ |
| 149 | GIT_TRACE=1 \ |
| 150 | git lfs fetch origin main 2>&1 | tee fetch.log |
| 151 | [ "0" -eq "$(grep -c "sending batch of size 1" fetch.log)" ] |
| 152 | GIT_ALTERNATE_OBJECT_DIRECTORIES="$alternate_stale$sep$alternate" \ |
| 153 | git lfs push "$(git config remote.origin.url)" main |
| 154 | ) |
| 155 | end_test |