| 1 | #!/usr/bin/env bash |
| 2 | # Test lfs capability to download data when blobs are stored in different |
| 3 | # endpoints |
| 4 | |
| 5 | . "$(dirname "$0")/testlib.sh" |
| 6 | |
| 7 | # This feature depends on the treeish parameter that is provided as metadata |
| 8 | # in git versions higher or equal than 2.27 |
| 9 | ensure_git_version_isnt $VERSION_LOWER "2.27.0" |
| 10 | |
| 11 | reponame="$(basename "$0" ".sh")" |
| 12 | |
| 13 | prepare_consumer() { |
| 14 | local consumer="$1" |
| 15 | mkdir "$consumer" |
| 16 | cd "$consumer" |
| 17 | git init |
| 18 | git remote add mr "file://$(urlify "$REMOTEDIR/$smain.git")" |
| 19 | git remote add fr "file://$(urlify "$REMOTEDIR/$sfork.git")" |
| 20 | git fetch mr |
| 21 | git fetch fr |
| 22 | } |
| 23 | |
| 24 | prepare_forks () { |
| 25 | local testcase="$1" |
| 26 | smain="$reponame"-"$testcase"-main-remote |
| 27 | sfork="$reponame"-"$testcase"-fork-remote |
| 28 | cmain="$HOME"/"$reponame"-"$testcase"-main-repo |
| 29 | cfork="$HOME"/"$reponame"-"$testcase"-fork-repo |
| 30 | setup_remote_repo "$smain" |
| 31 | setup_remote_repo "$sfork" |
| 32 | prepare_consumer "$cmain" |
| 33 | git checkout -b main |
| 34 | git lfs track '*.bin' |
| 35 | git add --all |
| 36 | git commit -m "Initial commit" |
| 37 | git push -u mr main |
| 38 | git push -u fr main |
| 39 | #Add a .bin in main repo |
| 40 | touch a.bin |
| 41 | printf "1234" > a.bin |
| 42 | git add --all |
| 43 | git commit -m "Add Bin file" |
| 44 | git push mr main |
| 45 | prepare_consumer "$cfork" |
| 46 | } |
| 47 | |
| 48 | exec_fail_git(){ |
| 49 | set +e |
| 50 | git "$@" |
| 51 | res=$? |
| 52 | set -e |
| 53 | if [ "$res" = "0" ]; then |
| 54 | exit 1 |
| 55 | fi |
| 56 | } |
| 57 | |
| 58 | begin_test "accept reset to different remote" |
| 59 | ( |
| 60 | set -e |
| 61 | prepare_forks "a-reset" |
| 62 | git checkout fr/main |
| 63 | git config lfs.remote.searchall false |
| 64 | git config lfs.remote.autodetect true |
| 65 | git reset --hard mr/main |
| 66 | ) |
| 67 | end_test |
| 68 | |
| 69 | begin_test "accept pull from different remote" |
| 70 | ( |
| 71 | set -e |
| 72 | prepare_forks "a-pull" |
| 73 | git checkout fr/main |
| 74 | git config lfs.remote.searchall false |
| 75 | git config lfs.remote.autodetect true |
| 76 | git pull mr main |
| 77 | ) |
| 78 | end_test |
| 79 | |
| 80 | begin_test "accept checkout different remote" |
| 81 | ( |
| 82 | set -e |
| 83 | prepare_forks "a-checkout" |
| 84 | git checkout fr/main |
| 85 | git config lfs.remote.searchall false |
| 86 | git config lfs.remote.autodetect true |
| 87 | git checkout mr/main |
| 88 | ) |
| 89 | end_test |
| 90 | |
| 91 | begin_test "accept rebase different remote" |
| 92 | ( |
| 93 | set -e |
| 94 | prepare_forks "a-rebase" |
| 95 | git checkout fr/main |
| 96 | git config lfs.remote.searchall false |
| 97 | git config lfs.remote.autodetect true |
| 98 | git rebase mr/main |
| 99 | ) |
| 100 | end_test |
| 101 | |
| 102 | begin_test "accept add bin file with sparsecheckout" |
| 103 | ( |
| 104 | set -e |
| 105 | prepare_forks "a-sparsecheckout" |
| 106 | git sparse-checkout init --no-cone |
| 107 | git sparse-checkout set /.gitignore |
| 108 | git checkout mr/main |
| 109 | git config lfs.remote.searchall false |
| 110 | git config lfs.remote.autodetect true |
| 111 | git sparse-checkout add a.bin |
| 112 | ) |
| 113 | end_test |
| 114 | |
| 115 | begin_test "accept cherry-pick head different remote" |
| 116 | ( |
| 117 | set -e |
| 118 | prepare_forks "a-cherrypick" |
| 119 | git checkout -b main --track fr/main |
| 120 | git config lfs.remote.searchall true |
| 121 | git config lfs.remote.autodetect false |
| 122 | git cherry-pick mr/main |
| 123 | ) |
| 124 | end_test |
| 125 | |
| 126 | begin_test "reject reset to different remote" |
| 127 | ( |
| 128 | set -e |
| 129 | prepare_forks "r-reset" |
| 130 | git checkout fr/main |
| 131 | git config lfs.remote.searchall false |
| 132 | git config lfs.remote.autodetect false |
| 133 | exec_fail_git reset --hard mr/main |
| 134 | ) |
| 135 | end_test |
| 136 | |
| 137 | begin_test "reject pull from different remote" |
| 138 | ( |
| 139 | set -e |
| 140 | prepare_forks "r-pull" |
| 141 | git checkout fr/main |
| 142 | git config lfs.remote.searchall false |
| 143 | git config lfs.remote.autodetect false |
| 144 | exec_fail_git pull mr main |
| 145 | ) |
| 146 | end_test |
| 147 | |
| 148 | begin_test "reject checkout different remote" |
| 149 | ( |
| 150 | set -e |
| 151 | prepare_forks "r-checkout" |
| 152 | git checkout fr/main |
| 153 | git config lfs.remote.searchall false |
| 154 | git config lfs.remote.autodetect false |
| 155 | exec_fail_git checkout mr/main |
| 156 | ) |
| 157 | end_test |
| 158 | |
| 159 | begin_test "reject rebase different remote" |
| 160 | ( |
| 161 | set -e |
| 162 | prepare_forks "r-rebase" |
| 163 | git checkout fr/main |
| 164 | git config lfs.remote.searchall false |
| 165 | git config lfs.remote.autodetect false |
| 166 | exec_fail_git rebase mr/main |
| 167 | ) |
| 168 | end_test |
| 169 | |
| 170 | begin_test "reject add bin file with sparsecheckout" |
| 171 | ( |
| 172 | set -e |
| 173 | prepare_forks "r-sparsecheckout" |
| 174 | git sparse-checkout init --no-cone |
| 175 | git sparse-checkout set /.gitignore |
| 176 | git checkout mr/main |
| 177 | git config lfs.remote.searchall false |
| 178 | git config lfs.remote.autodetect false |
| 179 | exec_fail_git sparse-checkout add a.bin |
| 180 | ) |
| 181 | end_test |
| 182 | |
| 183 | begin_test "reject cherry-pick head different remote" |
| 184 | ( |
| 185 | set -e |
| 186 | prepare_forks "r-cherrypick" |
| 187 | git checkout -b main --track fr/main |
| 188 | git config lfs.remote.searchall false |
| 189 | git config lfs.remote.autodetect false |
| 190 | exec_fail_git cherry-pick mr/main |
| 191 | ) |
| 192 | end_test |