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/t3507-cherry-pick-conflict.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 / t3507-cherry-pick-conflict.sh` 591 lines ยท 15539 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='test cherry-pick and revert with conflicts 4 5 - 6 + picked: rewrites foo to c 7 + base: rewrites foo to b 8 + initial: writes foo as a, unrelated as unrelated 9 10 ' 11 12 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 13 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 14 15 TEST_CREATE_REPO_NO_TEMPLATE=1 16 . ./test-lib.sh 17 18 pristine_detach () { 19 git checkout -f "$1^0" && 20 git read-tree -u --reset HEAD && 21 git clean -d -f -f -q -x 22 } 23 24 test_expect_success setup ' 25 26 echo unrelated >unrelated && 27 git add unrelated && 28 test_commit initial foo a && 29 test_commit base foo b && 30 test_commit picked foo c && 31 test_commit --signoff picked-signed foo d && 32 git checkout -b topic initial && 33 test_commit redundant-pick foo c redundant && 34 git commit --allow-empty --allow-empty-message && 35 git tag empty && 36 git checkout main && 37 git config set advice.detachedhead false 38 39 ' 40 41 test_expect_success 'failed cherry-pick does not advance HEAD' ' 42 pristine_detach initial && 43 44 head=$(git rev-parse HEAD) && 45 test_must_fail git cherry-pick picked && 46 newhead=$(git rev-parse HEAD) && 47 48 test "$head" = "$newhead" 49 ' 50 51 test_expect_success 'advice from failed cherry-pick' ' 52 pristine_detach initial && 53 54 picked=$(git rev-parse --short picked) && 55 cat <<-EOF >expected && 56 error: could not apply $picked... picked 57 hint: After resolving the conflicts, mark them with 58 hint: "git add/rm ", then run 59 hint: "git cherry-pick --continue". 60 hint: You can instead skip this commit with "git cherry-pick --skip". 61 hint: To abort and get back to the state before "git cherry-pick", 62 hint: run "git cherry-pick --abort". 63 hint: Disable this message with "git config set --global advice.mergeConflict false" 64 EOF 65 test_must_fail git cherry-pick picked 2>actual && 66 67 test_cmp expected actual 68 ' 69 70 test_expect_success 'advice from failed cherry-pick --no-commit' " 71 pristine_detach initial && 72 73 picked=\$(git rev-parse --short picked) && 74 cat <<-EOF >expected && 75 error: could not apply \$picked... picked 76 hint: after resolving the conflicts, mark the corrected paths 77 hint: with 'git add ' or 'git rm ' 78 hint: Disable this message with \"git config set --global advice.mergeConflict false\" 79 EOF 80 test_must_fail git cherry-pick --no-commit picked 2>actual && 81 82 test_cmp expected actual && 83 test_ref_missing CHERRY_PICK_HEAD 84 " 85 86 test_expect_success 'failed cherry-pick sets CHERRY_PICK_HEAD' ' 87 pristine_detach initial && 88 test_must_fail git cherry-pick picked && 89 test_cmp_rev picked CHERRY_PICK_HEAD 90 ' 91 92 test_expect_success 'successful cherry-pick does not set CHERRY_PICK_HEAD' ' 93 pristine_detach initial && 94 git cherry-pick base && 95 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD 96 ' 97 98 test_expect_success 'cherry-pick --no-commit does not set CHERRY_PICK_HEAD' ' 99 pristine_detach initial && 100 git cherry-pick --no-commit base && 101 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD 102 ' 103 104 test_expect_success 'cherry-pick w/dirty tree does not set CHERRY_PICK_HEAD' ' 105 pristine_detach initial && 106 echo foo >foo && 107 test_must_fail git cherry-pick base && 108 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD 109 ' 110 111 test_expect_success \ 112 'cherry-pick --strategy=resolve w/dirty tree does not set CHERRY_PICK_HEAD' ' 113 pristine_detach initial && 114 echo foo >foo && 115 test_must_fail git cherry-pick --strategy=resolve base && 116 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD 117 ' 118 119 test_expect_success 'GIT_CHERRY_PICK_HELP suppresses CHERRY_PICK_HEAD' ' 120 pristine_detach initial && 121 ( 122 GIT_CHERRY_PICK_HELP="and then do something else" && 123 export GIT_CHERRY_PICK_HELP && 124 test_must_fail git cherry-pick picked 125 ) && 126 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD 127 ' 128 129 test_expect_success 'git reset clears CHERRY_PICK_HEAD' ' 130 pristine_detach initial && 131 132 test_must_fail git cherry-pick picked && 133 git reset && 134 135 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD 136 ' 137 138 test_expect_success 'failed commit does not clear CHERRY_PICK_HEAD' ' 139 pristine_detach initial && 140 141 test_must_fail git cherry-pick picked && 142 test_must_fail git commit && 143 144 test_cmp_rev picked CHERRY_PICK_HEAD 145 ' 146 147 test_expect_success 'cancelled commit does not clear CHERRY_PICK_HEAD' ' 148 pristine_detach initial && 149 150 test_must_fail git cherry-pick picked && 151 echo resolved >foo && 152 git add foo && 153 git update-index --refresh -q && 154 test_must_fail git diff-index --exit-code HEAD && 155 ( 156 GIT_EDITOR=false && 157 export GIT_EDITOR && 158 test_must_fail git commit 159 ) && 160 161 test_cmp_rev picked CHERRY_PICK_HEAD 162 ' 163 164 test_expect_success 'successful commit clears CHERRY_PICK_HEAD' ' 165 pristine_detach initial && 166 167 test_must_fail git cherry-pick picked && 168 echo resolved >foo && 169 git add foo && 170 git commit && 171 172 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD 173 ' 174 175 test_expect_success 'partial commit of cherry-pick fails' ' 176 pristine_detach initial && 177 178 test_must_fail git cherry-pick picked && 179 echo resolved >foo && 180 git add foo && 181 test_must_fail git commit foo 2>err && 182 183 test_grep "cannot do a partial commit during a cherry-pick." err 184 ' 185 186 test_expect_success 'commit --amend of cherry-pick fails' ' 187 pristine_detach initial && 188 189 test_must_fail git cherry-pick picked && 190 echo resolved >foo && 191 git add foo && 192 test_must_fail git commit --amend 2>err && 193 194 test_grep "in the middle of a cherry-pick -- cannot amend." err 195 ' 196 197 test_expect_success 'successful final commit clears cherry-pick state' ' 198 pristine_detach initial && 199 200 test_must_fail git cherry-pick base picked-signed && 201 echo resolved >foo && 202 test_path_is_file .git/sequencer/todo && 203 git commit -a && 204 test_path_is_missing .git/sequencer 205 ' 206 207 test_expect_success 'reset after final pick clears cherry-pick state' ' 208 pristine_detach initial && 209 210 test_must_fail git cherry-pick base picked-signed && 211 echo resolved >foo && 212 test_path_is_file .git/sequencer/todo && 213 git reset && 214 test_path_is_missing .git/sequencer 215 ' 216 217 test_expect_success 'failed cherry-pick produces dirty index' ' 218 pristine_detach initial && 219 220 test_must_fail git cherry-pick picked && 221 222 test_must_fail git update-index --refresh -q && 223 test_must_fail git diff-index --exit-code HEAD 224 ' 225 226 test_expect_success 'failed cherry-pick registers participants in index' ' 227 pristine_detach initial && 228 { 229 git checkout base -- foo && 230 git ls-files --stage foo && 231 git checkout initial -- foo && 232 git ls-files --stage foo && 233 git checkout picked -- foo && 234 git ls-files --stage foo 235 } >stages && 236 sed " 237 1 s/ 0 / 1 / 238 2 s/ 0 / 2 / 239 3 s/ 0 / 3 / 240 " stages >expected && 241 git read-tree -u --reset HEAD && 242 243 test_must_fail git cherry-pick picked && 244 git ls-files --stage --unmerged >actual && 245 246 test_cmp expected actual 247 ' 248 249 test_expect_success \ 250 'cherry-pick conflict, ensure commit.cleanup = scissors places scissors line properly' ' 251 pristine_detach initial && 252 git config commit.cleanup scissors && 253 cat <<-EOF >expected && 254 picked 255 256 # ------------------------ >8 ------------------------ 257 # Do not modify or remove the line above. 258 # Everything below it will be ignored. 259 # 260 # Conflicts: 261 # foo 262 EOF 263 264 test_must_fail git cherry-pick picked && 265 266 test_cmp expected .git/MERGE_MSG 267 ' 268 269 test_expect_success \ 270 'cherry-pick conflict, ensure cleanup=scissors places scissors line properly' ' 271 pristine_detach initial && 272 git config --unset commit.cleanup && 273 cat <<-EOF >expected && 274 picked 275 276 # ------------------------ >8 ------------------------ 277 # Do not modify or remove the line above. 278 # Everything below it will be ignored. 279 # 280 # Conflicts: 281 # foo 282 EOF 283 284 test_must_fail git cherry-pick --cleanup=scissors picked && 285 286 test_cmp expected .git/MERGE_MSG 287 ' 288 289 test_expect_success 'failed cherry-pick describes conflict in work tree' ' 290 pristine_detach initial && 291 cat <<-EOF >expected && 292 <<<<<<< HEAD 293 a 294 ======= 295 c 296 >>>>>>> objid (picked) 297 EOF 298 299 test_must_fail git cherry-pick picked && 300 301 sed "s/[a-f0-9]* (/objid (/" foo >actual && 302 test_cmp expected actual 303 ' 304 305 test_expect_success 'diff3 -m style' ' 306 pristine_detach initial && 307 git config merge.conflictstyle diff3 && 308 cat <<-EOF >expected && 309 <<<<<<< HEAD 310 a 311 ||||||| parent of objid (picked) 312 b 313 ======= 314 c 315 >>>>>>> objid (picked) 316 EOF 317 318 test_must_fail git cherry-pick picked && 319 320 sed "s/[a-f0-9]* (/objid (/" foo >actual && 321 test_cmp expected actual 322 ' 323 324 test_expect_success 'revert also handles conflicts sanely' ' 325 git config --unset merge.conflictstyle && 326 pristine_detach initial && 327 cat <<-EOF >expected && 328 <<<<<<< HEAD 329 a 330 ======= 331 b 332 >>>>>>> parent of objid (picked) 333 EOF 334 { 335 git checkout picked -- foo && 336 git ls-files --stage foo && 337 git checkout initial -- foo && 338 git ls-files --stage foo && 339 git checkout base -- foo && 340 git ls-files --stage foo 341 } >stages && 342 sed " 343 1 s/ 0 / 1 / 344 2 s/ 0 / 2 / 345 3 s/ 0 / 3 / 346 " stages >expected-stages && 347 git read-tree -u --reset HEAD && 348 349 head=$(git rev-parse HEAD) && 350 test_must_fail git revert picked && 351 newhead=$(git rev-parse HEAD) && 352 git ls-files --stage --unmerged >actual-stages && 353 354 test "$head" = "$newhead" && 355 test_must_fail git update-index --refresh -q && 356 test_must_fail git diff-index --exit-code HEAD && 357 test_cmp expected-stages actual-stages && 358 sed "s/[a-f0-9]* (/objid (/" foo >actual && 359 test_cmp expected actual 360 ' 361 362 test_expect_success 'failed revert sets REVERT_HEAD' ' 363 pristine_detach initial && 364 test_must_fail git revert picked && 365 test_cmp_rev picked REVERT_HEAD 366 ' 367 368 test_expect_success 'successful revert does not set REVERT_HEAD' ' 369 pristine_detach base && 370 git revert base && 371 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD && 372 test_must_fail git rev-parse --verify REVERT_HEAD 373 ' 374 375 test_expect_success 'revert --no-commit sets REVERT_HEAD' ' 376 pristine_detach base && 377 git revert --no-commit base && 378 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD && 379 test_cmp_rev base REVERT_HEAD 380 ' 381 382 test_expect_success 'revert w/dirty tree does not set REVERT_HEAD' ' 383 pristine_detach base && 384 echo foo >foo && 385 test_must_fail git revert base && 386 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD && 387 test_must_fail git rev-parse --verify REVERT_HEAD 388 ' 389 390 test_expect_success 'GIT_CHERRY_PICK_HELP does not suppress REVERT_HEAD' ' 391 pristine_detach initial && 392 ( 393 GIT_CHERRY_PICK_HELP="and then do something else" && 394 GIT_REVERT_HELP="and then do something else, again" && 395 export GIT_CHERRY_PICK_HELP GIT_REVERT_HELP && 396 test_must_fail git revert picked 397 ) && 398 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD && 399 test_cmp_rev picked REVERT_HEAD 400 ' 401 402 test_expect_success 'git reset clears REVERT_HEAD' ' 403 pristine_detach initial && 404 test_must_fail git revert picked && 405 git reset && 406 test_must_fail git rev-parse --verify REVERT_HEAD 407 ' 408 409 test_expect_success 'failed commit does not clear REVERT_HEAD' ' 410 pristine_detach initial && 411 test_must_fail git revert picked && 412 test_must_fail git commit && 413 test_cmp_rev picked REVERT_HEAD 414 ' 415 416 test_expect_success 'successful final commit clears revert state' ' 417 pristine_detach picked-signed && 418 419 test_must_fail git revert picked-signed base && 420 echo resolved >foo && 421 test_path_is_file .git/sequencer/todo && 422 git commit -a && 423 test_path_is_missing .git/sequencer 424 ' 425 426 test_expect_success 'reset after final pick clears revert state' ' 427 pristine_detach picked-signed && 428 429 test_must_fail git revert picked-signed base && 430 echo resolved >foo && 431 test_path_is_file .git/sequencer/todo && 432 git reset && 433 test_path_is_missing .git/sequencer 434 ' 435 436 test_expect_success 'revert conflict, diff3 -m style' ' 437 pristine_detach initial && 438 git config merge.conflictstyle diff3 && 439 cat <<-EOF >expected && 440 <<<<<<< HEAD 441 a 442 ||||||| objid (picked) 443 c 444 ======= 445 b 446 >>>>>>> parent of objid (picked) 447 EOF 448 449 test_must_fail git revert picked && 450 451 sed "s/[a-f0-9]* (/objid (/" foo >actual && 452 test_cmp expected actual 453 ' 454 455 test_expect_success \ 456 'revert conflict, ensure commit.cleanup = scissors places scissors line properly' ' 457 pristine_detach initial && 458 git config commit.cleanup scissors && 459 cat >expected <<-EOF && 460 Revert "picked" 461 462 This reverts commit OBJID. 463 464 # ------------------------ >8 ------------------------ 465 # Do not modify or remove the line above. 466 # Everything below it will be ignored. 467 # 468 # Conflicts: 469 # foo 470 EOF 471 472 test_must_fail git revert picked && 473 474 sed "s/$OID_REGEX/OBJID/" .git/MERGE_MSG >actual && 475 test_cmp expected actual 476 ' 477 478 test_expect_success \ 479 'revert conflict, ensure cleanup=scissors places scissors line properly' ' 480 pristine_detach initial && 481 git config --unset commit.cleanup && 482 cat >expected <<-EOF && 483 Revert "picked" 484 485 This reverts commit OBJID. 486 487 # ------------------------ >8 ------------------------ 488 # Do not modify or remove the line above. 489 # Everything below it will be ignored. 490 # 491 # Conflicts: 492 # foo 493 EOF 494 495 test_must_fail git revert --cleanup=scissors picked && 496 497 sed "s/$OID_REGEX/OBJID/" .git/MERGE_MSG >actual && 498 test_cmp expected actual 499 ' 500 501 test_expect_success 'failed cherry-pick does not forget -s' ' 502 pristine_detach initial && 503 test_must_fail git cherry-pick -s picked && 504 test_grep -e "Signed-off-by" .git/MERGE_MSG 505 ' 506 507 test_expect_success 'commit after failed cherry-pick does not add duplicated -s' ' 508 pristine_detach initial && 509 test_must_fail git cherry-pick -s picked-signed && 510 git commit -a -s && 511 test $(git show -s >tmp && grep -c "Signed-off-by" tmp && rm tmp) = 1 512 ' 513 514 test_expect_success 'commit after failed cherry-pick adds -s at the right place' ' 515 pristine_detach initial && 516 test_must_fail git cherry-pick picked && 517 518 git commit -a -s && 519 520 # Do S-o-b and Conflicts appear in the right order? 521 cat <<-\EOF >expect && 522 Signed-off-by: C O Mitter 523 # Conflicts: 524 EOF 525 grep -e "^# Conflicts:" -e "^Signed-off-by" .git/COMMIT_EDITMSG >actual && 526 test_cmp expect actual && 527 528 cat <<-\EOF >expected && 529 picked 530 531 Signed-off-by: C O Mitter 532 EOF 533 534 git show -s --pretty=format:%B >actual && 535 test_cmp expected actual 536 ' 537 538 test_expect_success 'commit --amend -s places the sign-off at the right place' ' 539 pristine_detach initial && 540 test_must_fail git cherry-pick picked && 541 542 # emulate old-style conflicts block 543 mv .git/MERGE_MSG .git/MERGE_MSG+ && 544 sed -e "/^# Conflicts:/,\$s/^# *//" .git/MERGE_MSG+ >.git/MERGE_MSG && 545 546 git commit -a && 547 git commit --amend -s && 548 549 # Do S-o-b and Conflicts appear in the right order? 550 cat <<-\EOF >expect && 551 Signed-off-by: C O Mitter 552 Conflicts: 553 EOF 554 grep -e "^Conflicts:" -e "^Signed-off-by" .git/COMMIT_EDITMSG >actual && 555 test_cmp expect actual 556 ' 557 558 test_expect_success 'cherry-pick preserves sparse-checkout' ' 559 pristine_detach initial && 560 test_config core.sparseCheckout true && 561 test_when_finished " 562 echo \"/*\" >.git/info/sparse-checkout 563 git read-tree --reset -u HEAD 564 rm .git/info/sparse-checkout" && 565 mkdir .git/info && 566 echo /unrelated >.git/info/sparse-checkout && 567 git read-tree --reset -u HEAD && 568 test_must_fail git cherry-pick -Xours picked>actual && 569 test_grep ! "Changes not staged for commit:" actual 570 ' 571 572 test_expect_success 'cherry-pick --continue remembers --keep-redundant-commits' ' 573 test_when_finished "git cherry-pick --abort || :" && 574 pristine_detach initial && 575 test_must_fail git cherry-pick --keep-redundant-commits picked redundant && 576 echo c >foo && 577 git add foo && 578 git cherry-pick --continue 579 ' 580 581 test_expect_success 'cherry-pick --continue remembers --allow-empty and --allow-empty-message' ' 582 test_when_finished "git cherry-pick --abort || :" && 583 pristine_detach initial && 584 test_must_fail git cherry-pick --allow-empty --allow-empty-message \ 585 picked empty && 586 echo c >foo && 587 git add foo && 588 git cherry-pick --continue 589 ' 590 591 test_done