| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Basic fetch/push functionality. |
| 4 | |
| 5 | This test checks the following functionality: |
| 6 | |
| 7 | * command-line syntax |
| 8 | * refspecs |
| 9 | * fast-forward detection, and overriding it |
| 10 | * configuration |
| 11 | * hooks |
| 12 | * --porcelain output format |
| 13 | * hiderefs |
| 14 | * reflogs |
| 15 | * URL validation |
| 16 | ' |
| 17 | |
| 18 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 19 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 20 | |
| 21 | TEST_CREATE_REPO_NO_TEMPLATE=1 |
| 22 | . ./test-lib.sh |
| 23 | |
| 24 | D=$(pwd) |
| 25 | |
| 26 | mk_empty () { |
| 27 | repo_name="$1" |
| 28 | test_when_finished "rm -rf \"$repo_name\"" && |
| 29 | test_path_is_missing "$repo_name" && |
| 30 | git init --template= "$repo_name" && |
| 31 | mkdir "$repo_name"/.git/hooks && |
| 32 | git -C "$repo_name" config receive.denyCurrentBranch warn |
| 33 | } |
| 34 | |
| 35 | mk_test () { |
| 36 | repo_name="$1" |
| 37 | shift |
| 38 | |
| 39 | mk_empty "$repo_name" && |
| 40 | ( |
| 41 | for ref in "$@" |
| 42 | do |
| 43 | git push "$repo_name" $the_first_commit:refs/$ref || |
| 44 | exit |
| 45 | done && |
| 46 | cd "$repo_name" && |
| 47 | for ref in "$@" |
| 48 | do |
| 49 | echo "$the_first_commit" >expect && |
| 50 | git show-ref -s --verify refs/$ref >actual && |
| 51 | test_cmp expect actual || |
| 52 | exit |
| 53 | done && |
| 54 | git fsck --full |
| 55 | ) |
| 56 | } |
| 57 | |
| 58 | mk_test_with_hooks() { |
| 59 | repo_name=$1 |
| 60 | mk_test "$@" && |
| 61 | test_hook -C "$repo_name" pre-receive <<-'EOF' && |
| 62 | cat - >>pre-receive.actual |
| 63 | EOF |
| 64 | |
| 65 | test_hook -C "$repo_name" update <<-'EOF' && |
| 66 | printf "%s %s %s\n" "$@" >>update.actual |
| 67 | EOF |
| 68 | |
| 69 | test_hook -C "$repo_name" post-receive <<-'EOF' && |
| 70 | cat - >>post-receive.actual |
| 71 | EOF |
| 72 | |
| 73 | test_hook -C "$repo_name" post-update <<-'EOF' |
| 74 | for ref in "$@" |
| 75 | do |
| 76 | printf "%s\n" "$ref" >>post-update.actual |
| 77 | done |
| 78 | EOF |
| 79 | } |
| 80 | |
| 81 | mk_child() { |
| 82 | test_when_finished "rm -rf \"$2\"" && |
| 83 | git clone --template= "$1" "$2" |
| 84 | } |
| 85 | |
| 86 | check_push_result () { |
| 87 | test $# -ge 3 || |
| 88 | BUG "check_push_result requires at least 3 parameters" |
| 89 | |
| 90 | repo_name="$1" |
| 91 | shift |
| 92 | |
| 93 | ( |
| 94 | cd "$repo_name" && |
| 95 | echo "$1" >expect && |
| 96 | shift && |
| 97 | for ref in "$@" |
| 98 | do |
| 99 | git show-ref -s --verify refs/$ref >actual && |
| 100 | test_cmp expect actual || |
| 101 | exit |
| 102 | done && |
| 103 | git fsck --full |
| 104 | ) |
| 105 | } |
| 106 | |
| 107 | test_expect_success setup ' |
| 108 | >path1 && |
| 109 | git add path1 && |
| 110 | test_tick && |
| 111 | git commit -a -m repo && |
| 112 | the_first_commit=$(git show-ref -s --verify refs/heads/main) && |
| 113 | |
| 114 | >path2 && |
| 115 | git add path2 && |
| 116 | test_tick && |
| 117 | git commit -a -m second && |
| 118 | the_commit=$(git show-ref -s --verify refs/heads/main) |
| 119 | ' |
| 120 | |
| 121 | for cmd in push fetch |
| 122 | do |
| 123 | for opt in ipv4 ipv6 |
| 124 | do |
| 125 | test_expect_success "reject 'git $cmd --no-$opt'" ' |
| 126 | test_must_fail git $cmd --no-$opt 2>err && |
| 127 | grep "unknown option .no-$opt" err |
| 128 | ' |
| 129 | done |
| 130 | done |
| 131 | |
| 132 | test_expect_success 'fetch without wildcard' ' |
| 133 | mk_empty testrepo && |
| 134 | ( |
| 135 | cd testrepo && |
| 136 | git fetch .. refs/heads/main:refs/remotes/origin/main && |
| 137 | |
| 138 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
| 139 | git for-each-ref refs/remotes/origin >actual && |
| 140 | test_cmp expect actual |
| 141 | ) |
| 142 | ' |
| 143 | |
| 144 | test_expect_success 'fetch with wildcard' ' |
| 145 | mk_empty testrepo && |
| 146 | ( |
| 147 | cd testrepo && |
| 148 | git config remote.up.url .. && |
| 149 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && |
| 150 | git fetch up && |
| 151 | |
| 152 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
| 153 | git for-each-ref refs/remotes/origin >actual && |
| 154 | test_cmp expect actual |
| 155 | ) |
| 156 | ' |
| 157 | |
| 158 | test_expect_success 'fetch with insteadOf' ' |
| 159 | mk_empty testrepo && |
| 160 | ( |
| 161 | TRASH=$(pwd)/ && |
| 162 | cd testrepo && |
| 163 | git config "url.$TRASH.insteadOf" trash/ && |
| 164 | git config remote.up.url trash/. && |
| 165 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && |
| 166 | git fetch up && |
| 167 | |
| 168 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
| 169 | git for-each-ref refs/remotes/origin >actual && |
| 170 | test_cmp expect actual |
| 171 | ) |
| 172 | ' |
| 173 | |
| 174 | test_expect_success 'fetch with pushInsteadOf (should not rewrite)' ' |
| 175 | mk_empty testrepo && |
| 176 | ( |
| 177 | TRASH=$(pwd)/ && |
| 178 | cd testrepo && |
| 179 | git config "url.trash/.pushInsteadOf" "$TRASH" && |
| 180 | git config remote.up.url "$TRASH." && |
| 181 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && |
| 182 | git fetch up && |
| 183 | |
| 184 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
| 185 | git for-each-ref refs/remotes/origin >actual && |
| 186 | test_cmp expect actual |
| 187 | ) |
| 188 | ' |
| 189 | |
| 190 | grep_wrote () { |
| 191 | object_count=$1 |
| 192 | file_name=$2 |
| 193 | grep 'write_pack_file/wrote.*"value":"'$1'"' $2 |
| 194 | } |
| 195 | |
| 196 | test_expect_success 'push without negotiation' ' |
| 197 | mk_empty testrepo && |
| 198 | git push testrepo $the_first_commit:refs/remotes/origin/first_commit && |
| 199 | test_commit -C testrepo unrelated_commit && |
| 200 | git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && |
| 201 | test_when_finished "rm event" && |
| 202 | GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main && |
| 203 | grep_wrote 5 event # 2 commits, 2 trees, 1 blob |
| 204 | ' |
| 205 | |
| 206 | test_expect_success 'push with negotiation' ' |
| 207 | mk_empty testrepo && |
| 208 | git push testrepo $the_first_commit:refs/remotes/origin/first_commit && |
| 209 | test_commit -C testrepo unrelated_commit && |
| 210 | git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && |
| 211 | test_when_finished "rm event" && |
| 212 | GIT_TRACE2_EVENT="$(pwd)/event" \ |
| 213 | git -c protocol.version=2 -c push.negotiate=1 \ |
| 214 | push testrepo refs/heads/main:refs/remotes/origin/main && |
| 215 | grep \"key\":\"total_rounds\",\"value\":\"1\" event && |
| 216 | grep_wrote 2 event # 1 commit, 1 tree |
| 217 | ' |
| 218 | |
| 219 | test_expect_success 'push with negotiation proceeds anyway even if negotiation fails' ' |
| 220 | mk_empty testrepo && |
| 221 | git push testrepo $the_first_commit:refs/remotes/origin/first_commit && |
| 222 | test_commit -C testrepo unrelated_commit && |
| 223 | git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && |
| 224 | test_when_finished "rm event" && |
| 225 | GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \ |
| 226 | git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err && |
| 227 | grep_wrote 5 event && # 2 commits, 2 trees, 1 blob |
| 228 | test_grep "push negotiation failed" err |
| 229 | ' |
| 230 | |
| 231 | test_expect_success 'push deletion with negotiation' ' |
| 232 | mk_empty testrepo && |
| 233 | git push testrepo $the_first_commit:refs/heads/master && |
| 234 | git -c push.negotiate=1 push testrepo \ |
| 235 | :master $the_first_commit:refs/heads/next 2>errors-2 && |
| 236 | test_grep ! "negotiate-only needs one or " errors-2 && |
| 237 | git -c push.negotiate=1 push testrepo :next 2>errors-1 && |
| 238 | test_grep ! "negotiate-only needs one or " errors-1 |
| 239 | ' |
| 240 | |
| 241 | test_expect_success 'push with negotiation does not attempt to fetch submodules' ' |
| 242 | mk_empty submodule_upstream && |
| 243 | test_commit -C submodule_upstream submodule_commit && |
| 244 | test_config_global protocol.file.allow always && |
| 245 | git submodule add ./submodule_upstream submodule && |
| 246 | mk_empty testrepo && |
| 247 | git push testrepo $the_first_commit:refs/remotes/origin/first_commit && |
| 248 | test_commit -C testrepo unrelated_commit && |
| 249 | git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && |
| 250 | GIT_TRACE2_EVENT="$(pwd)/event" git -c submodule.recurse=true \ |
| 251 | -c protocol.version=2 -c push.negotiate=1 \ |
| 252 | push testrepo refs/heads/main:refs/remotes/origin/main 2>err && |
| 253 | grep \"key\":\"total_rounds\",\"value\":\"1\" event && |
| 254 | ! grep "Fetching submodule" err |
| 255 | ' |
| 256 | |
| 257 | test_expect_success 'push with negotiation and remote.<name>.negotiationInclude' ' |
| 258 | test_when_finished rm -rf negotiation_include && |
| 259 | mk_empty negotiation_include && |
| 260 | git push negotiation_include $the_first_commit:refs/remotes/origin/first_commit && |
| 261 | test_commit -C negotiation_include unrelated_commit && |
| 262 | git -C negotiation_include config receive.hideRefs refs/remotes/origin/first_commit && |
| 263 | test_when_finished "rm event" && |
| 264 | GIT_TRACE2_EVENT="$(pwd)/event" \ |
| 265 | git -c protocol.version=2 -c push.negotiate=1 \ |
| 266 | -c remote.negotiation_include.negotiationInclude=refs/heads/main \ |
| 267 | push negotiation_include refs/heads/main:refs/remotes/origin/main && |
| 268 | test_grep \"key\":\"total_rounds\" event && |
| 269 | grep_wrote 2 event # 1 commit, 1 tree |
| 270 | ' |
| 271 | |
| 272 | test_expect_success 'push with negotiation and remote.<name>.negotiationRestrict' ' |
| 273 | test_when_finished rm -rf negotiation_restrict && |
| 274 | mk_empty negotiation_restrict && |
| 275 | git push negotiation_restrict $the_first_commit:refs/remotes/origin/first_commit && |
| 276 | test_commit -C negotiation_restrict unrelated_commit && |
| 277 | git -C negotiation_restrict config receive.hideRefs refs/remotes/origin/first_commit && |
| 278 | test_when_finished "rm event" && |
| 279 | GIT_TRACE2_EVENT="$(pwd)/event" \ |
| 280 | git -c protocol.version=2 -c push.negotiate=1 \ |
| 281 | -c remote.negotiation_restrict.negotiationRestrict=refs/heads/main \ |
| 282 | push negotiation_restrict refs/heads/main:refs/remotes/origin/main && |
| 283 | test_grep \"key\":\"total_rounds\" event && |
| 284 | grep_wrote 2 event # 1 commit, 1 tree |
| 285 | ' |
| 286 | |
| 287 | test_expect_success 'push without wildcard' ' |
| 288 | mk_empty testrepo && |
| 289 | |
| 290 | git push testrepo refs/heads/main:refs/remotes/origin/main && |
| 291 | ( |
| 292 | cd testrepo && |
| 293 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
| 294 | git for-each-ref refs/remotes/origin >actual && |
| 295 | test_cmp expect actual |
| 296 | ) |
| 297 | ' |
| 298 | |
| 299 | test_expect_success 'push with wildcard' ' |
| 300 | mk_empty testrepo && |
| 301 | |
| 302 | git push testrepo "refs/heads/*:refs/remotes/origin/*" && |
| 303 | ( |
| 304 | cd testrepo && |
| 305 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
| 306 | git for-each-ref refs/remotes/origin >actual && |
| 307 | test_cmp expect actual |
| 308 | ) |
| 309 | ' |
| 310 | |
| 311 | test_expect_success 'push with insteadOf' ' |
| 312 | mk_empty testrepo && |
| 313 | TRASH="$(pwd)/" && |
| 314 | test_config "url.$TRASH.insteadOf" trash/ && |
| 315 | git push trash/testrepo refs/heads/main:refs/remotes/origin/main && |
| 316 | ( |
| 317 | cd testrepo && |
| 318 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
| 319 | git for-each-ref refs/remotes/origin >actual && |
| 320 | test_cmp expect actual |
| 321 | ) |
| 322 | ' |
| 323 | |
| 324 | test_expect_success 'push with pushInsteadOf' ' |
| 325 | mk_empty testrepo && |
| 326 | TRASH="$(pwd)/" && |
| 327 | test_config "url.$TRASH.pushInsteadOf" trash/ && |
| 328 | git push trash/testrepo refs/heads/main:refs/remotes/origin/main && |
| 329 | ( |
| 330 | cd testrepo && |
| 331 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
| 332 | git for-each-ref refs/remotes/origin >actual && |
| 333 | test_cmp expect actual |
| 334 | ) |
| 335 | ' |
| 336 | |
| 337 | test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' ' |
| 338 | mk_empty testrepo && |
| 339 | test_config "url.trash2/.pushInsteadOf" testrepo/ && |
| 340 | test_config "url.trash3/.pushInsteadOf" trash/wrong && |
| 341 | test_config remote.r.url trash/wrong && |
| 342 | test_config remote.r.pushurl "testrepo/" && |
| 343 | git push r refs/heads/main:refs/remotes/origin/main && |
| 344 | ( |
| 345 | cd testrepo && |
| 346 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
| 347 | git for-each-ref refs/remotes/origin >actual && |
| 348 | test_cmp expect actual |
| 349 | ) |
| 350 | ' |
| 351 | |
| 352 | test_expect_success 'push with matching heads' ' |
| 353 | mk_test testrepo heads/main && |
| 354 | git push testrepo : && |
| 355 | check_push_result testrepo $the_commit heads/main |
| 356 | ' |
| 357 | |
| 358 | test_expect_success 'push with matching heads on the command line' ' |
| 359 | mk_test testrepo heads/main && |
| 360 | git push testrepo : && |
| 361 | check_push_result testrepo $the_commit heads/main |
| 362 | ' |
| 363 | |
| 364 | test_expect_success 'failed (non-fast-forward) push with matching heads' ' |
| 365 | mk_test testrepo heads/main && |
| 366 | git push testrepo : && |
| 367 | git commit --amend -massaged && |
| 368 | test_must_fail git push testrepo && |
| 369 | check_push_result testrepo $the_commit heads/main && |
| 370 | git reset --hard $the_commit |
| 371 | ' |
| 372 | |
| 373 | test_expect_success 'push --force with matching heads' ' |
| 374 | mk_test testrepo heads/main && |
| 375 | git push testrepo : && |
| 376 | git commit --amend -massaged && |
| 377 | git push --force testrepo : && |
| 378 | ! check_push_result testrepo $the_commit heads/main && |
| 379 | git reset --hard $the_commit |
| 380 | ' |
| 381 | |
| 382 | test_expect_success 'push with matching heads and forced update' ' |
| 383 | mk_test testrepo heads/main && |
| 384 | git push testrepo : && |
| 385 | git commit --amend -massaged && |
| 386 | git push testrepo +: && |
| 387 | ! check_push_result testrepo $the_commit heads/main && |
| 388 | git reset --hard $the_commit |
| 389 | ' |
| 390 | |
| 391 | test_expect_success 'push with no ambiguity (1)' ' |
| 392 | mk_test testrepo heads/main && |
| 393 | git push testrepo main:main && |
| 394 | check_push_result testrepo $the_commit heads/main |
| 395 | ' |
| 396 | |
| 397 | test_expect_success 'push with no ambiguity (2)' ' |
| 398 | mk_test testrepo remotes/origin/main && |
| 399 | git push testrepo main:origin/main && |
| 400 | check_push_result testrepo $the_commit remotes/origin/main |
| 401 | ' |
| 402 | |
| 403 | test_expect_success 'push with colon-less refspec, no ambiguity' ' |
| 404 | mk_test testrepo heads/main heads/t/main && |
| 405 | git branch -f t/main main && |
| 406 | git push testrepo main && |
| 407 | check_push_result testrepo $the_commit heads/main && |
| 408 | check_push_result testrepo $the_first_commit heads/t/main |
| 409 | ' |
| 410 | |
| 411 | test_expect_success 'push with weak ambiguity (1)' ' |
| 412 | mk_test testrepo heads/main remotes/origin/main && |
| 413 | git push testrepo main:main && |
| 414 | check_push_result testrepo $the_commit heads/main && |
| 415 | check_push_result testrepo $the_first_commit remotes/origin/main |
| 416 | ' |
| 417 | |
| 418 | test_expect_success 'push with weak ambiguity (2)' ' |
| 419 | mk_test testrepo heads/main remotes/origin/main remotes/another/main && |
| 420 | git push testrepo main:main && |
| 421 | check_push_result testrepo $the_commit heads/main && |
| 422 | check_push_result testrepo $the_first_commit remotes/origin/main remotes/another/main |
| 423 | ' |
| 424 | |
| 425 | test_expect_success 'push with ambiguity' ' |
| 426 | mk_test testrepo heads/frotz tags/frotz && |
| 427 | test_must_fail git push testrepo main:frotz && |
| 428 | check_push_result testrepo $the_first_commit heads/frotz tags/frotz |
| 429 | ' |
| 430 | |
| 431 | test_expect_success 'push with onelevel ref' ' |
| 432 | mk_test testrepo heads/main && |
| 433 | test_must_fail git push testrepo HEAD:refs/onelevel |
| 434 | ' |
| 435 | |
| 436 | test_expect_success 'push with colon-less refspec (1)' ' |
| 437 | mk_test testrepo heads/frotz tags/frotz && |
| 438 | git branch -f frotz main && |
| 439 | git push testrepo frotz && |
| 440 | check_push_result testrepo $the_commit heads/frotz && |
| 441 | check_push_result testrepo $the_first_commit tags/frotz |
| 442 | ' |
| 443 | |
| 444 | test_expect_success 'push with colon-less refspec (2)' ' |
| 445 | mk_test testrepo heads/frotz tags/frotz && |
| 446 | if git show-ref --verify -q refs/heads/frotz |
| 447 | then |
| 448 | git branch -D frotz |
| 449 | fi && |
| 450 | git tag -f frotz && |
| 451 | git push -f testrepo frotz && |
| 452 | check_push_result testrepo $the_commit tags/frotz && |
| 453 | check_push_result testrepo $the_first_commit heads/frotz |
| 454 | ' |
| 455 | |
| 456 | test_expect_success 'push with colon-less refspec (3)' ' |
| 457 | |
| 458 | mk_test testrepo && |
| 459 | if git show-ref --verify -q refs/tags/frotz |
| 460 | then |
| 461 | git tag -d frotz |
| 462 | fi && |
| 463 | git branch -f frotz main && |
| 464 | git push testrepo frotz && |
| 465 | check_push_result testrepo $the_commit heads/frotz && |
| 466 | test 1 = $( cd testrepo && git show-ref | wc -l ) |
| 467 | ' |
| 468 | |
| 469 | test_expect_success 'push with colon-less refspec (4)' ' |
| 470 | mk_test testrepo && |
| 471 | if git show-ref --verify -q refs/heads/frotz |
| 472 | then |
| 473 | git branch -D frotz |
| 474 | fi && |
| 475 | git tag -f frotz && |
| 476 | git push testrepo frotz && |
| 477 | check_push_result testrepo $the_commit tags/frotz && |
| 478 | test 1 = $( cd testrepo && git show-ref | wc -l ) |
| 479 | ' |
| 480 | |
| 481 | test_expect_success 'push head with non-existent, incomplete dest' ' |
| 482 | mk_test testrepo && |
| 483 | git push testrepo main:branch && |
| 484 | check_push_result testrepo $the_commit heads/branch |
| 485 | ' |
| 486 | |
| 487 | test_expect_success 'push tag with non-existent, incomplete dest' ' |
| 488 | mk_test testrepo && |
| 489 | git tag -f v1.0 && |
| 490 | git push testrepo v1.0:tag && |
| 491 | check_push_result testrepo $the_commit tags/tag |
| 492 | ' |
| 493 | |
| 494 | test_expect_success 'push oid with non-existent, incomplete dest' ' |
| 495 | mk_test testrepo && |
| 496 | test_must_fail git push testrepo $(git rev-parse main):foo |
| 497 | ' |
| 498 | |
| 499 | test_expect_success 'push ref expression with non-existent, incomplete dest' ' |
| 500 | mk_test testrepo && |
| 501 | test_must_fail git push testrepo main^:branch |
| 502 | ' |
| 503 | |
| 504 | test_expect_success 'push ref expression with non-existent oid src' ' |
| 505 | mk_test testrepo && |
| 506 | test_must_fail git push testrepo $(test_oid 001):branch |
| 507 | ' |
| 508 | |
| 509 | for head in HEAD @ |
| 510 | do |
| 511 | |
| 512 | test_expect_success "push with $head" ' |
| 513 | mk_test testrepo heads/main && |
| 514 | git checkout main && |
| 515 | git push testrepo $head && |
| 516 | check_push_result testrepo $the_commit heads/main |
| 517 | ' |
| 518 | |
| 519 | test_expect_success "push with $head nonexisting at remote" ' |
| 520 | mk_test testrepo heads/main && |
| 521 | git checkout -b local main && |
| 522 | test_when_finished "git checkout main; git branch -D local" && |
| 523 | git push testrepo $head && |
| 524 | check_push_result testrepo $the_commit heads/local |
| 525 | ' |
| 526 | |
| 527 | test_expect_success "push with +$head" ' |
| 528 | mk_test testrepo heads/main && |
| 529 | git checkout -b local main && |
| 530 | test_when_finished "git checkout main; git branch -D local" && |
| 531 | git push testrepo main local && |
| 532 | check_push_result testrepo $the_commit heads/main && |
| 533 | check_push_result testrepo $the_commit heads/local && |
| 534 | |
| 535 | # Without force rewinding should fail |
| 536 | git reset --hard $head^ && |
| 537 | test_must_fail git push testrepo $head && |
| 538 | check_push_result testrepo $the_commit heads/local && |
| 539 | |
| 540 | # With force rewinding should succeed |
| 541 | git push testrepo +$head && |
| 542 | check_push_result testrepo $the_first_commit heads/local |
| 543 | ' |
| 544 | |
| 545 | test_expect_success "push $head with non-existent, incomplete dest" ' |
| 546 | mk_test testrepo && |
| 547 | git checkout main && |
| 548 | git push testrepo $head:branch && |
| 549 | check_push_result testrepo $the_commit heads/branch |
| 550 | ' |
| 551 | |
| 552 | test_expect_success "push with config remote.*.push = $head" ' |
| 553 | mk_test testrepo heads/local && |
| 554 | git checkout main && |
| 555 | git branch -f local $the_commit && |
| 556 | test_when_finished "git branch -D local" && |
| 557 | ( |
| 558 | cd testrepo && |
| 559 | git checkout local && |
| 560 | git reset --hard $the_first_commit |
| 561 | ) && |
| 562 | test_config remote.there.url testrepo && |
| 563 | test_config remote.there.push $head && |
| 564 | test_config branch.main.remote there && |
| 565 | git push && |
| 566 | check_push_result testrepo $the_commit heads/main && |
| 567 | check_push_result testrepo $the_first_commit heads/local |
| 568 | ' |
| 569 | |
| 570 | done |
| 571 | |
| 572 | test_expect_success "push to remote with no explicit refspec and config remote.*.push = src:dest" ' |
| 573 | mk_test testrepo heads/main && |
| 574 | git checkout $the_first_commit && |
| 575 | test_config remote.there.url testrepo && |
| 576 | test_config remote.there.push refs/heads/main:refs/heads/main && |
| 577 | git push there && |
| 578 | check_push_result testrepo $the_commit heads/main |
| 579 | ' |
| 580 | |
| 581 | test_expect_success 'push with remote.pushdefault' ' |
| 582 | mk_test up_repo heads/main && |
| 583 | mk_test down_repo heads/main && |
| 584 | test_config remote.up.url up_repo && |
| 585 | test_config remote.down.url down_repo && |
| 586 | test_config branch.main.remote up && |
| 587 | test_config remote.pushdefault down && |
| 588 | test_config push.default matching && |
| 589 | git push && |
| 590 | check_push_result up_repo $the_first_commit heads/main && |
| 591 | check_push_result down_repo $the_commit heads/main |
| 592 | ' |
| 593 | |
| 594 | test_expect_success 'push with config remote.*.pushurl' ' |
| 595 | mk_test testrepo heads/main && |
| 596 | git checkout main && |
| 597 | test_config remote.there.url test2repo && |
| 598 | test_config remote.there.pushurl testrepo && |
| 599 | git push there : && |
| 600 | check_push_result testrepo $the_commit heads/main |
| 601 | ' |
| 602 | |
| 603 | test_expect_success 'push with config branch.*.pushremote' ' |
| 604 | mk_test up_repo heads/main && |
| 605 | mk_test side_repo heads/main && |
| 606 | mk_test down_repo heads/main && |
| 607 | test_config remote.up.url up_repo && |
| 608 | test_config remote.pushdefault side_repo && |
| 609 | test_config remote.down.url down_repo && |
| 610 | test_config branch.main.remote up && |
| 611 | test_config branch.main.pushremote down && |
| 612 | test_config push.default matching && |
| 613 | git push && |
| 614 | check_push_result up_repo $the_first_commit heads/main && |
| 615 | check_push_result side_repo $the_first_commit heads/main && |
| 616 | check_push_result down_repo $the_commit heads/main |
| 617 | ' |
| 618 | |
| 619 | test_expect_success 'branch.*.pushremote config order is irrelevant' ' |
| 620 | mk_test one_repo heads/main && |
| 621 | mk_test two_repo heads/main && |
| 622 | test_config remote.one.url one_repo && |
| 623 | test_config remote.two.url two_repo && |
| 624 | test_config branch.main.pushremote two_repo && |
| 625 | test_config remote.pushdefault one_repo && |
| 626 | test_config push.default matching && |
| 627 | git push && |
| 628 | check_push_result one_repo $the_first_commit heads/main && |
| 629 | check_push_result two_repo $the_commit heads/main |
| 630 | ' |
| 631 | |
| 632 | test_expect_success 'push rejects empty branch name entries' ' |
| 633 | mk_test one_repo heads/main && |
| 634 | test_config remote.one.url one_repo && |
| 635 | test_config branch..remote one && |
| 636 | test_config branch..merge refs/heads/ && |
| 637 | test_config branch.main.remote one && |
| 638 | test_config branch.main.merge refs/heads/main && |
| 639 | test_must_fail git push 2>err && |
| 640 | grep "bad config variable .branch\.\." err |
| 641 | ' |
| 642 | |
| 643 | test_expect_success 'push ignores "branch." config without subsection' ' |
| 644 | mk_test one_repo heads/main && |
| 645 | test_config remote.one.url one_repo && |
| 646 | test_config branch.autoSetupMerge true && |
| 647 | test_config branch.main.remote one && |
| 648 | test_config branch.main.merge refs/heads/main && |
| 649 | git push |
| 650 | ' |
| 651 | |
| 652 | test_expect_success 'push with dry-run' ' |
| 653 | mk_test testrepo heads/main && |
| 654 | old_commit=$(git -C testrepo show-ref -s --verify refs/heads/main) && |
| 655 | git push --dry-run testrepo : && |
| 656 | check_push_result testrepo $old_commit heads/main |
| 657 | ' |
| 658 | |
| 659 | test_expect_success 'push updates local refs' ' |
| 660 | mk_test testrepo heads/main && |
| 661 | mk_child testrepo child && |
| 662 | ( |
| 663 | cd child && |
| 664 | git pull .. main && |
| 665 | git push && |
| 666 | test $(git rev-parse main) = \ |
| 667 | $(git rev-parse remotes/origin/main) |
| 668 | ) |
| 669 | ' |
| 670 | |
| 671 | test_expect_success 'push updates up-to-date local refs' ' |
| 672 | mk_test testrepo heads/main && |
| 673 | mk_child testrepo child1 && |
| 674 | mk_child testrepo child2 && |
| 675 | (cd child1 && git pull .. main && git push) && |
| 676 | ( |
| 677 | cd child2 && |
| 678 | git pull ../child1 main && |
| 679 | git push && |
| 680 | test $(git rev-parse main) = \ |
| 681 | $(git rev-parse remotes/origin/main) |
| 682 | ) |
| 683 | ' |
| 684 | |
| 685 | test_expect_success 'push preserves up-to-date packed refs' ' |
| 686 | mk_test testrepo heads/main && |
| 687 | mk_child testrepo child && |
| 688 | ( |
| 689 | cd child && |
| 690 | git push && |
| 691 | ! test -f .git/refs/remotes/origin/main |
| 692 | ) |
| 693 | ' |
| 694 | |
| 695 | test_expect_success 'push does not update local refs on failure' ' |
| 696 | mk_test testrepo heads/main && |
| 697 | mk_child testrepo child && |
| 698 | echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive && |
| 699 | chmod +x testrepo/.git/hooks/pre-receive && |
| 700 | ( |
| 701 | cd child && |
| 702 | git pull .. main && |
| 703 | test_must_fail git push && |
| 704 | test $(git rev-parse main) != \ |
| 705 | $(git rev-parse remotes/origin/main) |
| 706 | ) |
| 707 | ' |
| 708 | |
| 709 | test_expect_success 'allow deleting an invalid remote ref' ' |
| 710 | mk_test testrepo heads/branch && |
| 711 | rm -f testrepo/.git/objects/??/* && |
| 712 | git push testrepo :refs/heads/branch && |
| 713 | (cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch) |
| 714 | ' |
| 715 | |
| 716 | test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' ' |
| 717 | mk_test_with_hooks testrepo heads/main heads/next && |
| 718 | orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) && |
| 719 | newmain=$(git show-ref -s --verify refs/heads/main) && |
| 720 | orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && |
| 721 | newnext=$ZERO_OID && |
| 722 | git push testrepo refs/heads/main:refs/heads/main :refs/heads/next && |
| 723 | ( |
| 724 | cd testrepo/.git && |
| 725 | cat >pre-receive.expect <<-EOF && |
| 726 | $orgmain $newmain refs/heads/main |
| 727 | $orgnext $newnext refs/heads/next |
| 728 | EOF |
| 729 | |
| 730 | cat >update.expect <<-EOF && |
| 731 | refs/heads/next $orgnext $newnext |
| 732 | refs/heads/main $orgmain $newmain |
| 733 | EOF |
| 734 | |
| 735 | cat >post-receive.expect <<-EOF && |
| 736 | $orgmain $newmain refs/heads/main |
| 737 | $orgnext $newnext refs/heads/next |
| 738 | EOF |
| 739 | |
| 740 | cat >post-update.expect <<-EOF && |
| 741 | refs/heads/main |
| 742 | refs/heads/next |
| 743 | EOF |
| 744 | |
| 745 | test_cmp pre-receive.expect pre-receive.actual && |
| 746 | test_cmp update.expect update.actual && |
| 747 | test_cmp post-receive.expect post-receive.actual && |
| 748 | test_cmp post-update.expect post-update.actual |
| 749 | ) |
| 750 | ' |
| 751 | |
| 752 | test_expect_success 'deleting dangling ref triggers hooks with correct args' ' |
| 753 | mk_test_with_hooks testrepo heads/branch && |
| 754 | orig=$(git -C testrepo rev-parse refs/heads/branch) && |
| 755 | rm -f testrepo/.git/objects/??/* && |
| 756 | git push testrepo :refs/heads/branch && |
| 757 | ( |
| 758 | cd testrepo/.git && |
| 759 | cat >pre-receive.expect <<-EOF && |
| 760 | $orig $ZERO_OID refs/heads/branch |
| 761 | EOF |
| 762 | |
| 763 | cat >update.expect <<-EOF && |
| 764 | refs/heads/branch $orig $ZERO_OID |
| 765 | EOF |
| 766 | |
| 767 | cat >post-receive.expect <<-EOF && |
| 768 | $orig $ZERO_OID refs/heads/branch |
| 769 | EOF |
| 770 | |
| 771 | cat >post-update.expect <<-EOF && |
| 772 | refs/heads/branch |
| 773 | EOF |
| 774 | |
| 775 | test_cmp pre-receive.expect pre-receive.actual && |
| 776 | test_cmp update.expect update.actual && |
| 777 | test_cmp post-receive.expect post-receive.actual && |
| 778 | test_cmp post-update.expect post-update.actual |
| 779 | ) |
| 780 | ' |
| 781 | |
| 782 | test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' ' |
| 783 | mk_test_with_hooks testrepo heads/main && |
| 784 | orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) && |
| 785 | newmain=$(git show-ref -s --verify refs/heads/main) && |
| 786 | git push testrepo main :refs/heads/nonexistent && |
| 787 | ( |
| 788 | cd testrepo/.git && |
| 789 | cat >pre-receive.expect <<-EOF && |
| 790 | $orgmain $newmain refs/heads/main |
| 791 | $ZERO_OID $ZERO_OID refs/heads/nonexistent |
| 792 | EOF |
| 793 | |
| 794 | cat >update.expect <<-EOF && |
| 795 | refs/heads/nonexistent $ZERO_OID $ZERO_OID |
| 796 | refs/heads/main $orgmain $newmain |
| 797 | EOF |
| 798 | |
| 799 | cat >post-receive.expect <<-EOF && |
| 800 | $orgmain $newmain refs/heads/main |
| 801 | EOF |
| 802 | |
| 803 | cat >post-update.expect <<-EOF && |
| 804 | refs/heads/main |
| 805 | EOF |
| 806 | |
| 807 | test_cmp pre-receive.expect pre-receive.actual && |
| 808 | test_cmp update.expect update.actual && |
| 809 | test_cmp post-receive.expect post-receive.actual && |
| 810 | test_cmp post-update.expect post-update.actual |
| 811 | ) |
| 812 | ' |
| 813 | |
| 814 | test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' ' |
| 815 | mk_test_with_hooks testrepo heads/main && |
| 816 | git push testrepo :refs/heads/nonexistent && |
| 817 | ( |
| 818 | cd testrepo/.git && |
| 819 | cat >pre-receive.expect <<-EOF && |
| 820 | $ZERO_OID $ZERO_OID refs/heads/nonexistent |
| 821 | EOF |
| 822 | |
| 823 | cat >update.expect <<-EOF && |
| 824 | refs/heads/nonexistent $ZERO_OID $ZERO_OID |
| 825 | EOF |
| 826 | |
| 827 | test_cmp pre-receive.expect pre-receive.actual && |
| 828 | test_cmp update.expect update.actual && |
| 829 | test_path_is_missing post-receive.actual && |
| 830 | test_path_is_missing post-update.actual |
| 831 | ) |
| 832 | ' |
| 833 | |
| 834 | test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' ' |
| 835 | mk_test_with_hooks testrepo heads/main heads/next heads/seen && |
| 836 | orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) && |
| 837 | newmain=$(git show-ref -s --verify refs/heads/main) && |
| 838 | orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && |
| 839 | newnext=$ZERO_OID && |
| 840 | orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) && |
| 841 | newseen=$(git show-ref -s --verify refs/heads/main) && |
| 842 | git push testrepo refs/heads/main:refs/heads/main \ |
| 843 | refs/heads/main:refs/heads/seen :refs/heads/next \ |
| 844 | :refs/heads/nonexistent && |
| 845 | ( |
| 846 | cd testrepo/.git && |
| 847 | cat >pre-receive.expect <<-EOF && |
| 848 | $orgmain $newmain refs/heads/main |
| 849 | $orgnext $newnext refs/heads/next |
| 850 | $orgseen $newseen refs/heads/seen |
| 851 | $ZERO_OID $ZERO_OID refs/heads/nonexistent |
| 852 | EOF |
| 853 | |
| 854 | cat >update.expect <<-EOF && |
| 855 | refs/heads/next $orgnext $newnext |
| 856 | refs/heads/nonexistent $ZERO_OID $ZERO_OID |
| 857 | refs/heads/main $orgmain $newmain |
| 858 | refs/heads/seen $orgseen $newseen |
| 859 | EOF |
| 860 | |
| 861 | cat >post-receive.expect <<-EOF && |
| 862 | $orgmain $newmain refs/heads/main |
| 863 | $orgnext $newnext refs/heads/next |
| 864 | $orgseen $newseen refs/heads/seen |
| 865 | EOF |
| 866 | |
| 867 | cat >post-update.expect <<-EOF && |
| 868 | refs/heads/main |
| 869 | refs/heads/next |
| 870 | refs/heads/seen |
| 871 | EOF |
| 872 | |
| 873 | test_cmp pre-receive.expect pre-receive.actual && |
| 874 | test_cmp update.expect update.actual && |
| 875 | test_cmp post-receive.expect post-receive.actual && |
| 876 | test_cmp post-update.expect post-update.actual |
| 877 | ) |
| 878 | ' |
| 879 | |
| 880 | test_expect_success 'allow deleting a ref using --delete' ' |
| 881 | mk_test testrepo heads/main && |
| 882 | (cd testrepo && git config receive.denyDeleteCurrent warn) && |
| 883 | git push testrepo --delete main && |
| 884 | (cd testrepo && test_must_fail git rev-parse --verify refs/heads/main) |
| 885 | ' |
| 886 | |
| 887 | test_expect_success 'allow deleting a tag using --delete' ' |
| 888 | mk_test testrepo heads/main && |
| 889 | git tag -a -m dummy_message deltag heads/main && |
| 890 | git push testrepo --tags && |
| 891 | (cd testrepo && git rev-parse --verify -q refs/tags/deltag) && |
| 892 | git push testrepo --delete tag deltag && |
| 893 | (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag) |
| 894 | ' |
| 895 | |
| 896 | test_expect_success 'push --delete without args aborts' ' |
| 897 | mk_test testrepo heads/main && |
| 898 | test_must_fail git push testrepo --delete |
| 899 | ' |
| 900 | |
| 901 | test_expect_success 'push --delete refuses src:dest refspecs' ' |
| 902 | mk_test testrepo heads/main && |
| 903 | test_must_fail git push testrepo --delete main:foo |
| 904 | ' |
| 905 | |
| 906 | test_expect_success 'push --delete refuses empty string' ' |
| 907 | mk_test testrepo heads/master && |
| 908 | test_must_fail git push testrepo --delete "" |
| 909 | ' |
| 910 | |
| 911 | test_expect_success 'push --delete onelevel refspecs' ' |
| 912 | mk_test testrepo heads/main && |
| 913 | git -C testrepo update-ref refs/onelevel refs/heads/main && |
| 914 | git push testrepo --delete refs/onelevel && |
| 915 | test_must_fail git -C testrepo rev-parse --verify refs/onelevel |
| 916 | ' |
| 917 | |
| 918 | test_expect_success 'warn on push to HEAD of non-bare repository' ' |
| 919 | mk_test testrepo heads/main && |
| 920 | ( |
| 921 | cd testrepo && |
| 922 | git checkout main && |
| 923 | git config receive.denyCurrentBranch warn |
| 924 | ) && |
| 925 | git push testrepo main 2>stderr && |
| 926 | grep "warning: updating the current branch" stderr |
| 927 | ' |
| 928 | |
| 929 | test_expect_success 'deny push to HEAD of non-bare repository' ' |
| 930 | mk_test testrepo heads/main && |
| 931 | ( |
| 932 | cd testrepo && |
| 933 | git checkout main && |
| 934 | git config receive.denyCurrentBranch true |
| 935 | ) && |
| 936 | test_must_fail git push testrepo main |
| 937 | ' |
| 938 | |
| 939 | test_expect_success 'allow push to HEAD of bare repository (bare)' ' |
| 940 | mk_test testrepo heads/main && |
| 941 | ( |
| 942 | cd testrepo && |
| 943 | git checkout main && |
| 944 | git config receive.denyCurrentBranch true && |
| 945 | git config core.bare true |
| 946 | ) && |
| 947 | git push testrepo main 2>stderr && |
| 948 | ! grep "warning: updating the current branch" stderr |
| 949 | ' |
| 950 | |
| 951 | test_expect_success 'allow push to HEAD of non-bare repository (config)' ' |
| 952 | mk_test testrepo heads/main && |
| 953 | ( |
| 954 | cd testrepo && |
| 955 | git checkout main && |
| 956 | git config receive.denyCurrentBranch false |
| 957 | ) && |
| 958 | git push testrepo main 2>stderr && |
| 959 | ! grep "warning: updating the current branch" stderr |
| 960 | ' |
| 961 | |
| 962 | test_expect_success !WITH_BREAKING_CHANGES 'fetch with branches' ' |
| 963 | mk_empty testrepo && |
| 964 | git branch second $the_first_commit && |
| 965 | git checkout second && |
| 966 | mkdir testrepo/.git/branches && |
| 967 | echo ".." > testrepo/.git/branches/branch1 && |
| 968 | ( |
| 969 | cd testrepo && |
| 970 | git fetch branch1 && |
| 971 | echo "$the_commit commit refs/heads/branch1" >expect && |
| 972 | git for-each-ref refs/heads >actual && |
| 973 | test_cmp expect actual |
| 974 | ) && |
| 975 | git checkout main |
| 976 | ' |
| 977 | |
| 978 | test_expect_success !WITH_BREAKING_CHANGES 'fetch with branches containing #' ' |
| 979 | mk_empty testrepo && |
| 980 | mkdir testrepo/.git/branches && |
| 981 | echo "..#second" > testrepo/.git/branches/branch2 && |
| 982 | ( |
| 983 | cd testrepo && |
| 984 | git fetch branch2 && |
| 985 | echo "$the_first_commit commit refs/heads/branch2" >expect && |
| 986 | git for-each-ref refs/heads >actual && |
| 987 | test_cmp expect actual |
| 988 | ) && |
| 989 | git checkout main |
| 990 | ' |
| 991 | |
| 992 | test_expect_success !WITH_BREAKING_CHANGES 'push with branches' ' |
| 993 | mk_empty testrepo && |
| 994 | git checkout second && |
| 995 | |
| 996 | test_when_finished "rm -rf .git/branches" && |
| 997 | mkdir .git/branches && |
| 998 | echo "testrepo" > .git/branches/branch1 && |
| 999 | |
| 1000 | git push branch1 && |
| 1001 | ( |
| 1002 | cd testrepo && |
| 1003 | echo "$the_first_commit commit refs/heads/main" >expect && |
| 1004 | git for-each-ref refs/heads >actual && |
| 1005 | test_cmp expect actual |
| 1006 | ) |
| 1007 | ' |
| 1008 | |
| 1009 | test_expect_success !WITH_BREAKING_CHANGES 'push with branches containing #' ' |
| 1010 | mk_empty testrepo && |
| 1011 | |
| 1012 | test_when_finished "rm -rf .git/branches" && |
| 1013 | mkdir .git/branches && |
| 1014 | echo "testrepo#branch3" > .git/branches/branch2 && |
| 1015 | |
| 1016 | git push branch2 && |
| 1017 | ( |
| 1018 | cd testrepo && |
| 1019 | echo "$the_first_commit commit refs/heads/branch3" >expect && |
| 1020 | git for-each-ref refs/heads >actual && |
| 1021 | test_cmp expect actual |
| 1022 | ) && |
| 1023 | git checkout main |
| 1024 | ' |
| 1025 | |
| 1026 | test_expect_success 'push into aliased refs (consistent)' ' |
| 1027 | mk_test testrepo heads/main && |
| 1028 | mk_child testrepo child1 && |
| 1029 | mk_child testrepo child2 && |
| 1030 | ( |
| 1031 | cd child1 && |
| 1032 | git branch foo && |
| 1033 | git symbolic-ref refs/heads/bar refs/heads/foo && |
| 1034 | git config receive.denyCurrentBranch false |
| 1035 | ) && |
| 1036 | ( |
| 1037 | cd child2 && |
| 1038 | >path2 && |
| 1039 | git add path2 && |
| 1040 | test_tick && |
| 1041 | git commit -a -m child2 && |
| 1042 | git branch foo && |
| 1043 | git branch bar && |
| 1044 | git push ../child1 foo bar |
| 1045 | ) |
| 1046 | ' |
| 1047 | |
| 1048 | test_expect_success 'push into aliased refs (inconsistent)' ' |
| 1049 | mk_test testrepo heads/main && |
| 1050 | mk_child testrepo child1 && |
| 1051 | mk_child testrepo child2 && |
| 1052 | ( |
| 1053 | cd child1 && |
| 1054 | git branch foo && |
| 1055 | git symbolic-ref refs/heads/bar refs/heads/foo && |
| 1056 | git config receive.denyCurrentBranch false |
| 1057 | ) && |
| 1058 | ( |
| 1059 | cd child2 && |
| 1060 | >path2 && |
| 1061 | git add path2 && |
| 1062 | test_tick && |
| 1063 | git commit -a -m child2 && |
| 1064 | git branch foo && |
| 1065 | >path3 && |
| 1066 | git add path3 && |
| 1067 | test_tick && |
| 1068 | git commit -a -m child2 && |
| 1069 | git branch bar && |
| 1070 | test_must_fail git push ../child1 foo bar 2>stderr && |
| 1071 | grep "refusing inconsistent update" stderr |
| 1072 | ) |
| 1073 | ' |
| 1074 | |
| 1075 | test_force_push_tag () { |
| 1076 | tag_type_description=$1 |
| 1077 | tag_args=$2 |
| 1078 | |
| 1079 | test_expect_success "force pushing required to update $tag_type_description" " |
| 1080 | mk_test testrepo heads/main && |
| 1081 | mk_child testrepo child1 && |
| 1082 | mk_child testrepo child2 && |
| 1083 | ( |
| 1084 | cd child1 && |
| 1085 | git tag testTag && |
| 1086 | git push ../child2 testTag && |
| 1087 | >file1 && |
| 1088 | git add file1 && |
| 1089 | git commit -m 'file1' && |
| 1090 | git tag $tag_args testTag && |
| 1091 | test_must_fail git push ../child2 testTag && |
| 1092 | git push --force ../child2 testTag && |
| 1093 | git tag $tag_args testTag HEAD~ && |
| 1094 | test_must_fail git push ../child2 testTag && |
| 1095 | git push --force ../child2 testTag && |
| 1096 | |
| 1097 | # Clobbering without + in refspec needs --force |
| 1098 | git tag -f testTag && |
| 1099 | test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' && |
| 1100 | git push --force ../child2 'refs/tags/*:refs/tags/*' && |
| 1101 | |
| 1102 | # Clobbering with + in refspec does not need --force |
| 1103 | git tag -f testTag HEAD~ && |
| 1104 | git push ../child2 '+refs/tags/*:refs/tags/*' && |
| 1105 | |
| 1106 | # Clobbering with --no-force still obeys + in refspec |
| 1107 | git tag -f testTag && |
| 1108 | git push --no-force ../child2 '+refs/tags/*:refs/tags/*' && |
| 1109 | |
| 1110 | # Clobbering with/without --force and 'tag <name>' format |
| 1111 | git tag -f testTag HEAD~ && |
| 1112 | test_must_fail git push ../child2 tag testTag && |
| 1113 | git push --force ../child2 tag testTag |
| 1114 | ) |
| 1115 | " |
| 1116 | } |
| 1117 | |
| 1118 | test_force_push_tag "lightweight tag" "-f" |
| 1119 | test_force_push_tag "annotated tag" "-f -a -m'tag message'" |
| 1120 | |
| 1121 | test_force_fetch_tag () { |
| 1122 | tag_type_description=$1 |
| 1123 | tag_args=$2 |
| 1124 | |
| 1125 | test_expect_success "fetch will not clobber an existing $tag_type_description without --force" " |
| 1126 | mk_test testrepo heads/main && |
| 1127 | mk_child testrepo child1 && |
| 1128 | mk_child testrepo child2 && |
| 1129 | ( |
| 1130 | cd testrepo && |
| 1131 | git tag testTag && |
| 1132 | git -C ../child1 fetch origin tag testTag && |
| 1133 | >file1 && |
| 1134 | git add file1 && |
| 1135 | git commit -m 'file1' && |
| 1136 | git tag $tag_args testTag && |
| 1137 | test_must_fail git -C ../child1 fetch origin tag testTag && |
| 1138 | git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' |
| 1139 | ) |
| 1140 | " |
| 1141 | } |
| 1142 | |
| 1143 | test_force_fetch_tag "lightweight tag" "-f" |
| 1144 | test_force_fetch_tag "annotated tag" "-f -a -m'tag message'" |
| 1145 | |
| 1146 | test_expect_success 'push --porcelain' ' |
| 1147 | mk_empty testrepo && |
| 1148 | echo >.git/foo "To testrepo" && |
| 1149 | echo >>.git/foo "* refs/heads/main:refs/remotes/origin/main [new reference]" && |
| 1150 | echo >>.git/foo "Done" && |
| 1151 | git push >.git/bar --porcelain testrepo refs/heads/main:refs/remotes/origin/main && |
| 1152 | ( |
| 1153 | cd testrepo && |
| 1154 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
| 1155 | git for-each-ref refs/remotes/origin >actual && |
| 1156 | test_cmp expect actual |
| 1157 | ) && |
| 1158 | test_cmp .git/foo .git/bar |
| 1159 | ' |
| 1160 | |
| 1161 | test_expect_success 'push --porcelain bad url' ' |
| 1162 | mk_empty testrepo && |
| 1163 | test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/main:refs/remotes/origin/main && |
| 1164 | ! grep -q Done .git/bar |
| 1165 | ' |
| 1166 | |
| 1167 | test_expect_success 'push --porcelain rejected' ' |
| 1168 | mk_empty testrepo && |
| 1169 | git push testrepo refs/heads/main:refs/remotes/origin/main && |
| 1170 | (cd testrepo && |
| 1171 | git reset --hard origin/main^ && |
| 1172 | git config receive.denyCurrentBranch true) && |
| 1173 | |
| 1174 | echo >.git/foo "To testrepo" && |
| 1175 | echo >>.git/foo "! refs/heads/main:refs/heads/main [remote rejected] (branch is currently checked out)" && |
| 1176 | echo >>.git/foo "Done" && |
| 1177 | |
| 1178 | test_must_fail git push >.git/bar --porcelain testrepo refs/heads/main:refs/heads/main && |
| 1179 | test_cmp .git/foo .git/bar |
| 1180 | ' |
| 1181 | |
| 1182 | test_expect_success 'push --porcelain --dry-run rejected' ' |
| 1183 | mk_empty testrepo && |
| 1184 | git push testrepo refs/heads/main:refs/remotes/origin/main && |
| 1185 | (cd testrepo && |
| 1186 | git reset --hard origin/main && |
| 1187 | git config receive.denyCurrentBranch true) && |
| 1188 | |
| 1189 | echo >.git/foo "To testrepo" && |
| 1190 | echo >>.git/foo "! refs/heads/main^:refs/heads/main [rejected] (non-fast-forward)" && |
| 1191 | echo >>.git/foo "Done" && |
| 1192 | |
| 1193 | test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/main^:refs/heads/main && |
| 1194 | test_cmp .git/foo .git/bar |
| 1195 | ' |
| 1196 | |
| 1197 | test_expect_success 'push --prune' ' |
| 1198 | mk_test testrepo heads/main heads/foo heads/bar && |
| 1199 | git push --prune testrepo : && |
| 1200 | check_push_result testrepo $the_commit heads/main && |
| 1201 | ! check_push_result testrepo $the_first_commit heads/foo heads/bar |
| 1202 | ' |
| 1203 | |
| 1204 | test_expect_success 'push --prune refspec' ' |
| 1205 | mk_test testrepo tmp/main tmp/foo tmp/bar && |
| 1206 | git push --prune testrepo "refs/heads/*:refs/tmp/*" && |
| 1207 | check_push_result testrepo $the_commit tmp/main && |
| 1208 | ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar |
| 1209 | ' |
| 1210 | |
| 1211 | for configsection in transfer receive |
| 1212 | do |
| 1213 | test_expect_success "push to update a ref hidden by $configsection.hiderefs" ' |
| 1214 | mk_test testrepo heads/main hidden/one hidden/two hidden/three && |
| 1215 | ( |
| 1216 | cd testrepo && |
| 1217 | git config $configsection.hiderefs refs/hidden |
| 1218 | ) && |
| 1219 | |
| 1220 | # push to unhidden ref succeeds normally |
| 1221 | git push testrepo main:refs/heads/main && |
| 1222 | check_push_result testrepo $the_commit heads/main && |
| 1223 | |
| 1224 | # push to update a hidden ref should fail |
| 1225 | test_must_fail git push testrepo main:refs/hidden/one && |
| 1226 | check_push_result testrepo $the_first_commit hidden/one && |
| 1227 | |
| 1228 | # push to delete a hidden ref should fail |
| 1229 | test_must_fail git push testrepo :refs/hidden/two && |
| 1230 | check_push_result testrepo $the_first_commit hidden/two && |
| 1231 | |
| 1232 | # idempotent push to update a hidden ref should fail |
| 1233 | test_must_fail git push testrepo $the_first_commit:refs/hidden/three && |
| 1234 | check_push_result testrepo $the_first_commit hidden/three |
| 1235 | ' |
| 1236 | done |
| 1237 | |
| 1238 | test_expect_success 'fetch exact oid' ' |
| 1239 | mk_test testrepo heads/main hidden/one && |
| 1240 | git push testrepo main:refs/hidden/one && |
| 1241 | ( |
| 1242 | cd testrepo && |
| 1243 | git config transfer.hiderefs refs/hidden |
| 1244 | ) && |
| 1245 | check_push_result testrepo $the_commit hidden/one && |
| 1246 | |
| 1247 | mk_child testrepo child && |
| 1248 | ( |
| 1249 | cd child && |
| 1250 | |
| 1251 | # make sure $the_commit does not exist here |
| 1252 | git repack -a -d && |
| 1253 | git prune && |
| 1254 | test_must_fail git cat-file -t $the_commit && |
| 1255 | |
| 1256 | # Some protocol versions (e.g. 2) support fetching |
| 1257 | # unadvertised objects, so restrict this test to v0. |
| 1258 | |
| 1259 | # fetching the hidden object should fail by default |
| 1260 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
| 1261 | git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err && |
| 1262 | test_grep "Server does not allow request for unadvertised object" err && |
| 1263 | test_must_fail git rev-parse --verify refs/heads/copy && |
| 1264 | |
| 1265 | # the server side can allow it to succeed |
| 1266 | ( |
| 1267 | cd ../testrepo && |
| 1268 | git config uploadpack.allowtipsha1inwant true |
| 1269 | ) && |
| 1270 | |
| 1271 | git fetch -v ../testrepo $the_commit:refs/heads/copy main:refs/heads/extra && |
| 1272 | cat >expect <<-EOF && |
| 1273 | $the_commit |
| 1274 | $the_first_commit |
| 1275 | EOF |
| 1276 | { |
| 1277 | git rev-parse --verify refs/heads/copy && |
| 1278 | git rev-parse --verify refs/heads/extra |
| 1279 | } >actual && |
| 1280 | test_cmp expect actual |
| 1281 | ) |
| 1282 | ' |
| 1283 | |
| 1284 | test_expect_success 'fetch exact oid in protocol v2' ' |
| 1285 | mk_test testrepo heads/main hidden/one && |
| 1286 | git push testrepo main:refs/hidden/one && |
| 1287 | git -C testrepo config transfer.hiderefs refs/hidden && |
| 1288 | check_push_result testrepo $the_commit hidden/one && |
| 1289 | |
| 1290 | mk_child testrepo child && |
| 1291 | git -C child config protocol.version 2 && |
| 1292 | |
| 1293 | # make sure $the_commit does not exist here |
| 1294 | git -C child repack -a -d && |
| 1295 | git -C child prune && |
| 1296 | test_must_fail git -C child cat-file -t $the_commit && |
| 1297 | |
| 1298 | # fetching the hidden object succeeds by default |
| 1299 | GIT_TRACE_PACKET=$PWD/trace.out \ |
| 1300 | git -C child fetch -v ../testrepo $the_commit:refs/heads/copy && |
| 1301 | |
| 1302 | test_grep ! "ref-prefix.*$the_commit" trace.out |
| 1303 | ' |
| 1304 | |
| 1305 | for configallowtipsha1inwant in true false |
| 1306 | do |
| 1307 | test_expect_success "shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" ' |
| 1308 | mk_empty testrepo && |
| 1309 | ( |
| 1310 | cd testrepo && |
| 1311 | git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant && |
| 1312 | git commit --allow-empty -m foo && |
| 1313 | git commit --allow-empty -m bar |
| 1314 | ) && |
| 1315 | SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) && |
| 1316 | mk_empty shallow && |
| 1317 | ( |
| 1318 | cd shallow && |
| 1319 | # Some protocol versions (e.g. 2) support fetching |
| 1320 | # unadvertised objects, so restrict this test to v0. |
| 1321 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
| 1322 | git fetch --depth=1 ../testrepo/.git $SHA1 && |
| 1323 | git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true && |
| 1324 | git fetch --depth=1 ../testrepo/.git $SHA1 && |
| 1325 | git cat-file commit $SHA1 |
| 1326 | ) |
| 1327 | ' |
| 1328 | |
| 1329 | test_expect_success "deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" ' |
| 1330 | mk_empty testrepo && |
| 1331 | ( |
| 1332 | cd testrepo && |
| 1333 | git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant && |
| 1334 | git commit --allow-empty -m foo && |
| 1335 | git commit --allow-empty -m bar && |
| 1336 | git commit --allow-empty -m xyz |
| 1337 | ) && |
| 1338 | SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) && |
| 1339 | SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) && |
| 1340 | SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) && |
| 1341 | ( |
| 1342 | cd testrepo && |
| 1343 | git reset --hard $SHA1_2 && |
| 1344 | git cat-file commit $SHA1_1 && |
| 1345 | git cat-file commit $SHA1_3 |
| 1346 | ) && |
| 1347 | mk_empty shallow && |
| 1348 | ( |
| 1349 | cd shallow && |
| 1350 | # Some protocol versions (e.g. 2) support fetching |
| 1351 | # unadvertised objects, so restrict this test to v0. |
| 1352 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
| 1353 | git fetch ../testrepo/.git $SHA1_3 && |
| 1354 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
| 1355 | git fetch ../testrepo/.git $SHA1_1 && |
| 1356 | git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true && |
| 1357 | git fetch ../testrepo/.git $SHA1_1 && |
| 1358 | git cat-file commit $SHA1_1 && |
| 1359 | test_must_fail git cat-file commit $SHA1_2 && |
| 1360 | git fetch ../testrepo/.git $SHA1_2 && |
| 1361 | git cat-file commit $SHA1_2 && |
| 1362 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
| 1363 | git fetch ../testrepo/.git $SHA1_3 2>err && |
| 1364 | # ideally we would insist this be on a "remote error:" |
| 1365 | # line, but it is racy; see the commit message |
| 1366 | test_grep "not our ref.*$SHA1_3\$" err |
| 1367 | ) |
| 1368 | ' |
| 1369 | done |
| 1370 | |
| 1371 | test_expect_success 'fetch follows tags by default' ' |
| 1372 | mk_test testrepo heads/main && |
| 1373 | test_when_finished "rm -rf src" && |
| 1374 | git init src && |
| 1375 | ( |
| 1376 | cd src && |
| 1377 | git pull ../testrepo main && |
| 1378 | git tag -m "annotated" tag && |
| 1379 | git for-each-ref >tmp1 && |
| 1380 | sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 | |
| 1381 | sed -n "p; s|refs/heads/main$|refs/remotes/origin/HEAD|p" | |
| 1382 | sort -k 3 >../expect |
| 1383 | ) && |
| 1384 | test_when_finished "rm -rf dst" && |
| 1385 | git init dst && |
| 1386 | ( |
| 1387 | cd dst && |
| 1388 | git remote add origin ../src && |
| 1389 | git config branch.main.remote origin && |
| 1390 | git config branch.main.merge refs/heads/main && |
| 1391 | git pull && |
| 1392 | git for-each-ref >../actual |
| 1393 | ) && |
| 1394 | test_cmp expect actual |
| 1395 | ' |
| 1396 | |
| 1397 | test_expect_success 'peeled advertisements are not considered ref tips' ' |
| 1398 | mk_empty testrepo && |
| 1399 | git -C testrepo commit --allow-empty -m one && |
| 1400 | git -C testrepo commit --allow-empty -m two && |
| 1401 | git -C testrepo tag -m foo mytag HEAD^ && |
| 1402 | oid=$(git -C testrepo rev-parse mytag^{commit}) && |
| 1403 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
| 1404 | git fetch testrepo $oid 2>err && |
| 1405 | test_grep "Server does not allow request for unadvertised object" err |
| 1406 | ' |
| 1407 | |
| 1408 | test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' ' |
| 1409 | mk_test testrepo heads/main && |
| 1410 | test_when_finished "rm -rf src" && |
| 1411 | git init src && |
| 1412 | test_when_finished "rm -rf dst" && |
| 1413 | git init --bare dst && |
| 1414 | ( |
| 1415 | cd src && |
| 1416 | git pull ../testrepo main && |
| 1417 | git branch next && |
| 1418 | git config remote.dst.url ../dst && |
| 1419 | git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" && |
| 1420 | git push dst main && |
| 1421 | git show-ref refs/heads/main | |
| 1422 | sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect |
| 1423 | ) && |
| 1424 | ( |
| 1425 | cd dst && |
| 1426 | test_must_fail git show-ref refs/heads/next && |
| 1427 | test_must_fail git show-ref refs/heads/main && |
| 1428 | git show-ref refs/remotes/src/main >actual |
| 1429 | ) && |
| 1430 | test_cmp dst/expect dst/actual |
| 1431 | ' |
| 1432 | |
| 1433 | test_expect_success 'with no remote.$name.push, it is not used as refmap' ' |
| 1434 | mk_test testrepo heads/main && |
| 1435 | test_when_finished "rm -rf src" && |
| 1436 | git init src && |
| 1437 | test_when_finished "rm -rf dst" && |
| 1438 | git init --bare dst && |
| 1439 | ( |
| 1440 | cd src && |
| 1441 | git pull ../testrepo main && |
| 1442 | git branch next && |
| 1443 | git config remote.dst.url ../dst && |
| 1444 | git config push.default matching && |
| 1445 | git push dst main && |
| 1446 | git show-ref refs/heads/main >../dst/expect |
| 1447 | ) && |
| 1448 | ( |
| 1449 | cd dst && |
| 1450 | test_must_fail git show-ref refs/heads/next && |
| 1451 | git show-ref refs/heads/main >actual |
| 1452 | ) && |
| 1453 | test_cmp dst/expect dst/actual |
| 1454 | ' |
| 1455 | |
| 1456 | test_expect_success 'with no remote.$name.push, upstream mapping is used' ' |
| 1457 | mk_test testrepo heads/main && |
| 1458 | test_when_finished "rm -rf src" && |
| 1459 | git init src && |
| 1460 | test_when_finished "rm -rf dst" && |
| 1461 | git init --bare dst && |
| 1462 | ( |
| 1463 | cd src && |
| 1464 | git pull ../testrepo main && |
| 1465 | git branch next && |
| 1466 | git config remote.dst.url ../dst && |
| 1467 | git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" && |
| 1468 | git config push.default upstream && |
| 1469 | |
| 1470 | git config branch.main.merge refs/heads/trunk && |
| 1471 | git config branch.main.remote dst && |
| 1472 | |
| 1473 | git push dst main && |
| 1474 | git show-ref refs/heads/main | |
| 1475 | sed -e "s|refs/heads/main|refs/heads/trunk|" >../dst/expect |
| 1476 | ) && |
| 1477 | ( |
| 1478 | cd dst && |
| 1479 | test_must_fail git show-ref refs/heads/main && |
| 1480 | test_must_fail git show-ref refs/heads/next && |
| 1481 | git show-ref refs/heads/trunk >actual |
| 1482 | ) && |
| 1483 | test_cmp dst/expect dst/actual |
| 1484 | ' |
| 1485 | |
| 1486 | test_expect_success 'push does not follow tags by default' ' |
| 1487 | mk_test testrepo heads/main && |
| 1488 | test_when_finished "rm -rf src" && |
| 1489 | git init src && |
| 1490 | test_when_finished "rm -rf dst" && |
| 1491 | git init --bare dst && |
| 1492 | ( |
| 1493 | cd src && |
| 1494 | git pull ../testrepo main && |
| 1495 | git tag -m "annotated" tag && |
| 1496 | git checkout -b another && |
| 1497 | git commit --allow-empty -m "future commit" && |
| 1498 | git tag -m "future" future && |
| 1499 | git checkout main && |
| 1500 | git for-each-ref refs/heads/main >../expect && |
| 1501 | git push ../dst main |
| 1502 | ) && |
| 1503 | ( |
| 1504 | cd dst && |
| 1505 | git for-each-ref >../actual |
| 1506 | ) && |
| 1507 | test_cmp expect actual |
| 1508 | ' |
| 1509 | |
| 1510 | test_expect_success 'push --follow-tags only pushes relevant tags' ' |
| 1511 | mk_test testrepo heads/main && |
| 1512 | test_when_finished "rm -rf src" && |
| 1513 | git init src && |
| 1514 | test_when_finished "rm -rf dst" && |
| 1515 | git init --bare dst && |
| 1516 | ( |
| 1517 | cd src && |
| 1518 | git pull ../testrepo main && |
| 1519 | git tag -m "annotated" tag && |
| 1520 | git checkout -b another && |
| 1521 | git commit --allow-empty -m "future commit" && |
| 1522 | git tag -m "future" future && |
| 1523 | git checkout main && |
| 1524 | git for-each-ref refs/heads/main refs/tags/tag >../expect && |
| 1525 | git push --follow-tags ../dst main |
| 1526 | ) && |
| 1527 | ( |
| 1528 | cd dst && |
| 1529 | git for-each-ref >../actual |
| 1530 | ) && |
| 1531 | test_cmp expect actual |
| 1532 | ' |
| 1533 | |
| 1534 | test_expect_success 'push --no-thin must produce non-thin pack' ' |
| 1535 | cat >>path1 <<\EOF && |
| 1536 | keep base version of path1 big enough, compared to the new changes |
| 1537 | later, in order to pass size heuristics in |
| 1538 | builtin/pack-objects.c:try_delta() |
| 1539 | EOF |
| 1540 | git commit -am initial && |
| 1541 | git init no-thin && |
| 1542 | git --git-dir=no-thin/.git config receive.unpacklimit 0 && |
| 1543 | git push no-thin/.git refs/heads/main:refs/heads/foo && |
| 1544 | echo modified >> path1 && |
| 1545 | git commit -am modified && |
| 1546 | git repack -adf && |
| 1547 | rcvpck="git receive-pack --reject-thin-pack-for-testing" && |
| 1548 | git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/main:refs/heads/foo |
| 1549 | ' |
| 1550 | |
| 1551 | test_expect_success 'pushing a tag pushes the tagged object' ' |
| 1552 | blob=$(echo unreferenced | git hash-object -w --stdin) && |
| 1553 | git tag -m foo tag-of-blob $blob && |
| 1554 | test_when_finished "rm -rf dst.git" && |
| 1555 | git init --bare dst.git && |
| 1556 | git push dst.git tag-of-blob && |
| 1557 | # the receiving index-pack should have noticed |
| 1558 | # any problems, but we double check |
| 1559 | echo unreferenced >expect && |
| 1560 | git --git-dir=dst.git cat-file blob tag-of-blob >actual && |
| 1561 | test_cmp expect actual |
| 1562 | ' |
| 1563 | |
| 1564 | test_expect_success 'push into bare respects core.logallrefupdates' ' |
| 1565 | test_when_finished "rm -rf dst.git" && |
| 1566 | git init --bare dst.git && |
| 1567 | git -C dst.git config core.logallrefupdates true && |
| 1568 | |
| 1569 | # double push to test both with and without |
| 1570 | # the actual pack transfer |
| 1571 | git push dst.git main:one && |
| 1572 | echo "one@{0} push" >expect && |
| 1573 | git -C dst.git log -g --format="%gd %gs" one >actual && |
| 1574 | test_cmp expect actual && |
| 1575 | |
| 1576 | git push dst.git main:two && |
| 1577 | echo "two@{0} push" >expect && |
| 1578 | git -C dst.git log -g --format="%gd %gs" two >actual && |
| 1579 | test_cmp expect actual |
| 1580 | ' |
| 1581 | |
| 1582 | test_expect_success 'fetch into bare respects core.logallrefupdates' ' |
| 1583 | test_when_finished "rm -rf dst.git" && |
| 1584 | git init --bare dst.git && |
| 1585 | ( |
| 1586 | cd dst.git && |
| 1587 | git config core.logallrefupdates true && |
| 1588 | |
| 1589 | # as above, we double-fetch to test both |
| 1590 | # with and without pack transfer |
| 1591 | git fetch .. main:one && |
| 1592 | echo "one@{0} fetch .. main:one: storing head" >expect && |
| 1593 | git log -g --format="%gd %gs" one >actual && |
| 1594 | test_cmp expect actual && |
| 1595 | |
| 1596 | git fetch .. main:two && |
| 1597 | echo "two@{0} fetch .. main:two: storing head" >expect && |
| 1598 | git log -g --format="%gd %gs" two >actual && |
| 1599 | test_cmp expect actual |
| 1600 | ) |
| 1601 | ' |
| 1602 | |
| 1603 | test_expect_success 'receive.denyCurrentBranch = updateInstead' ' |
| 1604 | mk_empty testrepo && |
| 1605 | git push testrepo main && |
| 1606 | ( |
| 1607 | cd testrepo && |
| 1608 | git reset --hard && |
| 1609 | git config receive.denyCurrentBranch updateInstead |
| 1610 | ) && |
| 1611 | test_commit third path2 && |
| 1612 | |
| 1613 | # Try pushing into a repository with pristine working tree |
| 1614 | git push testrepo main && |
| 1615 | ( |
| 1616 | cd testrepo && |
| 1617 | git update-index -q --refresh && |
| 1618 | git diff-files --quiet -- && |
| 1619 | git diff-index --quiet --cached HEAD -- && |
| 1620 | test third = "$(cat path2)" && |
| 1621 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) |
| 1622 | ) && |
| 1623 | |
| 1624 | # Try pushing into a repository with working tree needing a refresh |
| 1625 | ( |
| 1626 | cd testrepo && |
| 1627 | git reset --hard HEAD^ && |
| 1628 | test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) && |
| 1629 | test-tool chmtime +100 path1 |
| 1630 | ) && |
| 1631 | git push testrepo main && |
| 1632 | ( |
| 1633 | cd testrepo && |
| 1634 | git update-index -q --refresh && |
| 1635 | git diff-files --quiet -- && |
| 1636 | git diff-index --quiet --cached HEAD -- && |
| 1637 | test_cmp ../path1 path1 && |
| 1638 | test third = "$(cat path2)" && |
| 1639 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) |
| 1640 | ) && |
| 1641 | |
| 1642 | # Update what is to be pushed |
| 1643 | test_commit fourth path2 && |
| 1644 | |
| 1645 | # Try pushing into a repository with a dirty working tree |
| 1646 | # (1) the working tree updated |
| 1647 | ( |
| 1648 | cd testrepo && |
| 1649 | echo changed >path1 |
| 1650 | ) && |
| 1651 | test_must_fail git push testrepo main && |
| 1652 | ( |
| 1653 | cd testrepo && |
| 1654 | test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) && |
| 1655 | git diff --quiet --cached && |
| 1656 | test changed = "$(cat path1)" |
| 1657 | ) && |
| 1658 | |
| 1659 | # (2) the index updated |
| 1660 | ( |
| 1661 | cd testrepo && |
| 1662 | echo changed >path1 && |
| 1663 | git add path1 |
| 1664 | ) && |
| 1665 | test_must_fail git push testrepo main && |
| 1666 | ( |
| 1667 | cd testrepo && |
| 1668 | test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) && |
| 1669 | git diff --quiet && |
| 1670 | test changed = "$(cat path1)" |
| 1671 | ) && |
| 1672 | |
| 1673 | # Introduce a new file in the update |
| 1674 | test_commit fifth path3 && |
| 1675 | |
| 1676 | # (3) the working tree has an untracked file that would interfere |
| 1677 | ( |
| 1678 | cd testrepo && |
| 1679 | git reset --hard && |
| 1680 | echo changed >path3 |
| 1681 | ) && |
| 1682 | test_must_fail git push testrepo main && |
| 1683 | ( |
| 1684 | cd testrepo && |
| 1685 | test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) && |
| 1686 | git diff --quiet && |
| 1687 | git diff --quiet --cached && |
| 1688 | test changed = "$(cat path3)" |
| 1689 | ) && |
| 1690 | |
| 1691 | # (4) the target changes to what gets pushed but it still is a change |
| 1692 | ( |
| 1693 | cd testrepo && |
| 1694 | git reset --hard && |
| 1695 | echo fifth >path3 && |
| 1696 | git add path3 |
| 1697 | ) && |
| 1698 | test_must_fail git push testrepo main && |
| 1699 | ( |
| 1700 | cd testrepo && |
| 1701 | test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) && |
| 1702 | git diff --quiet && |
| 1703 | test fifth = "$(cat path3)" |
| 1704 | ) && |
| 1705 | |
| 1706 | # (5) push into void |
| 1707 | test_when_finished "rm -rf void" && |
| 1708 | git init void && |
| 1709 | ( |
| 1710 | cd void && |
| 1711 | git config receive.denyCurrentBranch updateInstead |
| 1712 | ) && |
| 1713 | git push void main && |
| 1714 | ( |
| 1715 | cd void && |
| 1716 | test $(git -C .. rev-parse main) = $(git rev-parse HEAD) && |
| 1717 | git diff --quiet && |
| 1718 | git diff --cached --quiet |
| 1719 | ) && |
| 1720 | |
| 1721 | # (6) updateInstead intervened by fast-forward check |
| 1722 | test_must_fail git push void main^:main && |
| 1723 | test $(git -C void rev-parse HEAD) = $(git rev-parse main) && |
| 1724 | git -C void diff --quiet && |
| 1725 | git -C void diff --cached --quiet |
| 1726 | ' |
| 1727 | |
| 1728 | test_expect_success 'updateInstead with push-to-checkout hook' ' |
| 1729 | test_when_finished "rm -rf testrepo" && |
| 1730 | git init testrepo && |
| 1731 | git -C testrepo pull .. main && |
| 1732 | git -C testrepo reset --hard HEAD^^ && |
| 1733 | git -C testrepo tag initial && |
| 1734 | git -C testrepo config receive.denyCurrentBranch updateInstead && |
| 1735 | test_hook -C testrepo push-to-checkout <<-\EOF && |
| 1736 | echo >&2 updating from $(git rev-parse HEAD) |
| 1737 | echo >&2 updating to "$1" |
| 1738 | |
| 1739 | git update-index -q --refresh && |
| 1740 | git read-tree -u -m HEAD "$1" || { |
| 1741 | status=$? |
| 1742 | echo >&2 read-tree failed |
| 1743 | exit $status |
| 1744 | } |
| 1745 | EOF |
| 1746 | |
| 1747 | # Try pushing into a pristine |
| 1748 | git push testrepo main && |
| 1749 | ( |
| 1750 | cd testrepo && |
| 1751 | git diff --quiet && |
| 1752 | git diff HEAD --quiet && |
| 1753 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) |
| 1754 | ) && |
| 1755 | |
| 1756 | # Try pushing into a repository with conflicting change |
| 1757 | ( |
| 1758 | cd testrepo && |
| 1759 | git reset --hard initial && |
| 1760 | echo conflicting >path2 |
| 1761 | ) && |
| 1762 | test_must_fail git push testrepo main && |
| 1763 | ( |
| 1764 | cd testrepo && |
| 1765 | test $(git rev-parse initial) = $(git rev-parse HEAD) && |
| 1766 | test conflicting = "$(cat path2)" && |
| 1767 | git diff-index --quiet --cached HEAD |
| 1768 | ) && |
| 1769 | |
| 1770 | # Try pushing into a repository with unrelated change |
| 1771 | ( |
| 1772 | cd testrepo && |
| 1773 | git reset --hard initial && |
| 1774 | echo unrelated >path1 && |
| 1775 | echo irrelevant >path5 && |
| 1776 | git add path5 |
| 1777 | ) && |
| 1778 | git push testrepo main && |
| 1779 | ( |
| 1780 | cd testrepo && |
| 1781 | test "$(cat path1)" = unrelated && |
| 1782 | test "$(cat path5)" = irrelevant && |
| 1783 | test "$(git diff --name-only --cached HEAD)" = path5 && |
| 1784 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) |
| 1785 | ) && |
| 1786 | |
| 1787 | # push into void |
| 1788 | test_when_finished "rm -rf void" && |
| 1789 | git init void && |
| 1790 | git -C void config receive.denyCurrentBranch updateInstead && |
| 1791 | test_hook -C void push-to-checkout <<-\EOF && |
| 1792 | if git rev-parse --quiet --verify HEAD |
| 1793 | then |
| 1794 | has_head=yes |
| 1795 | echo >&2 updating from $(git rev-parse HEAD) |
| 1796 | else |
| 1797 | has_head=no |
| 1798 | echo >&2 pushing into void |
| 1799 | fi |
| 1800 | echo >&2 updating to "$1" |
| 1801 | |
| 1802 | git update-index -q --refresh && |
| 1803 | case "$has_head" in |
| 1804 | yes) |
| 1805 | git read-tree -u -m HEAD "$1" ;; |
| 1806 | no) |
| 1807 | git read-tree -u -m "$1" ;; |
| 1808 | esac || { |
| 1809 | status=$? |
| 1810 | echo >&2 read-tree failed |
| 1811 | exit $status |
| 1812 | } |
| 1813 | EOF |
| 1814 | |
| 1815 | git push void main && |
| 1816 | ( |
| 1817 | cd void && |
| 1818 | git diff --quiet && |
| 1819 | git diff --cached --quiet && |
| 1820 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) |
| 1821 | ) |
| 1822 | ' |
| 1823 | |
| 1824 | test_expect_success 'denyCurrentBranch and core.worktree' ' |
| 1825 | test_when_finished "rm -fr cloned cloned.git" && |
| 1826 | git clone --separate-git-dir cloned.git . cloned && |
| 1827 | git --git-dir cloned.git config receive.denyCurrentBranch updateInstead && |
| 1828 | git --git-dir cloned.git config core.worktree "$PWD/cloned" && |
| 1829 | test_commit raspberry && |
| 1830 | git push cloned.git HEAD:main && |
| 1831 | test_path_exists cloned/raspberry.t && |
| 1832 | test_must_fail git push --delete cloned.git main |
| 1833 | ' |
| 1834 | |
| 1835 | test_expect_success 'denyCurrentBranch and worktrees' ' |
| 1836 | test_when_finished "rm -fr cloned && git worktree remove --force new-wt" && |
| 1837 | git worktree add new-wt && |
| 1838 | git clone . cloned && |
| 1839 | test_commit -C cloned first && |
| 1840 | test_config receive.denyCurrentBranch refuse && |
| 1841 | test_must_fail git -C cloned push origin HEAD:new-wt && |
| 1842 | test_config receive.denyCurrentBranch updateInstead && |
| 1843 | git -C cloned push origin HEAD:new-wt && |
| 1844 | test_path_exists new-wt/first.t && |
| 1845 | test_must_fail git -C cloned push --delete origin new-wt |
| 1846 | ' |
| 1847 | |
| 1848 | test_expect_success 'denyCurrentBranch and bare repository worktrees' ' |
| 1849 | test_when_finished "rm -fr bare.git" && |
| 1850 | git clone --bare . bare.git && |
| 1851 | git -C bare.git worktree add wt && |
| 1852 | test_commit grape && |
| 1853 | git -C bare.git config receive.denyCurrentBranch refuse && |
| 1854 | test_must_fail git push bare.git HEAD:wt && |
| 1855 | git -C bare.git config receive.denyCurrentBranch updateInstead && |
| 1856 | git push bare.git HEAD:wt && |
| 1857 | test_path_exists bare.git/wt/grape.t && |
| 1858 | test_must_fail git push --delete bare.git wt |
| 1859 | ' |
| 1860 | |
| 1861 | test_expect_success 'updateInstead with bare repository worktree and unborn bare HEAD' ' |
| 1862 | test_when_finished "rm -fr bare.git cloned" && |
| 1863 | git clone --bare . bare.git && |
| 1864 | git -C bare.git worktree add wt && |
| 1865 | git -C bare.git config receive.denyCurrentBranch updateInstead && |
| 1866 | git -C bare.git symbolic-ref HEAD refs/heads/unborn && |
| 1867 | test_must_fail git -C bare.git rev-parse -q --verify HEAD^{commit} && |
| 1868 | git clone . cloned && |
| 1869 | test_commit -C cloned mozzarella && |
| 1870 | git -C cloned push ../bare.git HEAD:wt && |
| 1871 | test_path_exists bare.git/wt/mozzarella.t && |
| 1872 | test "$(git -C cloned rev-parse HEAD)" = "$(git -C bare.git/wt rev-parse HEAD)" |
| 1873 | ' |
| 1874 | |
| 1875 | test_expect_success 'refuse fetch to current branch of worktree' ' |
| 1876 | test_when_finished "git worktree remove --force wt && git branch -D wt" && |
| 1877 | git worktree add wt && |
| 1878 | test_commit apple && |
| 1879 | test_must_fail git fetch . HEAD:wt && |
| 1880 | git fetch -u . HEAD:wt |
| 1881 | ' |
| 1882 | |
| 1883 | test_expect_success 'refuse fetch to current branch of bare repository worktree' ' |
| 1884 | test_when_finished "rm -fr bare.git" && |
| 1885 | git clone --bare . bare.git && |
| 1886 | git -C bare.git worktree add wt && |
| 1887 | test_commit banana && |
| 1888 | test_must_fail git -C bare.git fetch .. HEAD:wt && |
| 1889 | git -C bare.git fetch -u .. HEAD:wt |
| 1890 | ' |
| 1891 | |
| 1892 | test_expect_success 'refuse to push a hidden ref, and make sure do not pollute the repository' ' |
| 1893 | mk_empty testrepo && |
| 1894 | git -C testrepo config receive.hiderefs refs/hidden && |
| 1895 | git -C testrepo config receive.unpackLimit 1 && |
| 1896 | test_must_fail git push testrepo HEAD:refs/hidden/foo && |
| 1897 | test_dir_is_empty testrepo/.git/objects/pack |
| 1898 | ' |
| 1899 | |
| 1900 | test_expect_success 'push with config push.useBitmaps' ' |
| 1901 | mk_test testrepo heads/main && |
| 1902 | git checkout main && |
| 1903 | test_unconfig push.useBitmaps && |
| 1904 | GIT_TRACE2_EVENT="$PWD/default" \ |
| 1905 | git push --quiet testrepo main:test && |
| 1906 | test_subcommand git pack-objects --all-progress-implied --revs --stdout \ |
| 1907 | --thin --delta-base-offset -q <default && |
| 1908 | |
| 1909 | test_config push.useBitmaps true && |
| 1910 | GIT_TRACE2_EVENT="$PWD/true" \ |
| 1911 | git push --quiet testrepo main:test2 && |
| 1912 | test_subcommand git pack-objects --all-progress-implied --revs --stdout \ |
| 1913 | --thin --delta-base-offset -q <true && |
| 1914 | |
| 1915 | test_config push.useBitmaps false && |
| 1916 | GIT_TRACE2_EVENT="$PWD/false" \ |
| 1917 | git push --quiet testrepo main:test3 && |
| 1918 | test_subcommand git pack-objects --all-progress-implied --revs --stdout \ |
| 1919 | --thin --delta-base-offset -q --no-use-bitmap-index <false |
| 1920 | ' |
| 1921 | |
| 1922 | test_expect_success 'push with config pack.usePathWalk=true' ' |
| 1923 | mk_test testrepo heads/main && |
| 1924 | git checkout main && |
| 1925 | test_config pack.usePathWalk true && |
| 1926 | GIT_TRACE2_EVENT="$(pwd)/path-walk.txt" \ |
| 1927 | git push --quiet testrepo main:test && |
| 1928 | |
| 1929 | test_region pack-objects path-walk path-walk.txt |
| 1930 | ' |
| 1931 | |
| 1932 | test_expect_success 'push with F/D conflict with deletion and creation' ' |
| 1933 | test_when_finished "git branch -D branch" && |
| 1934 | git branch branch/conflict && |
| 1935 | mk_test testrepo heads/branch/conflict && |
| 1936 | git branch -D branch/conflict && |
| 1937 | git branch branch && |
| 1938 | git push testrepo :refs/heads/branch/conflict refs/heads/branch |
| 1939 | ' |
| 1940 | |
| 1941 | test_expect_success 'pushing non-commit objects should report error' ' |
| 1942 | test_when_finished "rm -rf dest repo" && |
| 1943 | git init dest && |
| 1944 | git init repo && |
| 1945 | |
| 1946 | ( |
| 1947 | cd repo && |
| 1948 | test_commit --annotate test && |
| 1949 | |
| 1950 | tagsha=$(git rev-parse test^{tag}) && |
| 1951 | test_must_fail git push ../dest "$tagsha:refs/heads/branch" 2>err && |
| 1952 | test_grep "! \[remote rejected\] $tagsha -> branch (invalid new value provided)" err && |
| 1953 | test_grep "trying to write non-commit object $tagsha to branch ${SQ}refs/heads/branch${SQ}" err |
| 1954 | ) |
| 1955 | ' |
| 1956 | |
| 1957 | test_done |