git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
git / t / t5710-promisor-remote-capability.sh
| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='handling of promisor remote advertisement' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | if ! test_have_prereq PERL_TEST_HELPERS |
| 8 | then |
| 9 | skip_all='skipping promisor remote capabilities tests; Perl not available' |
| 10 | test_done |
| 11 | fi |
| 12 | |
| 13 | GIT_TEST_MULTI_PACK_INDEX=0 |
| 14 | GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL=0 |
| 15 | |
| 16 | # Setup the repository with three commits, this way HEAD is always |
| 17 | # available and we can hide commit 1 or 2. |
| 18 | test_expect_success 'setup: create "template" repository' ' |
| 19 | git init template && |
| 20 | test_commit -C template 1 && |
| 21 | test_commit -C template 2 && |
| 22 | test_commit -C template 3 && |
| 23 | test-tool genrandom foo 10k >template/foo && |
| 24 | git -C template add foo && |
| 25 | git -C template commit -m foo |
| 26 | ' |
| 27 | |
| 28 | # A bare repo will act as a server repo with unpacked objects. |
| 29 | test_expect_success 'setup: create bare "server" repository' ' |
| 30 | git clone --bare --no-local template server && |
| 31 | mv server/objects/pack/pack-* . && |
| 32 | packfile=$(ls pack-*.pack) && |
| 33 | git -C server unpack-objects --strict <"$packfile" |
| 34 | ' |
| 35 | |
| 36 | check_missing_objects () { |
| 37 | git -C "$1" rev-list --objects --all --missing=print > all.txt && |
| 38 | perl -ne 'print if s/^[?]//' all.txt >missing.txt && |
| 39 | test_line_count = "$2" missing.txt && |
| 40 | if test "$2" -lt 2 |
| 41 | then |
| 42 | test "$3" = "$(cat missing.txt)" |
| 43 | else |
| 44 | test -f "$3" && |
| 45 | sort <"$3" >expected_sorted && |
| 46 | sort <missing.txt >actual_sorted && |
| 47 | test_cmp expected_sorted actual_sorted |
| 48 | fi |
| 49 | } |
| 50 | |
| 51 | initialize_server () { |
| 52 | count="$1" |
| 53 | missing_oids="$2" |
| 54 | |
| 55 | # Repack everything first |
| 56 | git -C server -c repack.writebitmaps=false repack -a -d && |
| 57 | |
| 58 | # Remove promisor file in case they exist, useful when reinitializing |
| 59 | rm -rf server/objects/pack/*.promisor && |
| 60 | |
| 61 | # Repack without the largest object and create a promisor pack on server |
| 62 | git -C server -c repack.writebitmaps=false repack -a -d \ |
| 63 | --filter=blob:limit=5k --filter-to="$(pwd)/pack" && |
| 64 | promisor_file=$(ls server/objects/pack/*.pack | sed "s/\.pack/.promisor/") && |
| 65 | >"$promisor_file" && |
| 66 | |
| 67 | # Check objects missing on the server |
| 68 | check_missing_objects server "$count" "$missing_oids" |
| 69 | } |
| 70 | |
| 71 | copy_to_lop () { |
| 72 | oid_path="$(test_oid_to_path $1)" && |
| 73 | path="server/objects/$oid_path" && |
| 74 | path2="lop/objects/$oid_path" && |
| 75 | mkdir -p $(dirname "$path2") && |
| 76 | cp "$path" "$path2" |
| 77 | } |
| 78 | |
| 79 | # On Windows, `pwd` returns a path like 'D:/foo/bar'. Prepend '/' to turn |
| 80 | # it into '/D:/foo/bar', which is what git expects in file:// URLs on Windows. |
| 81 | # On Unix, the path already starts with '/', so this is a no-op. |
| 82 | pwd_path=$(pwd) |
| 83 | case "$pwd_path" in |
| 84 | [a-zA-Z]:*) pwd_path="/$pwd_path" ;; |
| 85 | esac |
| 86 | |
| 87 | # Allowed characters: alphanumeric, standard path/URI (_ . ~ / : -), |
| 88 | # and those percent-encoded below (% space = , ;) |
| 89 | rest=$(printf "%s" "$pwd_path" | tr -d 'a-zA-Z0-9_.~/:% =,;-') |
| 90 | if test -n "$rest" |
| 91 | then |
| 92 | skip_all="PWD contains unsupported special characters" |
| 93 | test_done |
| 94 | fi |
| 95 | |
| 96 | TRASH_DIRECTORY_URL="file://$pwd_path" |
| 97 | |
| 98 | encoded_path=$(printf "%s" "$pwd_path" | |
| 99 | sed -e 's/%/%25/g' -e 's/ /%20/g' -e 's/=/%3D/g' \ |
| 100 | -e 's/;/%3B/g' -e 's/,/%2C/g') |
| 101 | |
| 102 | ENCODED_TRASH_DIRECTORY_URL="file://$encoded_path" |
| 103 | |
| 104 | test_expect_success "setup for testing promisor remote advertisement" ' |
| 105 | # Create another bare repo called "lop" (for Large Object Promisor) |
| 106 | git init --bare lop && |
| 107 | |
| 108 | # Copy the largest object from server to lop |
| 109 | obj="HEAD:foo" && |
| 110 | oid="$(git -C server rev-parse $obj)" && |
| 111 | copy_to_lop "$oid" && |
| 112 | |
| 113 | initialize_server 1 "$oid" && |
| 114 | |
| 115 | # Configure lop as promisor remote for server |
| 116 | git -C server remote add lop "$TRASH_DIRECTORY_URL/lop" && |
| 117 | git -C server config remote.lop.promisor true && |
| 118 | |
| 119 | git -C lop config uploadpack.allowFilter true && |
| 120 | git -C lop config uploadpack.allowAnySHA1InWant true && |
| 121 | git -C server config uploadpack.allowFilter true && |
| 122 | git -C server config uploadpack.allowAnySHA1InWant true |
| 123 | ' |
| 124 | |
| 125 | test_expect_success "clone with promisor.advertise set to 'true'" ' |
| 126 | git -C server config promisor.advertise true && |
| 127 | test_when_finished "rm -rf client" && |
| 128 | |
| 129 | # Clone from server to create a client |
| 130 | GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 131 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 132 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 133 | -c promisor.acceptfromserver=All \ |
| 134 | --no-local --filter="blob:limit=5k" server client && |
| 135 | |
| 136 | # Check that the largest object is still missing on the server |
| 137 | check_missing_objects server 1 "$oid" |
| 138 | ' |
| 139 | |
| 140 | test_expect_success "clone with promisor.advertise set to 'false'" ' |
| 141 | git -C server config promisor.advertise false && |
| 142 | test_when_finished "rm -rf client" && |
| 143 | |
| 144 | # Clone from server to create a client |
| 145 | GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 146 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 147 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 148 | -c promisor.acceptfromserver=All \ |
| 149 | --no-local --filter="blob:limit=5k" server client && |
| 150 | |
| 151 | # Check that the largest object is not missing on the server |
| 152 | check_missing_objects server 0 "" && |
| 153 | |
| 154 | # Reinitialize server so that the largest object is missing again |
| 155 | initialize_server 1 "$oid" |
| 156 | ' |
| 157 | |
| 158 | test_expect_success "clone with promisor.acceptfromserver set to 'None'" ' |
| 159 | git -C server config promisor.advertise true && |
| 160 | test_when_finished "rm -rf client" && |
| 161 | |
| 162 | # Clone from server to create a client |
| 163 | GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 164 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 165 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 166 | -c promisor.acceptfromserver=None \ |
| 167 | --no-local --filter="blob:limit=5k" server client && |
| 168 | |
| 169 | # Check that the largest object is not missing on the server |
| 170 | check_missing_objects server 0 "" && |
| 171 | |
| 172 | # Reinitialize server so that the largest object is missing again |
| 173 | initialize_server 1 "$oid" |
| 174 | ' |
| 175 | |
| 176 | test_expect_success "clone with uploadpack.lazyFetchTrusted" ' |
| 177 | # No promisors are advertised |
| 178 | git -C server config promisor.advertise false && |
| 179 | test_when_finished "rm -rf client" && |
| 180 | |
| 181 | # The served repo is trusted for lazy fetching |
| 182 | test_config_global uploadpack.lazyFetchTrusted "$(pwd)/server" && |
| 183 | |
| 184 | # Clone without GIT_NO_LAZY_FETCH=0 |
| 185 | git clone --no-local --filter="blob:limit=5k" server client && |
| 186 | |
| 187 | # Check that the largest object is not missing on the server |
| 188 | # This means the server lazy fetched it |
| 189 | check_missing_objects server 0 "" && |
| 190 | |
| 191 | # Reinitialize server so that the largest object is missing again |
| 192 | initialize_server 1 "$oid" |
| 193 | ' |
| 194 | |
| 195 | test_expect_success "clone without uploadpack.lazyFetchTrusted fails" ' |
| 196 | # No promisors are advertised |
| 197 | git -C server config promisor.advertise false && |
| 198 | test_when_finished "rm -rf client" && |
| 199 | |
| 200 | # Note: no uploadpack.lazyFetchTrusted config is set here, so |
| 201 | # the served repo is NOT trusted for lazy fetching. |
| 202 | |
| 203 | # Clone without GIT_NO_LAZY_FETCH=0 fails |
| 204 | test_must_fail git clone --no-local --filter="blob:limit=5k" server client 2>err && |
| 205 | test_grep "lazy fetching disabled" err && |
| 206 | |
| 207 | # Check that the largest object is still missing on the server |
| 208 | check_missing_objects server 1 "$oid" |
| 209 | ' |
| 210 | |
| 211 | test_expect_success "uploadpack.lazyFetchTrusted is ignored in repo config" ' |
| 212 | # No promisors are advertised |
| 213 | git -C server config promisor.advertise false && |
| 214 | test_when_finished "rm -rf client" && |
| 215 | |
| 216 | # The served repo is trusted for lazy fetching, but this is |
| 217 | # done in the repo config, not in protected config, so this is |
| 218 | # ignored. |
| 219 | test_config -C server uploadpack.lazyFetchTrusted "$(pwd)/server" && |
| 220 | |
| 221 | # Clone without GIT_NO_LAZY_FETCH=0 fails |
| 222 | test_must_fail git clone --no-local --filter="blob:limit=5k" server client 2>err && |
| 223 | test_grep "lazy fetching disabled" err && |
| 224 | |
| 225 | # Check that the largest object is still missing on the server |
| 226 | check_missing_objects server 1 "$oid" |
| 227 | ' |
| 228 | |
| 229 | test_expect_success "explicit GIT_NO_LAZY_FETCH overrides uploadpack.lazyFetchTrusted" ' |
| 230 | # No promisors are advertised |
| 231 | git -C server config promisor.advertise false && |
| 232 | test_when_finished "rm -rf client" && |
| 233 | |
| 234 | # The served repo is trusted for lazy fetching |
| 235 | test_config_global uploadpack.lazyFetchTrusted "$(pwd)/server" && |
| 236 | |
| 237 | # But GIT_NO_LAZY_FETCH=1 disables lazy fetching, so clone fails |
| 238 | test_must_fail env GIT_NO_LAZY_FETCH=1 git clone --no-local \ |
| 239 | --filter="blob:limit=5k" server client 2>err && |
| 240 | test_grep "lazy fetching disabled" err && |
| 241 | |
| 242 | # Check that the largest object is still missing on the server |
| 243 | check_missing_objects server 1 "$oid" |
| 244 | ' |
| 245 | |
| 246 | test_expect_success "trusted repo as its own promisor remote does not recurse" ' |
| 247 | # No promisors are advertised |
| 248 | git -C server config promisor.advertise false && |
| 249 | test_when_finished "rm -rf client" && |
| 250 | |
| 251 | # Add itself as its own remote |
| 252 | git -C server remote add self "$TRASH_DIRECTORY_URL/server" && |
| 253 | git -C server config remote.self.promisor true && |
| 254 | test_when_finished "git -C server remote remove self" && |
| 255 | |
| 256 | # Make "self" the only promisor remote of the server, so that it |
| 257 | # cannot get the missing object from "lop". Note that |
| 258 | # "remote.lop.partialCloneFilter" also makes "lop" a promisor |
| 259 | # remote, so it has to be unset too. |
| 260 | git -C server config --unset remote.lop.promisor && |
| 261 | test_when_finished "git -C server config remote.lop.promisor true" && |
| 262 | lop_filter="$(git -C server config remote.lop.partialCloneFilter)" && |
| 263 | git -C server config --unset remote.lop.partialCloneFilter && |
| 264 | test_when_finished "git -C server config remote.lop.partialCloneFilter \"$lop_filter\"" && |
| 265 | |
| 266 | # Allow lazy fetching from itself |
| 267 | test_config_global uploadpack.lazyFetchTrusted "$(pwd)/server" && |
| 268 | |
| 269 | # Check that lazy fetching fails |
| 270 | test_must_fail git clone --no-local --filter="blob:limit=5k" server client 2>err && |
| 271 | test_grep "too many nested lazy fetches" err && |
| 272 | |
| 273 | # Check that the largest object is still missing on the server |
| 274 | check_missing_objects server 1 "$oid" |
| 275 | ' |
| 276 | |
| 277 | test_expect_success "uploadpack.lazyFetchTrusted needs the git dir of a non-bare repo" ' |
| 278 | test_when_finished "rm -rf nonbare nonbare-pack-* client client2" && |
| 279 | |
| 280 | # Create a non-bare repo, without any worktree content, so that |
| 281 | # its largest object can be filtered out below |
| 282 | git init nonbare && |
| 283 | git -C nonbare remote add origin "$TRASH_DIRECTORY_URL/template" && |
| 284 | git -C nonbare fetch origin && |
| 285 | git -C nonbare update-ref HEAD FETCH_HEAD && |
| 286 | |
| 287 | git -C nonbare remote add lop "$TRASH_DIRECTORY_URL/lop" && |
| 288 | git -C nonbare config remote.lop.promisor true && |
| 289 | git -C nonbare config uploadpack.allowFilter true && |
| 290 | git -C nonbare config uploadpack.allowAnySHA1InWant true && |
| 291 | git -C nonbare config promisor.advertise false && |
| 292 | |
| 293 | # Repack everything, then repack without the largest object and |
| 294 | # create a promisor pack, like initialize_server() does |
| 295 | git -C nonbare -c repack.writebitmaps=false repack -a -d && |
| 296 | rm -f nonbare/.git/objects/pack/*.promisor && |
| 297 | git -C nonbare -c repack.writebitmaps=false repack -a -d \ |
| 298 | --filter=blob:limit=5k --filter-to="$(pwd)/nonbare-pack" && |
| 299 | promisor_file=$(ls nonbare/.git/objects/pack/*.pack | sed "s/\.pack/.promisor/") && |
| 300 | >"$promisor_file" && |
| 301 | check_missing_objects nonbare 1 "$oid" && |
| 302 | |
| 303 | # The worktree path does not identify the repo, so it is not |
| 304 | # trusted and the clone fails |
| 305 | test_config_global uploadpack.lazyFetchTrusted "$(pwd)/nonbare" && |
| 306 | test_must_fail git clone --no-local --filter="blob:limit=1k" \ |
| 307 | nonbare client 2>err && |
| 308 | test_grep "lazy fetching disabled" err && |
| 309 | check_missing_objects nonbare 1 "$oid" && |
| 310 | |
| 311 | # The git dir identifies the repo, so it is trusted and the |
| 312 | # clone succeeds |
| 313 | test_config_global uploadpack.lazyFetchTrusted "$(pwd)/nonbare/.git" && |
| 314 | git clone --no-local --filter="blob:limit=1k" nonbare client2 && |
| 315 | check_missing_objects nonbare 0 "" |
| 316 | ' |
| 317 | |
| 318 | test_expect_success "uploadpack.lazyFetchTrusted needs the git dir a .git file points to" ' |
| 319 | test_when_finished "rm -rf sepwt sepgit sep-pack-* client client2" && |
| 320 | |
| 321 | # Create a non-bare repo with a ".git" file pointing to a |
| 322 | # separate git dir, without any worktree content, so that its |
| 323 | # largest object can be filtered out below |
| 324 | git init --separate-git-dir="$(pwd)/sepgit" sepwt && |
| 325 | test_path_is_file sepwt/.git && |
| 326 | git -C sepwt remote add origin "$TRASH_DIRECTORY_URL/template" && |
| 327 | git -C sepwt fetch origin && |
| 328 | git -C sepwt update-ref HEAD FETCH_HEAD && |
| 329 | |
| 330 | git -C sepwt remote add lop "$TRASH_DIRECTORY_URL/lop" && |
| 331 | git -C sepwt config remote.lop.promisor true && |
| 332 | git -C sepwt config uploadpack.allowFilter true && |
| 333 | git -C sepwt config uploadpack.allowAnySHA1InWant true && |
| 334 | git -C sepwt config promisor.advertise false && |
| 335 | |
| 336 | # Repack everything, then repack without the largest object and |
| 337 | # create a promisor pack, like initialize_server() does |
| 338 | git -C sepwt -c repack.writebitmaps=false repack -a -d && |
| 339 | rm -f sepgit/objects/pack/*.promisor && |
| 340 | git -C sepwt -c repack.writebitmaps=false repack -a -d \ |
| 341 | --filter=blob:limit=5k --filter-to="$(pwd)/sep-pack" && |
| 342 | promisor_file=$(ls sepgit/objects/pack/*.pack | sed "s/\.pack/.promisor/") && |
| 343 | >"$promisor_file" && |
| 344 | check_missing_objects sepwt 1 "$oid" && |
| 345 | |
| 346 | # The ".git" file does not identify the repo, so it is not |
| 347 | # trusted and the clone fails |
| 348 | test_config_global uploadpack.lazyFetchTrusted "$(pwd)/sepwt/.git" && |
| 349 | test_must_fail git clone --no-local --filter="blob:limit=1k" \ |
| 350 | sepwt client 2>err && |
| 351 | test_grep "lazy fetching disabled" err && |
| 352 | check_missing_objects sepwt 1 "$oid" && |
| 353 | |
| 354 | # The git dir the ".git" file points to identifies the repo, so |
| 355 | # it is trusted and the clone succeeds |
| 356 | test_config_global uploadpack.lazyFetchTrusted "$(pwd)/sepgit" && |
| 357 | git clone --no-local --filter="blob:limit=1k" sepwt client2 && |
| 358 | check_missing_objects sepwt 0 "" |
| 359 | ' |
| 360 | |
| 361 | test_expect_success "uploadpack.lazyFetchTrusted trust does not propagate to promisor remotes" ' |
| 362 | # No promisors are advertised |
| 363 | git -C server config promisor.advertise false && |
| 364 | test_when_finished "rm -rf client lop2" && |
| 365 | |
| 366 | # Create "lop2", a partial clone that is also missing the |
| 367 | # largest object, and that can lazily fetch it from "lop" |
| 368 | test_config -C template uploadpack.allowFilter true && |
| 369 | git clone --bare --no-local --filter="blob:limit=5k" \ |
| 370 | "$TRASH_DIRECTORY_URL/template" lop2 && |
| 371 | git -C lop2 remote set-url origin "$TRASH_DIRECTORY_URL/lop" && |
| 372 | git -C lop2 config uploadpack.allowFilter true && |
| 373 | git -C lop2 config uploadpack.allowAnySHA1InWant true && |
| 374 | check_missing_objects lop2 1 "$oid" && |
| 375 | |
| 376 | # Make "lop2" the only promisor remote of the server. Note that |
| 377 | # "remote.lop.partialCloneFilter" also makes "lop" a promisor |
| 378 | # remote, so it has to be unset too. |
| 379 | git -C server remote add lop2 "$TRASH_DIRECTORY_URL/lop2" && |
| 380 | git -C server config remote.lop2.promisor true && |
| 381 | test_when_finished "git -C server remote remove lop2" && |
| 382 | git -C server config --unset remote.lop.promisor && |
| 383 | test_when_finished "git -C server config remote.lop.promisor true" && |
| 384 | lop_filter="$(git -C server config remote.lop.partialCloneFilter)" && |
| 385 | git -C server config --unset remote.lop.partialCloneFilter && |
| 386 | test_when_finished "git -C server config remote.lop.partialCloneFilter \"$lop_filter\"" && |
| 387 | |
| 388 | # Only the server is trusted, not "lop2", so the upload-pack |
| 389 | # serving "lop2" to the server refuses to lazily fetch from "lop" |
| 390 | test_config_global uploadpack.lazyFetchTrusted "$(pwd)/server" && |
| 391 | test_must_fail git clone --no-local --filter="blob:limit=5k" \ |
| 392 | server client 2>err && |
| 393 | test_grep "lazy fetching disabled" err && |
| 394 | check_missing_objects server 1 "$oid" && |
| 395 | check_missing_objects lop2 1 "$oid" && |
| 396 | |
| 397 | # Once "lop2" is also trusted, the clone succeeds |
| 398 | git config --global --add uploadpack.lazyFetchTrusted "$(pwd)/lop2" && |
| 399 | git clone --no-local --filter="blob:limit=5k" server client && |
| 400 | check_missing_objects server 0 "" && |
| 401 | |
| 402 | # Reinitialize server so that the largest object is missing again |
| 403 | initialize_server 1 "$oid" |
| 404 | ' |
| 405 | |
| 406 | test_expect_success "init + fetch with promisor.advertise set to 'true'" ' |
| 407 | git -C server config promisor.advertise true && |
| 408 | test_when_finished "rm -rf client" && |
| 409 | |
| 410 | git init client && |
| 411 | git -C client config remote.lop.promisor true && |
| 412 | git -C client config remote.lop.fetch "+refs/heads/*:refs/remotes/lop/*" && |
| 413 | git -C client config remote.lop.url "$TRASH_DIRECTORY_URL/lop" && |
| 414 | git -C client config remote.server.url "$TRASH_DIRECTORY_URL/server" && |
| 415 | git -C client config remote.server.fetch "+refs/heads/*:refs/remotes/server/*" && |
| 416 | git -C client config promisor.acceptfromserver All && |
| 417 | GIT_NO_LAZY_FETCH=0 git -C client fetch --filter="blob:limit=5k" server && |
| 418 | |
| 419 | # Check that the largest object is still missing on the server |
| 420 | check_missing_objects server 1 "$oid" |
| 421 | ' |
| 422 | |
| 423 | test_expect_success "clone with two promisors but only one advertised" ' |
| 424 | git -C server config promisor.advertise true && |
| 425 | test_when_finished "rm -rf client unused_lop" && |
| 426 | |
| 427 | # Create a promisor that will be configured but not be used |
| 428 | git init --bare unused_lop && |
| 429 | |
| 430 | # Clone from server to create a client |
| 431 | GIT_TRACE="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \ |
| 432 | -c remote.unused_lop.promisor=true \ |
| 433 | -c remote.unused_lop.fetch="+refs/heads/*:refs/remotes/unused_lop/*" \ |
| 434 | -c remote.unused_lop.url="$TRASH_DIRECTORY_URL/unused_lop" \ |
| 435 | -c remote.lop.promisor=true \ |
| 436 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 437 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 438 | -c promisor.acceptfromserver=All \ |
| 439 | --no-local --filter="blob:limit=5k" server client && |
| 440 | |
| 441 | # Check that "unused_lop" appears before "lop" in the config |
| 442 | printf "remote.%s.promisor true\n" "unused_lop" "lop" "origin" >expect && |
| 443 | git -C client config get --all --show-names --regexp "^remote\..*\.promisor$" >actual && |
| 444 | test_cmp expect actual && |
| 445 | |
| 446 | # Check that "lop" was tried |
| 447 | test_grep " fetch lop " trace && |
| 448 | # Check that "unused_lop" was not contacted |
| 449 | # This means "lop", the accepted promisor, was tried first |
| 450 | test_grep ! " fetch unused_lop " trace && |
| 451 | |
| 452 | # Check that the largest object is still missing on the server |
| 453 | check_missing_objects server 1 "$oid" |
| 454 | ' |
| 455 | |
| 456 | test_expect_success "init + fetch two promisors but only one advertised" ' |
| 457 | git -C server config promisor.advertise true && |
| 458 | test_when_finished "rm -rf client unused_lop" && |
| 459 | |
| 460 | # Create a promisor that will be configured but not be used |
| 461 | git init --bare unused_lop && |
| 462 | |
| 463 | git init client && |
| 464 | git -C client config remote.unused_lop.promisor true && |
| 465 | git -C client config remote.unused_lop.fetch "+refs/heads/*:refs/remotes/unused_lop/*" && |
| 466 | git -C client config remote.unused_lop.url "$TRASH_DIRECTORY_URL/unused_lop" && |
| 467 | git -C client config remote.lop.promisor true && |
| 468 | git -C client config remote.lop.fetch "+refs/heads/*:refs/remotes/lop/*" && |
| 469 | git -C client config remote.lop.url "$TRASH_DIRECTORY_URL/lop" && |
| 470 | git -C client config remote.server.url "$TRASH_DIRECTORY_URL/server" && |
| 471 | git -C client config remote.server.fetch "+refs/heads/*:refs/remotes/server/*" && |
| 472 | git -C client config promisor.acceptfromserver All && |
| 473 | |
| 474 | # Check that "unused_lop" appears before "lop" in the config |
| 475 | printf "remote.%s.promisor true\n" "unused_lop" "lop" >expect && |
| 476 | git -C client config get --all --show-names --regexp "^remote\..*\.promisor$" >actual && |
| 477 | test_cmp expect actual && |
| 478 | |
| 479 | GIT_TRACE="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git -C client fetch --filter="blob:limit=5k" server && |
| 480 | |
| 481 | # Check that "lop" was tried |
| 482 | test_grep " fetch lop " trace && |
| 483 | # Check that "unused_lop" was not contacted |
| 484 | # This means "lop", the accepted promisor, was tried first |
| 485 | test_grep ! " fetch unused_lop " trace && |
| 486 | |
| 487 | # Check that the largest object is still missing on the server |
| 488 | check_missing_objects server 1 "$oid" |
| 489 | ' |
| 490 | |
| 491 | test_expect_success "clone with promisor.acceptfromserver set to 'KnownName'" ' |
| 492 | git -C server config promisor.advertise true && |
| 493 | test_when_finished "rm -rf client" && |
| 494 | |
| 495 | # Clone from server to create a client |
| 496 | GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 497 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 498 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 499 | -c promisor.acceptfromserver=KnownName \ |
| 500 | --no-local --filter="blob:limit=5k" server client && |
| 501 | |
| 502 | # Check that the largest object is still missing on the server |
| 503 | check_missing_objects server 1 "$oid" |
| 504 | ' |
| 505 | |
| 506 | test_expect_success "clone with 'KnownName' and different remote names" ' |
| 507 | git -C server config promisor.advertise true && |
| 508 | test_when_finished "rm -rf client" && |
| 509 | |
| 510 | # Clone from server to create a client |
| 511 | GIT_NO_LAZY_FETCH=0 git clone -c remote.serverTwo.promisor=true \ |
| 512 | -c remote.serverTwo.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 513 | -c remote.serverTwo.url="$TRASH_DIRECTORY_URL/lop" \ |
| 514 | -c promisor.acceptfromserver=KnownName \ |
| 515 | --no-local --filter="blob:limit=5k" server client && |
| 516 | |
| 517 | # Check that the largest object is not missing on the server |
| 518 | check_missing_objects server 0 "" && |
| 519 | |
| 520 | # Reinitialize server so that the largest object is missing again |
| 521 | initialize_server 1 "$oid" |
| 522 | ' |
| 523 | |
| 524 | test_expect_success "clone with 'KnownName' and missing URL in the config" ' |
| 525 | git -C server config promisor.advertise true && |
| 526 | test_when_finished "rm -rf client" && |
| 527 | |
| 528 | # Clone from server to create a client |
| 529 | # Lazy fetching by the client from the LOP will fail because of the |
| 530 | # missing URL in the client config, so the server will have to lazy |
| 531 | # fetch from the LOP. |
| 532 | GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 533 | -c promisor.acceptfromserver=KnownName \ |
| 534 | --no-local --filter="blob:limit=5k" server client && |
| 535 | |
| 536 | # Check that the largest object is not missing on the server |
| 537 | check_missing_objects server 0 "" && |
| 538 | |
| 539 | # Reinitialize server so that the largest object is missing again |
| 540 | initialize_server 1 "$oid" |
| 541 | ' |
| 542 | |
| 543 | test_expect_success "clone with promisor.acceptfromserver set to 'KnownUrl'" ' |
| 544 | git -C server config promisor.advertise true && |
| 545 | test_when_finished "rm -rf client" && |
| 546 | |
| 547 | # Clone from server to create a client |
| 548 | GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 549 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 550 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 551 | -c promisor.acceptfromserver=KnownUrl \ |
| 552 | --no-local --filter="blob:limit=5k" server client && |
| 553 | |
| 554 | # Check that the largest object is still missing on the server |
| 555 | check_missing_objects server 1 "$oid" |
| 556 | ' |
| 557 | |
| 558 | test_expect_success "clone with 'KnownUrl' and different remote urls" ' |
| 559 | ln -s lop serverTwo && |
| 560 | |
| 561 | git -C server config promisor.advertise true && |
| 562 | test_when_finished "rm -rf client" && |
| 563 | |
| 564 | # Clone from server to create a client |
| 565 | GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 566 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 567 | -c remote.lop.url="$TRASH_DIRECTORY_URL/serverTwo" \ |
| 568 | -c promisor.acceptfromserver=KnownUrl \ |
| 569 | --no-local --filter="blob:limit=5k" server client && |
| 570 | |
| 571 | # Check that the largest object is not missing on the server |
| 572 | check_missing_objects server 0 "" && |
| 573 | |
| 574 | # Reinitialize server so that the largest object is missing again |
| 575 | initialize_server 1 "$oid" |
| 576 | ' |
| 577 | |
| 578 | test_expect_success "clone with 'KnownUrl' and url not configured on the server" ' |
| 579 | git -C server config promisor.advertise true && |
| 580 | test_when_finished "rm -rf client" && |
| 581 | |
| 582 | test_when_finished "git -C server config set remote.lop.url \"$TRASH_DIRECTORY_URL/lop\"" && |
| 583 | git -C server config unset remote.lop.url && |
| 584 | |
| 585 | # Clone from server to create a client |
| 586 | # It should fail because the client will reject the LOP as URLs are |
| 587 | # different, and the server cannot lazy fetch as the LOP URL is |
| 588 | # missing, so the remote name will be used instead which will fail. |
| 589 | test_must_fail env GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 590 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 591 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 592 | -c promisor.acceptfromserver=KnownUrl \ |
| 593 | --no-local --filter="blob:limit=5k" server client && |
| 594 | |
| 595 | # Check that the largest object is still missing on the server |
| 596 | check_missing_objects server 1 "$oid" |
| 597 | ' |
| 598 | |
| 599 | test_expect_success "clone with 'KnownUrl' and empty url, so not advertised" ' |
| 600 | git -C server config promisor.advertise true && |
| 601 | test_when_finished "rm -rf client" && |
| 602 | |
| 603 | test_when_finished "git -C server config set remote.lop.url \"$TRASH_DIRECTORY_URL/lop\"" && |
| 604 | git -C server config set remote.lop.url "" && |
| 605 | |
| 606 | # Clone from server to create a client |
| 607 | # It should fail because the client will reject the LOP as an empty URL is |
| 608 | # not advertised, and the server cannot lazy fetch as the LOP URL is empty, |
| 609 | # so the remote name will be used instead which will fail. |
| 610 | test_must_fail env GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 611 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 612 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 613 | -c promisor.acceptfromserver=KnownUrl \ |
| 614 | --no-local --filter="blob:limit=5k" server client && |
| 615 | |
| 616 | # Check that the largest object is still missing on the server |
| 617 | check_missing_objects server 1 "$oid" |
| 618 | ' |
| 619 | |
| 620 | test_expect_success "clone with 'None' but URL allowlisted" ' |
| 621 | git -C server config promisor.advertise true && |
| 622 | test_when_finished "rm -rf client" && |
| 623 | |
| 624 | GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 625 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 626 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 627 | -c promisor.acceptfromserver=None \ |
| 628 | -c promisor.acceptFromServerUrl="$ENCODED_TRASH_DIRECTORY_URL/*" \ |
| 629 | --no-local --filter="blob:limit=5k" server client && |
| 630 | |
| 631 | # Check that the largest object is still missing on the server |
| 632 | check_missing_objects server 1 "$oid" |
| 633 | ' |
| 634 | |
| 635 | test_expect_success "clone with 'None' but URL not in allowlist" ' |
| 636 | git -C server config promisor.advertise true && |
| 637 | test_when_finished "rm -rf client" && |
| 638 | |
| 639 | GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 640 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 641 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 642 | -c promisor.acceptfromserver=None \ |
| 643 | -c promisor.acceptFromServerUrl="https://example.com/*" \ |
| 644 | --no-local --filter="blob:limit=5k" server client && |
| 645 | |
| 646 | # Check that the largest object is not missing on the server |
| 647 | check_missing_objects server 0 "" && |
| 648 | |
| 649 | # Reinitialize server so that the largest object is missing again |
| 650 | initialize_server 1 "$oid" |
| 651 | ' |
| 652 | |
| 653 | test_expect_success "clone with 'None' but URL allowlisted in one pattern out of two" ' |
| 654 | git -C server config promisor.advertise true && |
| 655 | test_when_finished "rm -rf client" && |
| 656 | |
| 657 | GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 658 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 659 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 660 | -c promisor.acceptfromserver=None \ |
| 661 | -c promisor.acceptFromServerUrl="https://example.com/*" \ |
| 662 | -c promisor.acceptFromServerUrl="$ENCODED_TRASH_DIRECTORY_URL/*" \ |
| 663 | --no-local --filter="blob:limit=5k" server client && |
| 664 | |
| 665 | # Check that the largest object is still missing on the server |
| 666 | check_missing_objects server 1 "$oid" |
| 667 | ' |
| 668 | |
| 669 | test_expect_success "clone with 'None', URL allowlisted, but client has different URL" ' |
| 670 | git -C server config promisor.advertise true && |
| 671 | test_when_finished "rm -rf client" && |
| 672 | |
| 673 | # The client configures "lop" with a different URL (serverTwo) than |
| 674 | # what the server advertises (lop). Even though the advertised URL |
| 675 | # matches the allowlist, the remote is rejected because the |
| 676 | # configured URL does not match the advertised one. |
| 677 | GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 678 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 679 | -c remote.lop.url="$TRASH_DIRECTORY_URL/serverTwo" \ |
| 680 | -c promisor.acceptfromserver=None \ |
| 681 | -c promisor.acceptFromServerUrl="$ENCODED_TRASH_DIRECTORY_URL/*" \ |
| 682 | --no-local --filter="blob:limit=5k" server client && |
| 683 | |
| 684 | # Check that the largest object is not missing on the server |
| 685 | check_missing_objects server 0 "" && |
| 686 | |
| 687 | # Reinitialize server so that the largest object is missing again |
| 688 | initialize_server 1 "$oid" |
| 689 | ' |
| 690 | |
| 691 | test_expect_success "clone with URL allowlisted and no remote already configured" ' |
| 692 | git -C server config promisor.advertise true && |
| 693 | test_when_finished "rm -rf client" && |
| 694 | test_when_finished "rm -f full_names" && |
| 695 | |
| 696 | GIT_NO_LAZY_FETCH=0 git clone \ |
| 697 | -c promisor.acceptfromserver=None \ |
| 698 | -c promisor.acceptFromServerUrl="$ENCODED_TRASH_DIRECTORY_URL/*" \ |
| 699 | --no-local --filter="blob:limit=5k" server client && |
| 700 | |
| 701 | # Check that exactly one remote has been auto-created, identified |
| 702 | # by "remote.<name>.advertisedAs" == "lop". |
| 703 | git -C client config get --all --show-names --regexp \ |
| 704 | "remote\..*\.advertisedas" >full_names && |
| 705 | test_line_count = 1 full_names && |
| 706 | REMOTE_NAME=$(sed "s/^remote\.\(.*\)\.advertisedas .*$/\1/" full_names) && |
| 707 | |
| 708 | # Check ".url" and ".promisor" values |
| 709 | printf "%s\n" "$TRASH_DIRECTORY_URL/lop" "true" >expect && |
| 710 | git -C client config "remote.$REMOTE_NAME.url" >actual && |
| 711 | git -C client config "remote.$REMOTE_NAME.promisor" >>actual && |
| 712 | test_cmp expect actual && |
| 713 | |
| 714 | # Check that the largest object is still missing on the server |
| 715 | check_missing_objects server 1 "$oid" |
| 716 | ' |
| 717 | |
| 718 | test_expect_success "clone with named URL allowlisted and no pre-configured remote" ' |
| 719 | git -C server config promisor.advertise true && |
| 720 | test_when_finished "rm -rf client" && |
| 721 | |
| 722 | GIT_NO_LAZY_FETCH=0 git clone \ |
| 723 | -c promisor.acceptfromserver=None \ |
| 724 | -c promisor.acceptFromServerUrl="cdn=$ENCODED_TRASH_DIRECTORY_URL/*" \ |
| 725 | --no-local --filter="blob:limit=5k" server client && |
| 726 | |
| 727 | # Check that a remote has been auto-created with the right "cdn" name and fields. |
| 728 | printf "%s\n" "$TRASH_DIRECTORY_URL/lop" "true" "lop" >expect && |
| 729 | git -C client config "remote.cdn.url" >actual && |
| 730 | git -C client config "remote.cdn.promisor" >>actual && |
| 731 | git -C client config "remote.cdn.advertisedAs" >>actual && |
| 732 | test_cmp expect actual && |
| 733 | |
| 734 | # Check that the largest object is still missing on the server |
| 735 | check_missing_objects server 1 "$oid" |
| 736 | ' |
| 737 | |
| 738 | test_expect_success "clone with URL allowlisted but colliding name" ' |
| 739 | git -C server config promisor.advertise true && |
| 740 | test_when_finished "rm -rf client" && |
| 741 | |
| 742 | GIT_NO_LAZY_FETCH=0 git clone -c remote.cdn.promisor=true \ |
| 743 | -c remote.cdn.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 744 | -c remote.cdn.url="https://example.com/cdn" \ |
| 745 | -c promisor.acceptfromserver=None \ |
| 746 | -c promisor.acceptFromServerUrl="cdn=$ENCODED_TRASH_DIRECTORY_URL/*" \ |
| 747 | --no-local --filter="blob:limit=5k" server client && |
| 748 | |
| 749 | # Check that a remote has been auto-created with the right "cdn-1" name and fields. |
| 750 | printf "%s\n" "$TRASH_DIRECTORY_URL/lop" "true" "lop" >expect && |
| 751 | git -C client config "remote.cdn-1.url" >actual && |
| 752 | git -C client config "remote.cdn-1.promisor" >>actual && |
| 753 | git -C client config "remote.cdn-1.advertisedAs" >>actual && |
| 754 | test_cmp expect actual && |
| 755 | |
| 756 | # Check that the original "cdn" remote was not overwritten. |
| 757 | printf "%s\n" "https://example.com/cdn" "true" >expect && |
| 758 | git -C client config "remote.cdn.url" >actual && |
| 759 | git -C client config "remote.cdn.promisor" >>actual && |
| 760 | test_cmp expect actual && |
| 761 | |
| 762 | # Check that the largest object is still missing on the server |
| 763 | check_missing_objects server 1 "$oid" |
| 764 | ' |
| 765 | |
| 766 | test_expect_success "clone with URL allowlisted and reusable remote" ' |
| 767 | git -C server config promisor.advertise true && |
| 768 | test_when_finished "rm -rf client" && |
| 769 | |
| 770 | GIT_NO_LAZY_FETCH=0 git clone \ |
| 771 | -c remote.cdn.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 772 | -c remote.cdn.url="$TRASH_DIRECTORY_URL/lop" \ |
| 773 | -c promisor.acceptfromserver=None \ |
| 774 | -c promisor.acceptFromServerUrl="cdn=$ENCODED_TRASH_DIRECTORY_URL/*" \ |
| 775 | --no-local --filter="blob:limit=5k" server client && |
| 776 | |
| 777 | # Check that the existing "cdn" remote has been properly updated. |
| 778 | printf "%s\n" "$TRASH_DIRECTORY_URL/lop" "true" "lop" "+refs/heads/*:refs/remotes/lop/*" >expect && |
| 779 | git -C client config "remote.cdn.url" >actual && |
| 780 | git -C client config "remote.cdn.promisor" >>actual && |
| 781 | git -C client config "remote.cdn.advertisedAs" >>actual && |
| 782 | git -C client config "remote.cdn.fetch" >>actual && |
| 783 | test_cmp expect actual && |
| 784 | |
| 785 | # Check that no new "cdn-1" remote has been created. |
| 786 | test_must_fail git -C client config "remote.cdn-1.url" && |
| 787 | |
| 788 | # Check that the largest object is still missing on the server |
| 789 | check_missing_objects server 1 "$oid" |
| 790 | ' |
| 791 | |
| 792 | test_expect_success "clone with invalid promisor.acceptFromServerUrl" ' |
| 793 | git -C server config promisor.advertise true && |
| 794 | test_when_finished "rm -rf client" && |
| 795 | |
| 796 | # As "bad name" contains a space, which is not a valid remote name, |
| 797 | # the pattern should be rejected with a warning and no remote created. |
| 798 | GIT_NO_LAZY_FETCH=0 git clone \ |
| 799 | -c promisor.acceptfromserver=None \ |
| 800 | -c "promisor.acceptFromServerUrl=bad name=https://example.com/*" \ |
| 801 | --no-local --filter="blob:limit=5k" server client 2>err && |
| 802 | |
| 803 | # Check that a warning was emitted |
| 804 | test_grep "invalid remote name '\''bad name'\''" err && |
| 805 | |
| 806 | # Check that no remote was auto-created |
| 807 | test_must_fail git -C client config get --regexp "remote\..*\.advertisedas" && |
| 808 | |
| 809 | # Check that the largest object is not missing on the server |
| 810 | check_missing_objects server 0 "" && |
| 811 | |
| 812 | # Reinitialize server so that the largest object is missing again |
| 813 | initialize_server 1 "$oid" |
| 814 | ' |
| 815 | |
| 816 | test_expect_success "clone with promisor.sendFields" ' |
| 817 | git -C server config promisor.advertise true && |
| 818 | test_when_finished "rm -rf client" && |
| 819 | |
| 820 | git -C server remote add otherLop "https://invalid.invalid" && |
| 821 | git -C server config remote.otherLop.token "fooBar" && |
| 822 | git -C server config remote.otherLop.stuff "baz" && |
| 823 | git -C server config remote.otherLop.partialCloneFilter "blob:limit=10k" && |
| 824 | test_when_finished "git -C server remote remove otherLop" && |
| 825 | test_config -C server promisor.sendFields "partialCloneFilter, token" && |
| 826 | test_when_finished "rm trace" && |
| 827 | |
| 828 | # Clone from server to create a client |
| 829 | GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \ |
| 830 | -c remote.lop.promisor=true \ |
| 831 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 832 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 833 | -c promisor.acceptfromserver=All \ |
| 834 | --no-local --filter="blob:limit=5k" server client && |
| 835 | |
| 836 | # Check that fields are properly transmitted |
| 837 | PR1="name=lop,url=$ENCODED_TRASH_DIRECTORY_URL/lop,partialCloneFilter=blob:none" && |
| 838 | PR2="name=otherLop,url=https://invalid.invalid,partialCloneFilter=blob:limit=10k,token=fooBar" && |
| 839 | test_grep "clone< promisor-remote=$PR1;$PR2" trace && |
| 840 | test_grep "clone> promisor-remote=lop;otherLop" trace && |
| 841 | |
| 842 | # Check that the largest object is still missing on the server |
| 843 | check_missing_objects server 1 "$oid" |
| 844 | ' |
| 845 | |
| 846 | test_expect_success "clone with promisor.checkFields" ' |
| 847 | git -C server config promisor.advertise true && |
| 848 | test_when_finished "rm -rf client" && |
| 849 | |
| 850 | git -C server remote add otherLop "https://invalid.invalid" && |
| 851 | git -C server config remote.otherLop.token "fooBar" && |
| 852 | git -C server config remote.otherLop.stuff "baz" && |
| 853 | git -C server config remote.otherLop.partialCloneFilter "blob:limit=10k" && |
| 854 | test_when_finished "git -C server remote remove otherLop" && |
| 855 | test_config -C server promisor.sendFields "partialCloneFilter, token" && |
| 856 | test_when_finished "rm trace" && |
| 857 | |
| 858 | # Clone from server to create a client |
| 859 | GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \ |
| 860 | -c remote.lop.promisor=true \ |
| 861 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 862 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 863 | -c remote.lop.partialCloneFilter="blob:none" \ |
| 864 | -c promisor.acceptfromserver=All \ |
| 865 | -c promisor.checkFields=partialcloneFilter \ |
| 866 | --no-local --filter="blob:limit=5k" server client && |
| 867 | |
| 868 | # Check that fields are properly transmitted |
| 869 | PR1="name=lop,url=$ENCODED_TRASH_DIRECTORY_URL/lop,partialCloneFilter=blob:none" && |
| 870 | PR2="name=otherLop,url=https://invalid.invalid,partialCloneFilter=blob:limit=10k,token=fooBar" && |
| 871 | test_grep "clone< promisor-remote=$PR1;$PR2" trace && |
| 872 | test_grep "clone> promisor-remote=lop" trace && |
| 873 | test_grep ! "clone> promisor-remote=lop;otherLop" trace && |
| 874 | |
| 875 | # Check that the largest object is still missing on the server |
| 876 | check_missing_objects server 1 "$oid" |
| 877 | ' |
| 878 | |
| 879 | test_expect_success "clone with promisor.storeFields=partialCloneFilter" ' |
| 880 | git -C server config promisor.advertise true && |
| 881 | test_when_finished "rm -rf client" && |
| 882 | |
| 883 | git -C server remote add otherLop "https://invalid.invalid" && |
| 884 | git -C server config remote.otherLop.token "fooBar" && |
| 885 | git -C server config remote.otherLop.stuff "baz" && |
| 886 | git -C server config remote.otherLop.partialCloneFilter "blob:limit=10k" && |
| 887 | test_when_finished "git -C server remote remove otherLop" && |
| 888 | |
| 889 | git -C server config remote.lop.token "fooXXX" && |
| 890 | git -C server config remote.lop.partialCloneFilter "blob:limit=8k" && |
| 891 | |
| 892 | test_config -C server promisor.sendFields "partialCloneFilter, token" && |
| 893 | test_when_finished "rm trace" && |
| 894 | |
| 895 | # Clone from server to create a client |
| 896 | GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \ |
| 897 | -c remote.lop.promisor=true \ |
| 898 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 899 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 900 | -c remote.lop.token="fooYYY" \ |
| 901 | -c remote.lop.partialCloneFilter="blob:none" \ |
| 902 | -c promisor.acceptfromserver=All \ |
| 903 | -c promisor.storeFields=partialcloneFilter \ |
| 904 | --no-local --filter="blob:limit=5k" server client 2>err && |
| 905 | |
| 906 | # Check that the filter from the server is stored |
| 907 | echo "blob:limit=8k" >expected && |
| 908 | git -C client config remote.lop.partialCloneFilter >actual && |
| 909 | test_cmp expected actual && |
| 910 | |
| 911 | # Check that user is notified when the filter is stored |
| 912 | test_grep "Storing new filter from server for remote '\''lop'\''" err && |
| 913 | test_grep "'\''blob:none'\'' -> '\''blob:limit=8k'\''" err && |
| 914 | |
| 915 | # Check that the token from the server is NOT stored |
| 916 | echo "fooYYY" >expected && |
| 917 | git -C client config remote.lop.token >actual && |
| 918 | test_cmp expected actual && |
| 919 | test_grep ! "Storing new token from server" err && |
| 920 | |
| 921 | # Check that the filter for an unknown remote is NOT stored |
| 922 | test_must_fail git -C client config remote.otherLop.partialCloneFilter >actual && |
| 923 | |
| 924 | # Check that the largest object is still missing on the server |
| 925 | check_missing_objects server 1 "$oid" && |
| 926 | |
| 927 | # Change the configuration on the server and fetch from the client |
| 928 | git -C server config remote.lop.partialCloneFilter "blob:limit=7k" && |
| 929 | GIT_NO_LAZY_FETCH=0 git -C client fetch \ |
| 930 | --filter="blob:limit=5k" ../server 2>err && |
| 931 | |
| 932 | # Check that the fetch updated the configuration on the client |
| 933 | echo "blob:limit=7k" >expected && |
| 934 | git -C client config remote.lop.partialCloneFilter >actual && |
| 935 | test_cmp expected actual && |
| 936 | |
| 937 | # Check that user is notified when the new filter is stored |
| 938 | test_grep "Storing new filter from server for remote '\''lop'\''" err && |
| 939 | test_grep "'\''blob:limit=8k'\'' -> '\''blob:limit=7k'\''" err |
| 940 | ' |
| 941 | |
| 942 | test_expect_success "clone and fetch with --filter=auto" ' |
| 943 | git -C server config promisor.advertise true && |
| 944 | test_when_finished "rm -rf client trace" && |
| 945 | |
| 946 | git -C server config remote.lop.partialCloneFilter "blob:limit=9500" && |
| 947 | test_config -C server promisor.sendFields "partialCloneFilter" && |
| 948 | |
| 949 | GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \ |
| 950 | -c remote.lop.promisor=true \ |
| 951 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 952 | -c promisor.acceptfromserver=All \ |
| 953 | --no-local --filter=auto server client 2>err && |
| 954 | |
| 955 | test_grep "filter blob:limit=9500" trace && |
| 956 | test_grep ! "filter auto" trace && |
| 957 | |
| 958 | # Verify "auto" is persisted in config |
| 959 | echo auto >expected && |
| 960 | git -C client config remote.origin.partialCloneFilter >actual && |
| 961 | test_cmp expected actual && |
| 962 | |
| 963 | # Check that the largest object is still missing on the server |
| 964 | check_missing_objects server 1 "$oid" && |
| 965 | |
| 966 | # Now change the filter on the server |
| 967 | git -C server config remote.lop.partialCloneFilter "blob:limit=5678" && |
| 968 | |
| 969 | # Get a new commit on the server to ensure "git fetch" actually runs fetch-pack |
| 970 | test_commit -C template new-commit && |
| 971 | git -C template push --all "$(pwd)/server" && |
| 972 | |
| 973 | # Perform a fetch WITH --filter=auto |
| 974 | rm -rf trace && |
| 975 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch --filter=auto && |
| 976 | |
| 977 | # Verify that the new filter was used |
| 978 | test_grep "filter blob:limit=5678" trace && |
| 979 | |
| 980 | # Check that the largest object is still missing on the server |
| 981 | check_missing_objects server 1 "$oid" && |
| 982 | |
| 983 | # Change the filter on the server again |
| 984 | git -C server config remote.lop.partialCloneFilter "blob:limit=5432" && |
| 985 | |
| 986 | # Get yet a new commit on the server to ensure fetch-pack runs |
| 987 | test_commit -C template yet-a-new-commit && |
| 988 | git -C template push --all "$(pwd)/server" && |
| 989 | |
| 990 | # Perform a fetch WITHOUT --filter=auto |
| 991 | # Relies on "auto" being persisted in the client config |
| 992 | rm -rf trace && |
| 993 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch && |
| 994 | |
| 995 | # Verify that the new filter was used |
| 996 | test_grep "filter blob:limit=5432" trace && |
| 997 | |
| 998 | # Check that the largest object is still missing on the server |
| 999 | check_missing_objects server 1 "$oid" |
| 1000 | ' |
| 1001 | |
| 1002 | test_expect_success "clone with promisor.advertise set to 'true' but don't delete the client" ' |
| 1003 | git -C server config promisor.advertise true && |
| 1004 | |
| 1005 | # Clone from server to create a client |
| 1006 | GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ |
| 1007 | -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ |
| 1008 | -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ |
| 1009 | -c promisor.acceptfromserver=All \ |
| 1010 | --no-local --filter="blob:limit=5k" server client && |
| 1011 | |
| 1012 | # Check that the largest object is still missing on the server |
| 1013 | check_missing_objects server 1 "$oid" |
| 1014 | ' |
| 1015 | |
| 1016 | test_expect_success "setup for subsequent fetches" ' |
| 1017 | # Generate new commit with large blob |
| 1018 | test-tool genrandom bar 10k >template/bar && |
| 1019 | git -C template add bar && |
| 1020 | git -C template commit -m bar && |
| 1021 | |
| 1022 | # Fetch new commit with large blob |
| 1023 | git -C server fetch origin && |
| 1024 | git -C server update-ref HEAD FETCH_HEAD && |
| 1025 | git -C server rev-parse HEAD >expected_head && |
| 1026 | |
| 1027 | # Repack everything twice and remove .promisor files before |
| 1028 | # each repack. This makes sure everything gets repacked |
| 1029 | # into a single packfile. The second repack is necessary |
| 1030 | # because the first one fetches from lop and creates a new |
| 1031 | # packfile and its associated .promisor file. |
| 1032 | |
| 1033 | rm -f server/objects/pack/*.promisor && |
| 1034 | git -C server -c repack.writebitmaps=false repack -a -d && |
| 1035 | rm -f server/objects/pack/*.promisor && |
| 1036 | git -C server -c repack.writebitmaps=false repack -a -d && |
| 1037 | |
| 1038 | # Unpack everything |
| 1039 | rm pack-* && |
| 1040 | mv server/objects/pack/pack-* . && |
| 1041 | packfile=$(ls pack-*.pack) && |
| 1042 | git -C server unpack-objects --strict <"$packfile" && |
| 1043 | |
| 1044 | # Copy new large object to lop |
| 1045 | obj_bar="HEAD:bar" && |
| 1046 | oid_bar="$(git -C server rev-parse $obj_bar)" && |
| 1047 | copy_to_lop "$oid_bar" && |
| 1048 | |
| 1049 | # Reinitialize server so that the 2 largest objects are missing |
| 1050 | printf "%s\n" "$oid" "$oid_bar" >expected_missing.txt && |
| 1051 | initialize_server 2 expected_missing.txt && |
| 1052 | |
| 1053 | # Create one more client |
| 1054 | cp -r client client2 |
| 1055 | ' |
| 1056 | |
| 1057 | test_expect_success "subsequent fetch from a client when promisor.advertise is true" ' |
| 1058 | git -C server config promisor.advertise true && |
| 1059 | |
| 1060 | GIT_NO_LAZY_FETCH=0 git -C client pull origin && |
| 1061 | |
| 1062 | git -C client rev-parse HEAD >actual && |
| 1063 | test_cmp expected_head actual && |
| 1064 | |
| 1065 | cat client/bar >/dev/null && |
| 1066 | |
| 1067 | check_missing_objects server 2 expected_missing.txt |
| 1068 | ' |
| 1069 | |
| 1070 | test_expect_success "subsequent fetch from a client when promisor.advertise is false" ' |
| 1071 | git -C server config promisor.advertise false && |
| 1072 | |
| 1073 | GIT_NO_LAZY_FETCH=0 git -C client2 pull origin && |
| 1074 | |
| 1075 | git -C client2 rev-parse HEAD >actual && |
| 1076 | test_cmp expected_head actual && |
| 1077 | |
| 1078 | cat client2/bar >/dev/null && |
| 1079 | |
| 1080 | check_missing_objects server 1 "$oid" |
| 1081 | ' |
| 1082 | |
| 1083 | test_done |