Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t5703-upload-pack-ref-in-want.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t5703-upload-pack-ref-in-want.sh` 558 lines ยท 14877 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='upload-pack ref-in-want' 4 5 . ./test-lib.sh 6 7 get_actual_refs () { 8 sed -n -e '/wanted-refs/,/0001/{ 9 /wanted-refs/d 10 /0001/d 11 p 12 }' actual_refs 13 } 14 15 get_actual_commits () { 16 test-tool pkt-line unpack-sideband o.pack && 17 git index-pack o.pack && 18 git verify-pack -v o.idx >objs && 19 sed -n -e 's/\([0-9a-f][0-9a-f]*\) commit .*/\1/p' objs >objs.sed && 20 sort >actual_commits sorted_commits && 28 test_cmp sorted_commits actual_commits 29 } 30 31 write_command () { 32 echo "command=$1" 33 34 if test "$(test_oid algo)" != sha1 35 then 36 echo "object-format=$(test_oid algo)" 37 fi 38 } 39 40 # Write a complete fetch command to stdout, suitable for use with `test-tool 41 # pkt-line`. "want-ref", "want", and "have" lines are read from stdin. 42 # 43 # Examples: 44 # 45 # write_fetch_command <<-EOF 46 # want-ref refs/heads/main 47 # have $(git rev-parse a) 48 # EOF 49 # 50 # write_fetch_command <<-EOF 51 # want $(git rev-parse b) 52 # have $(git rev-parse a) 53 # EOF 54 # 55 write_fetch_command () { 56 write_command fetch && 57 echo "0001" && 58 echo "no-progress" && 59 cat && 60 echo "done" && 61 echo "0000" 62 } 63 64 # c(o/foo) d(o/bar) 65 # \ / 66 # b e(baz) f(main) 67 # \__ | __/ 68 # \ | / 69 # a 70 test_expect_success 'setup repository' ' 71 test_commit a && 72 git branch -M main && 73 git checkout -b o/foo && 74 test_commit b && 75 test_commit c && 76 git checkout -b o/bar b && 77 test_commit d && 78 git checkout -b baz a && 79 test_commit e && 80 git checkout main && 81 test_commit f 82 ' 83 84 test_expect_success 'config controls ref-in-want advertisement' ' 85 test-tool serve-v2 --advertise-capabilities >out && 86 test_grep ! "ref-in-want" out && 87 88 git config uploadpack.allowRefInWant false && 89 test-tool serve-v2 --advertise-capabilities >out && 90 test_grep ! "ref-in-want" out && 91 92 git config uploadpack.allowRefInWant true && 93 test-tool serve-v2 --advertise-capabilities >out && 94 test_grep "ref-in-want" out 95 ' 96 97 test_expect_success 'invalid want-ref line' ' 98 write_fetch_command >pkt <<-EOF && 99 want-ref refs/heads/non-existent 100 EOF 101 102 test-tool pkt-line pack in && 103 test_must_fail test-tool serve-v2 --stateless-rpc 2>out expected_refs <<-EOF && 110 $oid refs/heads/main 111 EOF 112 git rev-parse f >expected_commits && 113 114 write_fetch_command >pkt <<-EOF && 115 want-ref refs/heads/main 116 have $(git rev-parse a) 117 EOF 118 test-tool pkt-line pack in && 119 120 test-tool serve-v2 --stateless-rpc >out expected_refs <<-EOF && 128 $oid_c refs/heads/o/foo 129 $oid_d refs/heads/o/bar 130 EOF 131 git rev-parse c d >expected_commits && 132 133 write_fetch_command >pkt <<-EOF && 134 want-ref refs/heads/o/foo 135 want-ref refs/heads/o/bar 136 have $(git rev-parse b) 137 EOF 138 test-tool pkt-line pack in && 139 140 test-tool serve-v2 --stateless-rpc >out expected_refs <<-EOF && 147 $oid refs/heads/main 148 EOF 149 git rev-parse e f >expected_commits && 150 151 write_fetch_command >pkt <<-EOF && 152 want-ref refs/heads/main 153 want $(git rev-parse e) 154 have $(git rev-parse a) 155 EOF 156 test-tool pkt-line pack in && 157 158 test-tool serve-v2 --stateless-rpc >out expected_refs <<-EOF && 165 $oid refs/heads/o/foo 166 EOF 167 >expected_commits && 168 169 write_fetch_command >pkt <<-EOF && 170 want-ref refs/heads/o/foo 171 have $(git rev-parse c) 172 EOF 173 test-tool pkt-line pack in && 174 175 test-tool serve-v2 --stateless-rpc >out expected && 240 git -C local rev-parse refs/heads/actual >actual && 241 test_cmp expected actual && 242 test_grep "want $oid" log 243 ' 244 245 test_expect_success 'fetching multiple refs' ' 246 test_when_finished "rm -f log" && 247 248 rm -rf local && 249 cp -r "$LOCAL_PRISTINE" local && 250 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin main baz && 251 252 git -C "$REPO" rev-parse "main" "baz" >expected && 253 git -C local rev-parse refs/remotes/origin/main refs/remotes/origin/baz >actual && 254 test_cmp expected actual && 255 test_grep "want-ref refs/heads/main" log && 256 test_grep "want-ref refs/heads/baz" log 257 ' 258 259 test_expect_success 'fetching ref and exact OID' ' 260 test_when_finished "rm -f log" && 261 262 rm -rf local && 263 cp -r "$LOCAL_PRISTINE" local && 264 oid=$(git -C "$REPO" rev-parse b) && 265 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \ 266 main "$oid":refs/heads/actual && 267 268 git -C "$REPO" rev-parse "main" "b" >expected && 269 git -C local rev-parse refs/remotes/origin/main refs/heads/actual >actual && 270 test_cmp expected actual && 271 test_grep "want $oid" log && 272 test_grep "want-ref refs/heads/main" log 273 ' 274 275 test_expect_success 'fetching with wildcard that does not match any refs' ' 276 test_when_finished "rm -f log" && 277 278 rm -rf local && 279 cp -r "$LOCAL_PRISTINE" local && 280 git -C local fetch origin refs/heads/none*:refs/heads/* >out && 281 test_must_be_empty out 282 ' 283 284 test_expect_success 'fetching with wildcard that matches multiple refs' ' 285 test_when_finished "rm -f log" && 286 287 rm -rf local && 288 cp -r "$LOCAL_PRISTINE" local && 289 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin refs/heads/o*:refs/heads/o* && 290 291 git -C "$REPO" rev-parse "o/foo" "o/bar" >expected && 292 git -C local rev-parse "o/foo" "o/bar" >actual && 293 test_cmp expected actual && 294 test_grep "want-ref refs/heads/o/foo" log && 295 test_grep "want-ref refs/heads/o/bar" log 296 ' 297 298 test_expect_success 'shallow clone with ref-in-want' ' 299 rm -rf local && 300 GIT_TEST_PROTOCOL_VERSION=2 git clone --depth=1 "file://$REPO" local && 301 git -C "$REPO" rev-parse main >expected && 302 git -C local rev-parse refs/remotes/origin/main >actual && 303 test_cmp expected actual && 304 git -C local log --oneline refs/remotes/origin/main >log && 305 test_line_count = 1 log 306 ' 307 308 test_expect_success 'incremental shallow fetch with ref-in-want' ' 309 rm -rf local && 310 GIT_TEST_PROTOCOL_VERSION=2 git clone --depth=1 "file://$REPO" local && 311 GIT_TEST_PROTOCOL_VERSION=2 git -C local fetch --depth=2 origin main && 312 git -C local log --oneline refs/remotes/origin/main >log && 313 test_line_count = 2 log 314 ' 315 316 REPO="$(pwd)/repo-ns" 317 318 test_expect_success 'setup namespaced repo' ' 319 ( 320 git init -b main "$REPO" && 321 cd "$REPO" && 322 test_commit a && 323 test_commit b && 324 git checkout a && 325 test_commit c && 326 git checkout a && 327 test_commit d && 328 git update-ref refs/heads/ns-no b && 329 git update-ref refs/namespaces/ns/refs/heads/ns-yes c && 330 git update-ref refs/namespaces/ns/refs/heads/hidden d 331 ) && 332 git -C "$REPO" config uploadpack.allowRefInWant true 333 ' 334 335 test_expect_success 'with namespace: want-ref is considered relative to namespace' ' 336 wanted_ref=refs/heads/ns-yes && 337 338 oid=$(git -C "$REPO" rev-parse "refs/namespaces/ns/$wanted_ref") && 339 cat >expected_refs <<-EOF && 340 $oid $wanted_ref 341 EOF 342 cat >expected_commits <<-EOF && 343 $oid 344 $(git -C "$REPO" rev-parse a) 345 EOF 346 347 write_fetch_command >pkt <<-EOF && 348 want-ref $wanted_ref 349 EOF 350 test-tool pkt-line pack in && 351 352 GIT_NAMESPACE=ns test-tool -C "$REPO" serve-v2 --stateless-rpc >out pkt <<-EOF && 360 want-ref $wanted_ref 361 EOF 362 test-tool pkt-line pack in && 363 364 test_must_fail env GIT_NAMESPACE=ns \ 365 test-tool -C "$REPO" serve-v2 --stateless-rpc >out expected_refs <<-EOF && 375 $oid $wanted_ref 376 EOF 377 cat >expected_commits <<-EOF && 378 $oid 379 $(git -C "$REPO" rev-parse a) 380 EOF 381 382 write_fetch_command >pkt <<-EOF && 383 want-ref $wanted_ref 384 EOF 385 test-tool pkt-line pack in && 386 387 test-tool -C "$REPO" serve-v2 --stateless-rpc >out pkt <<-EOF && 396 want-ref $wanted_ref 397 EOF 398 test-tool pkt-line pack in && 399 400 test_must_fail env GIT_NAMESPACE=ns \ 401 test-tool -C "$REPO" serve-v2 --stateless-rpc >out