Git fork
at reftables-rust 1031 lines 26 kB view raw
1#!/bin/sh 2 3test_description='git commit porcelain-ish' 4 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8. ./test-lib.sh 9 10commit_msg_is () { 11 expect=commit_msg_is.expect 12 actual=commit_msg_is.actual 13 14 printf "%s" "$(git log --pretty=format:%s%b -1)" >$actual && 15 printf "%s" "$1" >$expect && 16 test_cmp $expect $actual 17} 18 19# Arguments: [<prefix] [<commit message>] [<commit options>] 20check_summary_oneline() { 21 test_tick && 22 git commit ${3+"$3"} -m "$2" >raw && 23 head -n 1 raw >act && 24 25 # branch name 26 SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" && 27 28 # append the "special" prefix, like "root-commit", "detached HEAD" 29 if test -n "$1" 30 then 31 SUMMARY_PREFIX="$SUMMARY_PREFIX ($1)" 32 fi 33 34 # abbrev SHA-1 35 SUMMARY_POSTFIX="$(git log -1 --pretty='format:%h')" 36 echo "[$SUMMARY_PREFIX $SUMMARY_POSTFIX] $2" >exp && 37 38 test_cmp exp act 39} 40 41trailer_commit_base () { 42 echo "fun" >>file && 43 git add file && 44 git commit -s --trailer "Signed-off-by=C1 E1 " \ 45 --trailer "Helped-by:C2 E2 " \ 46 --trailer "Reported-by=C3 E3" \ 47 --trailer "Mentored-by:C4 E4" \ 48 -m "hello" 49} 50 51test_expect_success 'output summary format' ' 52 53 echo new >file1 && 54 git add file1 && 55 check_summary_oneline "root-commit" "initial" && 56 57 echo change >>file1 && 58 git add file1 59' 60 61test_expect_success 'output summary format: root-commit' ' 62 check_summary_oneline "" "a change" 63' 64 65test_expect_success 'output summary format for commit with an empty diff' ' 66 67 check_summary_oneline "" "empty" "--allow-empty" 68' 69 70test_expect_success 'output summary format for merges' ' 71 72 git checkout -b recursive-base && 73 test_commit base file1 && 74 75 git checkout -b recursive-a recursive-base && 76 test_commit commit-a file1 && 77 78 git checkout -b recursive-b recursive-base && 79 test_commit commit-b file1 && 80 81 # conflict 82 git checkout recursive-a && 83 test_must_fail git merge recursive-b && 84 # resolve the conflict 85 echo commit-a >file1 && 86 git add file1 && 87 check_summary_oneline "" "Merge" 88' 89 90output_tests_cleanup() { 91 # this is needed for "do not fire editor in the presence of conflicts" 92 git checkout main && 93 94 # this is needed for the "partial removal" test to pass 95 git rm file1 && 96 git commit -m "cleanup" 97} 98 99test_expect_success 'the basics' ' 100 101 output_tests_cleanup && 102 103 echo doing partial >"commit is" && 104 mkdir not && 105 echo very much encouraged but we should >not/forbid && 106 git add "commit is" not && 107 echo update added "commit is" file >"commit is" && 108 echo also update another >not/forbid && 109 test_tick && 110 git commit -a -m "initial with -a" && 111 112 git cat-file blob HEAD:"commit is" >current.1 && 113 git cat-file blob HEAD:not/forbid >current.2 && 114 115 cmp current.1 "commit is" && 116 cmp current.2 not/forbid 117 118' 119 120test_expect_success 'partial' ' 121 122 echo another >"commit is" && 123 echo another >not/forbid && 124 test_tick && 125 git commit -m "partial commit to handle a file" "commit is" && 126 127 changed=$(git diff-tree --name-only HEAD^ HEAD) && 128 test "$changed" = "commit is" 129 130' 131 132test_expect_success 'partial modification in a subdirectory' ' 133 134 test_tick && 135 git commit -m "partial commit to subdirectory" not && 136 137 changed=$(git diff-tree -r --name-only HEAD^ HEAD) && 138 test "$changed" = "not/forbid" 139 140' 141 142test_expect_success 'partial removal' ' 143 144 git rm not/forbid && 145 git commit -m "partial commit to remove not/forbid" not && 146 147 changed=$(git diff-tree -r --name-only HEAD^ HEAD) && 148 test "$changed" = "not/forbid" && 149 remain=$(git ls-tree -r --name-only HEAD) && 150 test "$remain" = "commit is" 151 152' 153 154test_expect_success 'sign off' ' 155 156 >positive && 157 git add positive && 158 git commit -s -m "thank you" && 159 git cat-file commit HEAD >commit.msg && 160 sed -ne "s/Signed-off-by: //p" commit.msg >actual && 161 git var GIT_COMMITTER_IDENT >ident && 162 sed -e "s/>.*/>/" ident >expected && 163 test_cmp expected actual 164 165' 166 167test_expect_success 'commit --trailer with "="' ' 168 trailer_commit_base && 169 cat >expected <<-\EOF && 170 hello 171 172 Signed-off-by: C O Mitter <committer@example.com> 173 Signed-off-by: C1 E1 174 Helped-by: C2 E2 175 Reported-by: C3 E3 176 Mentored-by: C4 E4 177 EOF 178 git cat-file commit HEAD >commit.msg && 179 sed -e "1,/^\$/d" commit.msg >actual && 180 test_cmp expected actual 181' 182 183test_expect_success 'commit --trailer with -c and "replace" as ifexists' ' 184 trailer_commit_base && 185 cat >expected <<-\EOF && 186 hello 187 188 Signed-off-by: C O Mitter <committer@example.com> 189 Signed-off-by: C1 E1 190 Reported-by: C3 E3 191 Mentored-by: C4 E4 192 Helped-by: C3 E3 193 EOF 194 git -c trailer.ifexists="replace" \ 195 commit --trailer "Mentored-by: C4 E4" \ 196 --trailer "Helped-by: C3 E3" \ 197 --amend && 198 git cat-file commit HEAD >commit.msg && 199 sed -e "1,/^\$/d" commit.msg >actual && 200 test_cmp expected actual 201' 202 203test_expect_success 'commit --trailer with -c and "add" as ifexists' ' 204 trailer_commit_base && 205 cat >expected <<-\EOF && 206 hello 207 208 Signed-off-by: C O Mitter <committer@example.com> 209 Signed-off-by: C1 E1 210 Helped-by: C2 E2 211 Reported-by: C3 E3 212 Mentored-by: C4 E4 213 Reported-by: C3 E3 214 Mentored-by: C4 E4 215 EOF 216 git -c trailer.ifexists="add" \ 217 commit --trailer "Reported-by: C3 E3" \ 218 --trailer "Mentored-by: C4 E4" \ 219 --amend && 220 git cat-file commit HEAD >commit.msg && 221 sed -e "1,/^\$/d" commit.msg >actual && 222 test_cmp expected actual 223' 224 225test_expect_success 'commit --trailer with -c and "donothing" as ifexists' ' 226 trailer_commit_base && 227 cat >expected <<-\EOF && 228 hello 229 230 Signed-off-by: C O Mitter <committer@example.com> 231 Signed-off-by: C1 E1 232 Helped-by: C2 E2 233 Reported-by: C3 E3 234 Mentored-by: C4 E4 235 Reviewed-by: C6 E6 236 EOF 237 git -c trailer.ifexists="donothing" \ 238 commit --trailer "Mentored-by: C5 E5" \ 239 --trailer "Reviewed-by: C6 E6" \ 240 --amend && 241 git cat-file commit HEAD >commit.msg && 242 sed -e "1,/^\$/d" commit.msg >actual && 243 test_cmp expected actual 244' 245 246test_expect_success 'commit --trailer with -c and "addIfDifferent" as ifexists' ' 247 trailer_commit_base && 248 cat >expected <<-\EOF && 249 hello 250 251 Signed-off-by: C O Mitter <committer@example.com> 252 Signed-off-by: C1 E1 253 Helped-by: C2 E2 254 Reported-by: C3 E3 255 Mentored-by: C4 E4 256 Mentored-by: C5 E5 257 EOF 258 git -c trailer.ifexists="addIfDifferent" \ 259 commit --trailer "Reported-by: C3 E3" \ 260 --trailer "Mentored-by: C5 E5" \ 261 --amend && 262 git cat-file commit HEAD >commit.msg && 263 sed -e "1,/^\$/d" commit.msg >actual && 264 test_cmp expected actual 265' 266 267test_expect_success 'commit --trailer with -c and "addIfDifferentNeighbor" as ifexists' ' 268 trailer_commit_base && 269 cat >expected <<-\EOF && 270 hello 271 272 Signed-off-by: C O Mitter <committer@example.com> 273 Signed-off-by: C1 E1 274 Helped-by: C2 E2 275 Reported-by: C3 E3 276 Mentored-by: C4 E4 277 Reported-by: C3 E3 278 EOF 279 git -c trailer.ifexists="addIfDifferentNeighbor" \ 280 commit --trailer "Mentored-by: C4 E4" \ 281 --trailer "Reported-by: C3 E3" \ 282 --amend && 283 git cat-file commit HEAD >commit.msg && 284 sed -e "1,/^\$/d" commit.msg >actual && 285 test_cmp expected actual 286' 287 288test_expect_success 'commit --trailer with -c and "end" as where' ' 289 trailer_commit_base && 290 cat >expected <<-\EOF && 291 hello 292 293 Signed-off-by: C O Mitter <committer@example.com> 294 Signed-off-by: C1 E1 295 Helped-by: C2 E2 296 Reported-by: C3 E3 297 Mentored-by: C4 E4 298 Reported-by: C3 E3 299 Mentored-by: C4 E4 300 EOF 301 git -c trailer.where="end" \ 302 commit --trailer "Reported-by: C3 E3" \ 303 --trailer "Mentored-by: C4 E4" \ 304 --amend && 305 git cat-file commit HEAD >commit.msg && 306 sed -e "1,/^\$/d" commit.msg >actual && 307 test_cmp expected actual 308' 309 310test_expect_success 'commit --trailer with -c and "start" as where' ' 311 trailer_commit_base && 312 cat >expected <<-\EOF && 313 hello 314 315 Signed-off-by: C1 E1 316 Signed-off-by: C O Mitter <committer@example.com> 317 Signed-off-by: C1 E1 318 Helped-by: C2 E2 319 Reported-by: C3 E3 320 Mentored-by: C4 E4 321 EOF 322 git -c trailer.where="start" \ 323 commit --trailer "Signed-off-by: C O Mitter <committer@example.com>" \ 324 --trailer "Signed-off-by: C1 E1" \ 325 --amend && 326 git cat-file commit HEAD >commit.msg && 327 sed -e "1,/^\$/d" commit.msg >actual && 328 test_cmp expected actual 329' 330 331test_expect_success 'commit --trailer with -c and "after" as where' ' 332 trailer_commit_base && 333 cat >expected <<-\EOF && 334 hello 335 336 Signed-off-by: C O Mitter <committer@example.com> 337 Signed-off-by: C1 E1 338 Helped-by: C2 E2 339 Reported-by: C3 E3 340 Mentored-by: C4 E4 341 Mentored-by: C5 E5 342 EOF 343 git -c trailer.where="after" \ 344 commit --trailer "Mentored-by: C4 E4" \ 345 --trailer "Mentored-by: C5 E5" \ 346 --amend && 347 git cat-file commit HEAD >commit.msg && 348 sed -e "1,/^\$/d" commit.msg >actual && 349 test_cmp expected actual 350' 351 352test_expect_success 'commit --trailer with -c and "before" as where' ' 353 trailer_commit_base && 354 cat >expected <<-\EOF && 355 hello 356 357 Signed-off-by: C O Mitter <committer@example.com> 358 Signed-off-by: C1 E1 359 Helped-by: C2 E2 360 Reported-by: C3 E3 361 Mentored-by: C2 E2 362 Mentored-by: C3 E3 363 Mentored-by: C4 E4 364 EOF 365 git -c trailer.where="before" \ 366 commit --trailer "Mentored-by: C3 E3" \ 367 --trailer "Mentored-by: C2 E2" \ 368 --amend && 369 git cat-file commit HEAD >commit.msg && 370 sed -e "1,/^\$/d" commit.msg >actual && 371 test_cmp expected actual 372' 373 374test_expect_success 'commit --trailer with -c and "donothing" as ifmissing' ' 375 trailer_commit_base && 376 cat >expected <<-\EOF && 377 hello 378 379 Signed-off-by: C O Mitter <committer@example.com> 380 Signed-off-by: C1 E1 381 Helped-by: C2 E2 382 Reported-by: C3 E3 383 Mentored-by: C4 E4 384 Helped-by: C5 E5 385 EOF 386 git -c trailer.ifmissing="donothing" \ 387 commit --trailer "Helped-by: C5 E5" \ 388 --trailer "Based-by: C6 E6" \ 389 --amend && 390 git cat-file commit HEAD >commit.msg && 391 sed -e "1,/^\$/d" commit.msg >actual && 392 test_cmp expected actual 393' 394 395test_expect_success 'commit --trailer with -c and "add" as ifmissing' ' 396 trailer_commit_base && 397 cat >expected <<-\EOF && 398 hello 399 400 Signed-off-by: C O Mitter <committer@example.com> 401 Signed-off-by: C1 E1 402 Helped-by: C2 E2 403 Reported-by: C3 E3 404 Mentored-by: C4 E4 405 Helped-by: C5 E5 406 Based-by: C6 E6 407 EOF 408 git -c trailer.ifmissing="add" \ 409 commit --trailer "Helped-by: C5 E5" \ 410 --trailer "Based-by: C6 E6" \ 411 --amend && 412 git cat-file commit HEAD >commit.msg && 413 sed -e "1,/^\$/d" commit.msg >actual && 414 test_cmp expected actual 415' 416 417test_expect_success 'commit --trailer with -c ack.key ' ' 418 echo "fun" >>file1 && 419 git add file1 && 420 cat >expected <<-\EOF && 421 hello 422 423 Acked-by: Peff 424 EOF 425 git -c trailer.ack.key="Acked-by" \ 426 commit --trailer "ack = Peff" -m "hello" && 427 git cat-file commit HEAD >commit.msg && 428 sed -e "1,/^\$/d" commit.msg >actual && 429 test_cmp expected actual 430' 431 432test_expect_success 'commit --trailer with -c and ":=#" as separators' ' 433 echo "fun" >>file1 && 434 git add file1 && 435 cat >expected <<-\EOF && 436 I hate bug 437 438 Bug #42 439 EOF 440 git -c trailer.separators=":=#" \ 441 -c trailer.bug.key="Bug #" \ 442 commit --trailer "bug = 42" -m "I hate bug" && 443 git cat-file commit HEAD >commit.msg && 444 sed -e "1,/^\$/d" commit.msg >actual && 445 test_cmp expected actual 446' 447 448test_expect_success 'commit --trailer with -c and command' ' 449 trailer_commit_base && 450 cat >expected <<-\EOF && 451 hello 452 453 Signed-off-by: C O Mitter <committer@example.com> 454 Signed-off-by: C1 E1 455 Helped-by: C2 E2 456 Mentored-by: C4 E4 457 Reported-by: A U Thor <author@example.com> 458 EOF 459 git -c trailer.report.key="Reported-by: " \ 460 -c trailer.report.ifexists="replace" \ 461 -c trailer.report.command="NAME=\"\$ARG\"; test -n \"\$NAME\" && \ 462 git log --author=\"\$NAME\" -1 --format=\"format:%aN <%aE>\" || true" \ 463 commit --trailer "report = author" --amend && 464 git cat-file commit HEAD >commit.msg && 465 sed -e "1,/^\$/d" commit.msg >actual && 466 test_cmp expected actual 467' 468 469test_expect_success 'commit --trailer not confused by --- separator' ' 470 cat >msg <<-\EOF && 471 subject 472 473 body with dashes 474 --- 475 in it 476 EOF 477 git commit --allow-empty --trailer="my-trailer: value" -F msg && 478 { 479 cat msg && 480 echo && 481 echo "my-trailer: value" 482 } >expected && 483 git cat-file commit HEAD >commit.msg && 484 sed -e "1,/^\$/d" commit.msg >actual && 485 test_cmp expected actual 486' 487 488test_expect_success 'commit --trailer with --verbose' ' 489 cat >msg <<-\EOF && 490 subject 491 492 body 493 EOF 494 GIT_EDITOR=: git commit --edit -F msg --allow-empty \ 495 --trailer="my-trailer: value" --verbose && 496 { 497 cat msg && 498 echo && 499 echo "my-trailer: value" 500 } >expected && 501 git cat-file commit HEAD >commit.msg && 502 sed -e "1,/^\$/d" commit.msg >actual && 503 test_cmp expected actual 504' 505 506test_expect_success 'multiple -m' ' 507 508 >negative && 509 git add negative && 510 git commit -m "one" -m "two" -m "three" && 511 actual=$(git cat-file commit HEAD >tmp && sed -e "1,/^\$/d" tmp && rm tmp) && 512 expected=$(test_write_lines "one" "" "two" "" "three") && 513 test "z$actual" = "z$expected" 514 515' 516 517test_expect_success 'verbose' ' 518 519 echo minus >negative && 520 git add negative && 521 git status -v >raw && 522 sed -ne "/^diff --git /p" raw >actual && 523 echo "diff --git a/negative b/negative" >expect && 524 test_cmp expect actual 525 526' 527 528test_expect_success 'verbose respects diff config' ' 529 530 test_config diff.noprefix true && 531 git status -v >actual && 532 grep "diff --git negative negative" actual 533' 534 535mesg_with_comment_and_newlines=' 536# text 537 538' 539 540test_expect_success 'prepare file with comment line and trailing newlines' ' 541 printf "%s" "$mesg_with_comment_and_newlines" >expect 542' 543 544test_expect_success 'cleanup commit messages (verbatim option,-t)' ' 545 546 echo >>negative && 547 git commit --cleanup=verbatim --no-status -t expect -a && 548 git cat-file -p HEAD >raw && 549 sed -e "1,/^\$/d" raw >actual && 550 test_cmp expect actual 551 552' 553 554test_expect_success 'cleanup commit messages (verbatim option,-F)' ' 555 556 echo >>negative && 557 git commit --cleanup=verbatim -F expect -a && 558 git cat-file -p HEAD >raw && 559 sed -e "1,/^\$/d" raw >actual && 560 test_cmp expect actual 561 562' 563 564test_expect_success 'cleanup commit messages (verbatim option,-m)' ' 565 566 echo >>negative && 567 git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a && 568 git cat-file -p HEAD >raw && 569 sed -e "1,/^\$/d" raw >actual && 570 test_cmp expect actual 571 572' 573 574test_expect_success 'cleanup commit messages (whitespace option,-F)' ' 575 576 echo >>negative && 577 test_write_lines "" "# text" "" >text && 578 echo "# text" >expect && 579 git commit --cleanup=whitespace -F text -a && 580 git cat-file -p HEAD >raw && 581 sed -e "1,/^\$/d" raw >actual && 582 test_cmp expect actual 583 584' 585 586test_expect_success 'cleanup commit messages (scissors option,-F,-e)' ' 587 588 echo >>negative && 589 cat >text <<-\EOF && 590 591 # to be kept 592 593 # ------------------------ >8 ------------------------ 594 # to be kept, too 595 # ------------------------ >8 ------------------------ 596 to be removed 597 # ------------------------ >8 ------------------------ 598 to be removed, too 599 EOF 600 601 cat >expect <<-\EOF && 602 # to be kept 603 604 # ------------------------ >8 ------------------------ 605 # to be kept, too 606 EOF 607 git commit --cleanup=scissors -e -F text -a && 608 git cat-file -p HEAD >raw && 609 sed -e "1,/^\$/d" raw >actual && 610 test_cmp expect actual 611' 612 613test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line)' ' 614 615 echo >>negative && 616 cat >text <<-\EOF && 617 # ------------------------ >8 ------------------------ 618 to be removed 619 EOF 620 git commit --cleanup=scissors -e -F text -a --allow-empty-message && 621 git cat-file -p HEAD >raw && 622 sed -e "1,/^\$/d" raw >actual && 623 test_must_be_empty actual 624' 625 626test_expect_success 'cleanup commit messages (strip option,-F)' ' 627 628 echo >>negative && 629 test_write_lines "" "# text" "sample" "" >text && 630 echo sample >expect && 631 git commit --cleanup=strip -F text -a && 632 git cat-file -p HEAD >raw && 633 sed -e "1,/^\$/d" raw >actual && 634 test_cmp expect actual 635 636' 637 638test_expect_success 'cleanup commit messages (strip option,-F,-e)' ' 639 640 echo >>negative && 641 test_write_lines "" "sample" "" >text && 642 git commit -e -F text -a && 643 head -n 4 .git/COMMIT_EDITMSG >actual 644' 645 646echo "sample 647 648# Please enter the commit message for your changes. Lines starting 649# with '#' will be ignored, and an empty message aborts the commit." >expect 650 651test_expect_success 'cleanup commit messages (strip option,-F,-e): output' ' 652 test_cmp expect actual 653' 654 655test_expect_success 'cleanup commit message (fail on invalid cleanup mode option)' ' 656 test_must_fail git commit --cleanup=non-existent 657' 658 659test_expect_success 'cleanup commit message (fail on invalid cleanup mode configuration)' ' 660 test_must_fail git -c commit.cleanup=non-existent commit 661' 662 663test_expect_success 'cleanup commit message (no config and no option uses default)' ' 664 echo content >>file && 665 git add file && 666 ( 667 test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment && 668 git commit --no-status 669 ) && 670 commit_msg_is "commit message" 671' 672 673test_expect_success 'cleanup commit message (option overrides default)' ' 674 echo content >>file && 675 git add file && 676 ( 677 test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment && 678 git commit --cleanup=whitespace --no-status 679 ) && 680 commit_msg_is "commit message # comment" 681' 682 683test_expect_success 'cleanup commit message (config overrides default)' ' 684 echo content >>file && 685 git add file && 686 ( 687 test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment && 688 git -c commit.cleanup=whitespace commit --no-status 689 ) && 690 commit_msg_is "commit message # comment" 691' 692 693test_expect_success 'cleanup commit message (option overrides config)' ' 694 echo content >>file && 695 git add file && 696 ( 697 test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment && 698 git -c commit.cleanup=whitespace commit --cleanup=default 699 ) && 700 commit_msg_is "commit message" 701' 702 703test_expect_success 'cleanup commit message (default, -m)' ' 704 echo content >>file && 705 git add file && 706 git commit -m "message #comment " && 707 commit_msg_is "message #comment" 708' 709 710test_expect_success 'cleanup commit message (whitespace option, -m)' ' 711 echo content >>file && 712 git add file && 713 git commit --cleanup=whitespace --no-status -m "message #comment " && 714 commit_msg_is "message #comment" 715' 716 717test_expect_success 'cleanup commit message (whitespace config, -m)' ' 718 echo content >>file && 719 git add file && 720 git -c commit.cleanup=whitespace commit --no-status -m "message #comment " && 721 commit_msg_is "message #comment" 722' 723 724test_expect_success 'message shows author when it is not equal to committer' ' 725 echo >>negative && 726 git commit -e -m "sample" -a && 727 test_grep \ 728 "^# Author: *A U Thor <author@example.com>\$" \ 729 .git/COMMIT_EDITMSG 730' 731 732test_expect_success 'message shows date when it is explicitly set' ' 733 git commit --allow-empty -e -m foo --date="2010-01-02T03:04:05" && 734 test_grep \ 735 "^# Date: *Sat Jan 2 03:04:05 2010 +0000" \ 736 .git/COMMIT_EDITMSG 737' 738 739test_expect_success 'message does not have multiple scissors lines' ' 740 git commit --cleanup=scissors -v --allow-empty -e -m foo && 741 test $(grep -c -e "--- >8 ---" .git/COMMIT_EDITMSG) -eq 1 742' 743 744test_expect_success AUTOIDENT 'message shows committer when it is automatic' ' 745 746 echo >>negative && 747 ( 748 sane_unset GIT_COMMITTER_EMAIL && 749 sane_unset GIT_COMMITTER_NAME && 750 git commit -e -m "sample" -a 751 ) && 752 # the ident is calculated from the system, so we cannot 753 # check the actual value, only that it is there 754 test_grep "^# Committer: " .git/COMMIT_EDITMSG 755' 756 757write_script .git/FAKE_EDITOR <<EOF 758echo editor started >"$(pwd)/.git/result" 759exit 0 760EOF 761 762test_expect_success !FAIL_PREREQS,!AUTOIDENT 'do not fire editor when committer is bogus' ' 763 >.git/result && 764 765 echo >>negative && 766 ( 767 sane_unset GIT_COMMITTER_EMAIL && 768 sane_unset GIT_COMMITTER_NAME && 769 GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" && 770 export GIT_EDITOR && 771 test_must_fail git commit -e -m sample -a 772 ) && 773 test_must_be_empty .git/result 774' 775 776test_expect_success 'do not fire editor if -m <msg> was given' ' 777 echo tick >file && 778 git add file && 779 echo "editor not started" >.git/result && 780 (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" git commit -m tick) && 781 test "$(cat .git/result)" = "editor not started" 782' 783 784test_expect_success 'do not fire editor if -m "" was given' ' 785 echo tock >file && 786 git add file && 787 echo "editor not started" >.git/result && 788 (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" \ 789 git commit -m "" --allow-empty-message) && 790 test "$(cat .git/result)" = "editor not started" 791' 792 793test_expect_success 'do not fire editor in the presence of conflicts' ' 794 795 git clean -f && 796 echo f >g && 797 git add g && 798 git commit -m "add g" && 799 git branch second && 800 echo main >g && 801 echo g >h && 802 git add g h && 803 git commit -m "modify g and add h" && 804 git checkout second && 805 echo second >g && 806 git add g && 807 git commit -m second && 808 # Must fail due to conflict 809 test_must_fail git cherry-pick -n main && 810 echo "editor not started" >.git/result && 811 ( 812 GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" && 813 export GIT_EDITOR && 814 test_must_fail git commit 815 ) && 816 test "$(cat .git/result)" = "editor not started" 817' 818 819write_script .git/FAKE_EDITOR <<EOF 820# kill -TERM command added below. 821EOF 822 823test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' ' 824 echo >>negative && 825 ! "$SHELL_PATH" -c '\'' 826 echo kill -TERM $$ >>.git/FAKE_EDITOR 827 GIT_EDITOR=.git/FAKE_EDITOR 828 export GIT_EDITOR 829 exec git commit -a'\'' && 830 test ! -f .git/index.lock 831' 832 833rm -f .git/MERGE_MSG .git/COMMIT_EDITMSG 834git reset -q --hard 835 836test_expect_success 'Hand committing of a redundant merge removes dups' ' 837 838 git rev-parse second main >expect && 839 test_must_fail git merge second main && 840 git checkout main g && 841 EDITOR=: git commit -a && 842 git cat-file commit HEAD >raw && 843 sed -n -e "s/^parent //p" -e "/^$/q" raw >actual && 844 test_cmp expect actual 845 846' 847 848test_expect_success 'A single-liner subject with a token plus colon is not a footer' ' 849 850 git reset --hard && 851 git commit -s -m "hello: kitty" --allow-empty && 852 git cat-file commit HEAD >raw && 853 sed -e "1,/^$/d" raw >actual && 854 test_line_count = 3 actual 855 856' 857 858test_expect_success 'commit -s places sob on third line after two empty lines' ' 859 git commit -s --allow-empty --allow-empty-message && 860 cat <<-EOF >expect && 861 862 863 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 864 865 EOF 866 sed -e "/^#/d" -e "s/^:.*//" .git/COMMIT_EDITMSG >actual && 867 test_cmp expect actual 868' 869 870write_script .git/FAKE_EDITOR <<\EOF 871mv "$1" "$1.orig" 872( 873 echo message 874 cat "$1.orig" 875) >"$1" 876EOF 877 878echo '## Custom template' >template 879 880try_commit () { 881 git reset --hard && 882 echo >>negative && 883 GIT_EDITOR=.git/FAKE_EDITOR git commit -a $* $use_template && 884 case "$use_template" in 885 '') 886 test_grep ! "^## Custom template" .git/COMMIT_EDITMSG ;; 887 *) 888 test_grep "^## Custom template" .git/COMMIT_EDITMSG ;; 889 esac 890} 891 892try_commit_status_combo () { 893 894 test_expect_success 'commit' ' 895 try_commit "" && 896 test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG 897 ' 898 899 test_expect_success 'commit --status' ' 900 try_commit --status && 901 test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG 902 ' 903 904 test_expect_success 'commit --no-status' ' 905 try_commit --no-status && 906 test_grep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG 907 ' 908 909 test_expect_success 'commit with commit.status = yes' ' 910 test_config commit.status yes && 911 try_commit "" && 912 test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG 913 ' 914 915 test_expect_success 'commit with commit.status = no' ' 916 test_config commit.status no && 917 try_commit "" && 918 test_grep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG 919 ' 920 921 test_expect_success 'commit --status with commit.status = yes' ' 922 test_config commit.status yes && 923 try_commit --status && 924 test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG 925 ' 926 927 test_expect_success 'commit --no-status with commit.status = yes' ' 928 test_config commit.status yes && 929 try_commit --no-status && 930 test_grep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG 931 ' 932 933 test_expect_success 'commit --status with commit.status = no' ' 934 test_config commit.status no && 935 try_commit --status && 936 test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG 937 ' 938 939 test_expect_success 'commit --no-status with commit.status = no' ' 940 test_config commit.status no && 941 try_commit --no-status && 942 test_grep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG 943 ' 944 945} 946 947try_commit_status_combo 948 949use_template="-t template" 950 951try_commit_status_combo 952 953test_expect_success 'commit --status with custom comment character' ' 954 test_config core.commentchar ";" && 955 try_commit --status && 956 test_grep "^; Changes to be committed:" .git/COMMIT_EDITMSG 957' 958 959test_expect_success !WITH_BREAKING_CHANGES 'switch core.commentchar' ' 960 test_commit "#foo" foo && 961 cat >config-include <<-\EOF && 962 [core] 963 commentString=: 964 commentString=% 965 commentChar=auto 966 EOF 967 test_when_finished "rm config-include" && 968 test_config include.path "$(pwd)/config-include" && 969 test_config core.commentChar ! && 970 GIT_EDITOR=.git/FAKE_EDITOR git commit --amend 2>err && 971 sed -n "s/^hint: *\$//p; s/^hint: //p; s/^warning: //p" err >actual && 972 cat >expect <<-EOF && 973 Support for ${SQ}core.commentChar=auto${SQ} is deprecated and will be removed in Git 3.0 974 975 To use the default comment string (#) please run 976 977 git config unset core.commentChar 978 git config unset --file ~/config-include --all core.commentString 979 git config unset --file ~/config-include core.commentChar 980 981 To set a custom comment string please run 982 983 git config set --file ~/config-include core.commentChar <comment string> 984 985 where ${SQ}<comment string>${SQ} is the string you wish to use. 986 EOF 987 test_cmp expect actual && 988 test_grep "^; Changes to be committed:" .git/COMMIT_EDITMSG 989' 990 991test_expect_success !WITH_BREAKING_CHANGES 'switch core.commentchar but out of options' ' 992 cat >text <<\EOF && 993# 1 994; 2 995@ 3 996! 4 997$ 5 998% 6 999^ 7 1000& 8 1001| 9 1002: 10 1003EOF 1004 git commit --amend -F text && 1005 ( 1006 test_set_editor .git/FAKE_EDITOR && 1007 test_must_fail git -c core.commentChar=auto commit --amend 1008 ) 1009' 1010 1011test_expect_success WITH_BREAKING_CHANGES 'core.commentChar=auto is rejected' ' 1012 test_config core.commentChar auto && 1013 test_must_fail git rev-parse --git-dir 2>err && 1014 sed -n "s/^hint: *\$//p; s/^hint: //p; s/^fatal: //p" err >actual && 1015 cat >expect <<-EOF && 1016 Support for ${SQ}core.commentChar=auto${SQ} has been removed in Git 3.0 1017 1018 To use the default comment string (#) please run 1019 1020 git config unset core.commentChar 1021 1022 To set a custom comment string please run 1023 1024 git config set core.commentChar <comment string> 1025 1026 where ${SQ}<comment string>${SQ} is the string you wish to use. 1027 EOF 1028 test_cmp expect actual 1029' 1030 1031test_done