The eleventh batch
[git/gitster.git] / t / t7502-commit-porcelain.sh
blob84f1ff52b6738d3123de4d66f1d10d744bfd9e4b
1 #!/bin/sh
3 test_description='git commit porcelain-ish'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 commit_msg_is () {
12 expect=commit_msg_is.expect
13 actual=commit_msg_is.actual
15 printf "%s" "$(git log --pretty=format:%s%b -1)" >$actual &&
16 printf "%s" "$1" >$expect &&
17 test_cmp $expect $actual
20 # Arguments: [<prefix] [<commit message>] [<commit options>]
21 check_summary_oneline() {
22 test_tick &&
23 git commit ${3+"$3"} -m "$2" >raw &&
24 head -n 1 raw >act &&
26 # branch name
27 SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" &&
29 # append the "special" prefix, like "root-commit", "detached HEAD"
30 if test -n "$1"
31 then
32 SUMMARY_PREFIX="$SUMMARY_PREFIX ($1)"
35 # abbrev SHA-1
36 SUMMARY_POSTFIX="$(git log -1 --pretty='format:%h')"
37 echo "[$SUMMARY_PREFIX $SUMMARY_POSTFIX] $2" >exp &&
39 test_cmp exp act
42 trailer_commit_base () {
43 echo "fun" >>file &&
44 git add file &&
45 git commit -s --trailer "Signed-off-by=C1 E1 " \
46 --trailer "Helped-by:C2 E2 " \
47 --trailer "Reported-by=C3 E3" \
48 --trailer "Mentored-by:C4 E4" \
49 -m "hello"
52 test_expect_success 'output summary format' '
54 echo new >file1 &&
55 git add file1 &&
56 check_summary_oneline "root-commit" "initial" &&
58 echo change >>file1 &&
59 git add file1
62 test_expect_success 'output summary format: root-commit' '
63 check_summary_oneline "" "a change"
66 test_expect_success 'output summary format for commit with an empty diff' '
68 check_summary_oneline "" "empty" "--allow-empty"
71 test_expect_success 'output summary format for merges' '
73 git checkout -b recursive-base &&
74 test_commit base file1 &&
76 git checkout -b recursive-a recursive-base &&
77 test_commit commit-a file1 &&
79 git checkout -b recursive-b recursive-base &&
80 test_commit commit-b file1 &&
82 # conflict
83 git checkout recursive-a &&
84 test_must_fail git merge recursive-b &&
85 # resolve the conflict
86 echo commit-a >file1 &&
87 git add file1 &&
88 check_summary_oneline "" "Merge"
91 output_tests_cleanup() {
92 # this is needed for "do not fire editor in the presence of conflicts"
93 git checkout main &&
95 # this is needed for the "partial removal" test to pass
96 git rm file1 &&
97 git commit -m "cleanup"
100 test_expect_success 'the basics' '
102 output_tests_cleanup &&
104 echo doing partial >"commit is" &&
105 mkdir not &&
106 echo very much encouraged but we should >not/forbid &&
107 git add "commit is" not &&
108 echo update added "commit is" file >"commit is" &&
109 echo also update another >not/forbid &&
110 test_tick &&
111 git commit -a -m "initial with -a" &&
113 git cat-file blob HEAD:"commit is" >current.1 &&
114 git cat-file blob HEAD:not/forbid >current.2 &&
116 cmp current.1 "commit is" &&
117 cmp current.2 not/forbid
121 test_expect_success 'partial' '
123 echo another >"commit is" &&
124 echo another >not/forbid &&
125 test_tick &&
126 git commit -m "partial commit to handle a file" "commit is" &&
128 changed=$(git diff-tree --name-only HEAD^ HEAD) &&
129 test "$changed" = "commit is"
133 test_expect_success 'partial modification in a subdirectory' '
135 test_tick &&
136 git commit -m "partial commit to subdirectory" not &&
138 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
139 test "$changed" = "not/forbid"
143 test_expect_success 'partial removal' '
145 git rm not/forbid &&
146 git commit -m "partial commit to remove not/forbid" not &&
148 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
149 test "$changed" = "not/forbid" &&
150 remain=$(git ls-tree -r --name-only HEAD) &&
151 test "$remain" = "commit is"
155 test_expect_success 'sign off' '
157 >positive &&
158 git add positive &&
159 git commit -s -m "thank you" &&
160 git cat-file commit HEAD >commit.msg &&
161 sed -ne "s/Signed-off-by: //p" commit.msg >actual &&
162 git var GIT_COMMITTER_IDENT >ident &&
163 sed -e "s/>.*/>/" ident >expected &&
164 test_cmp expected actual
168 test_expect_success 'commit --trailer with "="' '
169 trailer_commit_base &&
170 cat >expected <<-\EOF &&
171 hello
173 Signed-off-by: C O Mitter <committer@example.com>
174 Signed-off-by: C1 E1
175 Helped-by: C2 E2
176 Reported-by: C3 E3
177 Mentored-by: C4 E4
179 git cat-file commit HEAD >commit.msg &&
180 sed -e "1,/^\$/d" commit.msg >actual &&
181 test_cmp expected actual
184 test_expect_success 'commit --trailer with -c and "replace" as ifexists' '
185 trailer_commit_base &&
186 cat >expected <<-\EOF &&
187 hello
189 Signed-off-by: C O Mitter <committer@example.com>
190 Signed-off-by: C1 E1
191 Reported-by: C3 E3
192 Mentored-by: C4 E4
193 Helped-by: C3 E3
195 git -c trailer.ifexists="replace" \
196 commit --trailer "Mentored-by: C4 E4" \
197 --trailer "Helped-by: C3 E3" \
198 --amend &&
199 git cat-file commit HEAD >commit.msg &&
200 sed -e "1,/^\$/d" commit.msg >actual &&
201 test_cmp expected actual
204 test_expect_success 'commit --trailer with -c and "add" as ifexists' '
205 trailer_commit_base &&
206 cat >expected <<-\EOF &&
207 hello
209 Signed-off-by: C O Mitter <committer@example.com>
210 Signed-off-by: C1 E1
211 Helped-by: C2 E2
212 Reported-by: C3 E3
213 Mentored-by: C4 E4
214 Reported-by: C3 E3
215 Mentored-by: C4 E4
217 git -c trailer.ifexists="add" \
218 commit --trailer "Reported-by: C3 E3" \
219 --trailer "Mentored-by: C4 E4" \
220 --amend &&
221 git cat-file commit HEAD >commit.msg &&
222 sed -e "1,/^\$/d" commit.msg >actual &&
223 test_cmp expected actual
226 test_expect_success 'commit --trailer with -c and "donothing" as ifexists' '
227 trailer_commit_base &&
228 cat >expected <<-\EOF &&
229 hello
231 Signed-off-by: C O Mitter <committer@example.com>
232 Signed-off-by: C1 E1
233 Helped-by: C2 E2
234 Reported-by: C3 E3
235 Mentored-by: C4 E4
236 Reviewed-by: C6 E6
238 git -c trailer.ifexists="donothing" \
239 commit --trailer "Mentored-by: C5 E5" \
240 --trailer "Reviewed-by: C6 E6" \
241 --amend &&
242 git cat-file commit HEAD >commit.msg &&
243 sed -e "1,/^\$/d" commit.msg >actual &&
244 test_cmp expected actual
247 test_expect_success 'commit --trailer with -c and "addIfDifferent" as ifexists' '
248 trailer_commit_base &&
249 cat >expected <<-\EOF &&
250 hello
252 Signed-off-by: C O Mitter <committer@example.com>
253 Signed-off-by: C1 E1
254 Helped-by: C2 E2
255 Reported-by: C3 E3
256 Mentored-by: C4 E4
257 Mentored-by: C5 E5
259 git -c trailer.ifexists="addIfDifferent" \
260 commit --trailer "Reported-by: C3 E3" \
261 --trailer "Mentored-by: C5 E5" \
262 --amend &&
263 git cat-file commit HEAD >commit.msg &&
264 sed -e "1,/^\$/d" commit.msg >actual &&
265 test_cmp expected actual
268 test_expect_success 'commit --trailer with -c and "addIfDifferentNeighbor" as ifexists' '
269 trailer_commit_base &&
270 cat >expected <<-\EOF &&
271 hello
273 Signed-off-by: C O Mitter <committer@example.com>
274 Signed-off-by: C1 E1
275 Helped-by: C2 E2
276 Reported-by: C3 E3
277 Mentored-by: C4 E4
278 Reported-by: C3 E3
280 git -c trailer.ifexists="addIfDifferentNeighbor" \
281 commit --trailer "Mentored-by: C4 E4" \
282 --trailer "Reported-by: C3 E3" \
283 --amend &&
284 git cat-file commit HEAD >commit.msg &&
285 sed -e "1,/^\$/d" commit.msg >actual &&
286 test_cmp expected actual
289 test_expect_success 'commit --trailer with -c and "end" as where' '
290 trailer_commit_base &&
291 cat >expected <<-\EOF &&
292 hello
294 Signed-off-by: C O Mitter <committer@example.com>
295 Signed-off-by: C1 E1
296 Helped-by: C2 E2
297 Reported-by: C3 E3
298 Mentored-by: C4 E4
299 Reported-by: C3 E3
300 Mentored-by: C4 E4
302 git -c trailer.where="end" \
303 commit --trailer "Reported-by: C3 E3" \
304 --trailer "Mentored-by: C4 E4" \
305 --amend &&
306 git cat-file commit HEAD >commit.msg &&
307 sed -e "1,/^\$/d" commit.msg >actual &&
308 test_cmp expected actual
311 test_expect_success 'commit --trailer with -c and "start" as where' '
312 trailer_commit_base &&
313 cat >expected <<-\EOF &&
314 hello
316 Signed-off-by: C1 E1
317 Signed-off-by: C O Mitter <committer@example.com>
318 Signed-off-by: C1 E1
319 Helped-by: C2 E2
320 Reported-by: C3 E3
321 Mentored-by: C4 E4
323 git -c trailer.where="start" \
324 commit --trailer "Signed-off-by: C O Mitter <committer@example.com>" \
325 --trailer "Signed-off-by: C1 E1" \
326 --amend &&
327 git cat-file commit HEAD >commit.msg &&
328 sed -e "1,/^\$/d" commit.msg >actual &&
329 test_cmp expected actual
332 test_expect_success 'commit --trailer with -c and "after" as where' '
333 trailer_commit_base &&
334 cat >expected <<-\EOF &&
335 hello
337 Signed-off-by: C O Mitter <committer@example.com>
338 Signed-off-by: C1 E1
339 Helped-by: C2 E2
340 Reported-by: C3 E3
341 Mentored-by: C4 E4
342 Mentored-by: C5 E5
344 git -c trailer.where="after" \
345 commit --trailer "Mentored-by: C4 E4" \
346 --trailer "Mentored-by: C5 E5" \
347 --amend &&
348 git cat-file commit HEAD >commit.msg &&
349 sed -e "1,/^\$/d" commit.msg >actual &&
350 test_cmp expected actual
353 test_expect_success 'commit --trailer with -c and "before" as where' '
354 trailer_commit_base &&
355 cat >expected <<-\EOF &&
356 hello
358 Signed-off-by: C O Mitter <committer@example.com>
359 Signed-off-by: C1 E1
360 Helped-by: C2 E2
361 Reported-by: C3 E3
362 Mentored-by: C2 E2
363 Mentored-by: C3 E3
364 Mentored-by: C4 E4
366 git -c trailer.where="before" \
367 commit --trailer "Mentored-by: C3 E3" \
368 --trailer "Mentored-by: C2 E2" \
369 --amend &&
370 git cat-file commit HEAD >commit.msg &&
371 sed -e "1,/^\$/d" commit.msg >actual &&
372 test_cmp expected actual
375 test_expect_success 'commit --trailer with -c and "donothing" as ifmissing' '
376 trailer_commit_base &&
377 cat >expected <<-\EOF &&
378 hello
380 Signed-off-by: C O Mitter <committer@example.com>
381 Signed-off-by: C1 E1
382 Helped-by: C2 E2
383 Reported-by: C3 E3
384 Mentored-by: C4 E4
385 Helped-by: C5 E5
387 git -c trailer.ifmissing="donothing" \
388 commit --trailer "Helped-by: C5 E5" \
389 --trailer "Based-by: C6 E6" \
390 --amend &&
391 git cat-file commit HEAD >commit.msg &&
392 sed -e "1,/^\$/d" commit.msg >actual &&
393 test_cmp expected actual
396 test_expect_success 'commit --trailer with -c and "add" as ifmissing' '
397 trailer_commit_base &&
398 cat >expected <<-\EOF &&
399 hello
401 Signed-off-by: C O Mitter <committer@example.com>
402 Signed-off-by: C1 E1
403 Helped-by: C2 E2
404 Reported-by: C3 E3
405 Mentored-by: C4 E4
406 Helped-by: C5 E5
407 Based-by: C6 E6
409 git -c trailer.ifmissing="add" \
410 commit --trailer "Helped-by: C5 E5" \
411 --trailer "Based-by: C6 E6" \
412 --amend &&
413 git cat-file commit HEAD >commit.msg &&
414 sed -e "1,/^\$/d" commit.msg >actual &&
415 test_cmp expected actual
418 test_expect_success 'commit --trailer with -c ack.key ' '
419 echo "fun" >>file1 &&
420 git add file1 &&
421 cat >expected <<-\EOF &&
422 hello
424 Acked-by: Peff
426 git -c trailer.ack.key="Acked-by" \
427 commit --trailer "ack = Peff" -m "hello" &&
428 git cat-file commit HEAD >commit.msg &&
429 sed -e "1,/^\$/d" commit.msg >actual &&
430 test_cmp expected actual
433 test_expect_success 'commit --trailer with -c and ":=#" as separators' '
434 echo "fun" >>file1 &&
435 git add file1 &&
436 cat >expected <<-\EOF &&
437 I hate bug
439 Bug #42
441 git -c trailer.separators=":=#" \
442 -c trailer.bug.key="Bug #" \
443 commit --trailer "bug = 42" -m "I hate bug" &&
444 git cat-file commit HEAD >commit.msg &&
445 sed -e "1,/^\$/d" commit.msg >actual &&
446 test_cmp expected actual
449 test_expect_success 'commit --trailer with -c and command' '
450 trailer_commit_base &&
451 cat >expected <<-\EOF &&
452 hello
454 Signed-off-by: C O Mitter <committer@example.com>
455 Signed-off-by: C1 E1
456 Helped-by: C2 E2
457 Mentored-by: C4 E4
458 Reported-by: A U Thor <author@example.com>
460 git -c trailer.report.key="Reported-by: " \
461 -c trailer.report.ifexists="replace" \
462 -c trailer.report.command="NAME=\"\$ARG\"; test -n \"\$NAME\" && \
463 git log --author=\"\$NAME\" -1 --format=\"format:%aN <%aE>\" || true" \
464 commit --trailer "report = author" --amend &&
465 git cat-file commit HEAD >commit.msg &&
466 sed -e "1,/^\$/d" commit.msg >actual &&
467 test_cmp expected actual
470 test_expect_success 'commit --trailer not confused by --- separator' '
471 cat >msg <<-\EOF &&
472 subject
474 body with dashes
476 in it
478 git commit --allow-empty --trailer="my-trailer: value" -F msg &&
480 cat msg &&
481 echo &&
482 echo "my-trailer: value"
483 } >expected &&
484 git cat-file commit HEAD >commit.msg &&
485 sed -e "1,/^\$/d" commit.msg >actual &&
486 test_cmp expected actual
489 test_expect_success 'commit --trailer with --verbose' '
490 cat >msg <<-\EOF &&
491 subject
493 body
495 GIT_EDITOR=: git commit --edit -F msg --allow-empty \
496 --trailer="my-trailer: value" --verbose &&
498 cat msg &&
499 echo &&
500 echo "my-trailer: value"
501 } >expected &&
502 git cat-file commit HEAD >commit.msg &&
503 sed -e "1,/^\$/d" commit.msg >actual &&
504 test_cmp expected actual
507 test_expect_success 'multiple -m' '
509 >negative &&
510 git add negative &&
511 git commit -m "one" -m "two" -m "three" &&
512 actual=$(git cat-file commit HEAD >tmp && sed -e "1,/^\$/d" tmp && rm tmp) &&
513 expected=$(test_write_lines "one" "" "two" "" "three") &&
514 test "z$actual" = "z$expected"
518 test_expect_success 'verbose' '
520 echo minus >negative &&
521 git add negative &&
522 git status -v >raw &&
523 sed -ne "/^diff --git /p" raw >actual &&
524 echo "diff --git a/negative b/negative" >expect &&
525 test_cmp expect actual
529 test_expect_success 'verbose respects diff config' '
531 test_config diff.noprefix true &&
532 git status -v >actual &&
533 grep "diff --git negative negative" actual
536 mesg_with_comment_and_newlines='
537 # text
541 test_expect_success 'prepare file with comment line and trailing newlines' '
542 printf "%s" "$mesg_with_comment_and_newlines" >expect
545 test_expect_success 'cleanup commit messages (verbatim option,-t)' '
547 echo >>negative &&
548 git commit --cleanup=verbatim --no-status -t expect -a &&
549 git cat-file -p HEAD >raw &&
550 sed -e "1,/^\$/d" raw >actual &&
551 test_cmp expect actual
555 test_expect_success 'cleanup commit messages (verbatim option,-F)' '
557 echo >>negative &&
558 git commit --cleanup=verbatim -F expect -a &&
559 git cat-file -p HEAD >raw &&
560 sed -e "1,/^\$/d" raw >actual &&
561 test_cmp expect actual
565 test_expect_success 'cleanup commit messages (verbatim option,-m)' '
567 echo >>negative &&
568 git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a &&
569 git cat-file -p HEAD >raw &&
570 sed -e "1,/^\$/d" raw >actual &&
571 test_cmp expect actual
575 test_expect_success 'cleanup commit messages (whitespace option,-F)' '
577 echo >>negative &&
578 test_write_lines "" "# text" "" >text &&
579 echo "# text" >expect &&
580 git commit --cleanup=whitespace -F text -a &&
581 git cat-file -p HEAD >raw &&
582 sed -e "1,/^\$/d" raw >actual &&
583 test_cmp expect actual
587 test_expect_success 'cleanup commit messages (scissors option,-F,-e)' '
589 echo >>negative &&
590 cat >text <<-\EOF &&
592 # to be kept
594 # ------------------------ >8 ------------------------
595 # to be kept, too
596 # ------------------------ >8 ------------------------
597 to be removed
598 # ------------------------ >8 ------------------------
599 to be removed, too
602 cat >expect <<-\EOF &&
603 # to be kept
605 # ------------------------ >8 ------------------------
606 # to be kept, too
608 git commit --cleanup=scissors -e -F text -a &&
609 git cat-file -p HEAD >raw &&
610 sed -e "1,/^\$/d" raw >actual &&
611 test_cmp expect actual
614 test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line)' '
616 echo >>negative &&
617 cat >text <<-\EOF &&
618 # ------------------------ >8 ------------------------
619 to be removed
621 git commit --cleanup=scissors -e -F text -a --allow-empty-message &&
622 git cat-file -p HEAD >raw &&
623 sed -e "1,/^\$/d" raw >actual &&
624 test_must_be_empty actual
627 test_expect_success 'cleanup commit messages (strip option,-F)' '
629 echo >>negative &&
630 test_write_lines "" "# text" "sample" "" >text &&
631 echo sample >expect &&
632 git commit --cleanup=strip -F text -a &&
633 git cat-file -p HEAD >raw &&
634 sed -e "1,/^\$/d" raw >actual &&
635 test_cmp expect actual
639 test_expect_success 'cleanup commit messages (strip option,-F,-e)' '
641 echo >>negative &&
642 test_write_lines "" "sample" "" >text &&
643 git commit -e -F text -a &&
644 head -n 4 .git/COMMIT_EDITMSG >actual
647 echo "sample
649 # Please enter the commit message for your changes. Lines starting
650 # with '#' will be ignored, and an empty message aborts the commit." >expect
652 test_expect_success 'cleanup commit messages (strip option,-F,-e): output' '
653 test_cmp expect actual
656 test_expect_success 'cleanup commit message (fail on invalid cleanup mode option)' '
657 test_must_fail git commit --cleanup=non-existent
660 test_expect_success 'cleanup commit message (fail on invalid cleanup mode configuration)' '
661 test_must_fail git -c commit.cleanup=non-existent commit
664 test_expect_success 'cleanup commit message (no config and no option uses default)' '
665 echo content >>file &&
666 git add file &&
668 test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
669 git commit --no-status
670 ) &&
671 commit_msg_is "commit message"
674 test_expect_success 'cleanup commit message (option overrides default)' '
675 echo content >>file &&
676 git add file &&
678 test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
679 git commit --cleanup=whitespace --no-status
680 ) &&
681 commit_msg_is "commit message # comment"
684 test_expect_success 'cleanup commit message (config overrides default)' '
685 echo content >>file &&
686 git add file &&
688 test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
689 git -c commit.cleanup=whitespace commit --no-status
690 ) &&
691 commit_msg_is "commit message # comment"
694 test_expect_success 'cleanup commit message (option overrides config)' '
695 echo content >>file &&
696 git add file &&
698 test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
699 git -c commit.cleanup=whitespace commit --cleanup=default
700 ) &&
701 commit_msg_is "commit message"
704 test_expect_success 'cleanup commit message (default, -m)' '
705 echo content >>file &&
706 git add file &&
707 git commit -m "message #comment " &&
708 commit_msg_is "message #comment"
711 test_expect_success 'cleanup commit message (whitespace option, -m)' '
712 echo content >>file &&
713 git add file &&
714 git commit --cleanup=whitespace --no-status -m "message #comment " &&
715 commit_msg_is "message #comment"
718 test_expect_success 'cleanup commit message (whitespace config, -m)' '
719 echo content >>file &&
720 git add file &&
721 git -c commit.cleanup=whitespace commit --no-status -m "message #comment " &&
722 commit_msg_is "message #comment"
725 test_expect_success 'message shows author when it is not equal to committer' '
726 echo >>negative &&
727 git commit -e -m "sample" -a &&
728 test_grep \
729 "^# Author: *A U Thor <author@example.com>\$" \
730 .git/COMMIT_EDITMSG
733 test_expect_success 'message shows date when it is explicitly set' '
734 git commit --allow-empty -e -m foo --date="2010-01-02T03:04:05" &&
735 test_grep \
736 "^# Date: *Sat Jan 2 03:04:05 2010 +0000" \
737 .git/COMMIT_EDITMSG
740 test_expect_success 'message does not have multiple scissors lines' '
741 git commit --cleanup=scissors -v --allow-empty -e -m foo &&
742 test $(grep -c -e "--- >8 ---" .git/COMMIT_EDITMSG) -eq 1
745 test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
747 echo >>negative &&
749 sane_unset GIT_COMMITTER_EMAIL &&
750 sane_unset GIT_COMMITTER_NAME &&
751 git commit -e -m "sample" -a
752 ) &&
753 # the ident is calculated from the system, so we cannot
754 # check the actual value, only that it is there
755 test_grep "^# Committer: " .git/COMMIT_EDITMSG
758 write_script .git/FAKE_EDITOR <<EOF
759 echo editor started >"$(pwd)/.git/result"
760 exit 0
763 test_expect_success !FAIL_PREREQS,!AUTOIDENT 'do not fire editor when committer is bogus' '
764 >.git/result &&
766 echo >>negative &&
768 sane_unset GIT_COMMITTER_EMAIL &&
769 sane_unset GIT_COMMITTER_NAME &&
770 GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" &&
771 export GIT_EDITOR &&
772 test_must_fail git commit -e -m sample -a
773 ) &&
774 test_must_be_empty .git/result
777 test_expect_success 'do not fire editor if -m <msg> was given' '
778 echo tick >file &&
779 git add file &&
780 echo "editor not started" >.git/result &&
781 (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" git commit -m tick) &&
782 test "$(cat .git/result)" = "editor not started"
785 test_expect_success 'do not fire editor if -m "" was given' '
786 echo tock >file &&
787 git add file &&
788 echo "editor not started" >.git/result &&
789 (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" \
790 git commit -m "" --allow-empty-message) &&
791 test "$(cat .git/result)" = "editor not started"
794 test_expect_success 'do not fire editor in the presence of conflicts' '
796 git clean -f &&
797 echo f >g &&
798 git add g &&
799 git commit -m "add g" &&
800 git branch second &&
801 echo main >g &&
802 echo g >h &&
803 git add g h &&
804 git commit -m "modify g and add h" &&
805 git checkout second &&
806 echo second >g &&
807 git add g &&
808 git commit -m second &&
809 # Must fail due to conflict
810 test_must_fail git cherry-pick -n main &&
811 echo "editor not started" >.git/result &&
813 GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" &&
814 export GIT_EDITOR &&
815 test_must_fail git commit
816 ) &&
817 test "$(cat .git/result)" = "editor not started"
820 write_script .git/FAKE_EDITOR <<EOF
821 # kill -TERM command added below.
824 test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' '
825 echo >>negative &&
826 ! "$SHELL_PATH" -c '\''
827 echo kill -TERM $$ >>.git/FAKE_EDITOR
828 GIT_EDITOR=.git/FAKE_EDITOR
829 export GIT_EDITOR
830 exec git commit -a'\'' &&
831 test ! -f .git/index.lock
834 rm -f .git/MERGE_MSG .git/COMMIT_EDITMSG
835 git reset -q --hard
837 test_expect_success 'Hand committing of a redundant merge removes dups' '
839 git rev-parse second main >expect &&
840 test_must_fail git merge second main &&
841 git checkout main g &&
842 EDITOR=: git commit -a &&
843 git cat-file commit HEAD >raw &&
844 sed -n -e "s/^parent //p" -e "/^$/q" raw >actual &&
845 test_cmp expect actual
849 test_expect_success 'A single-liner subject with a token plus colon is not a footer' '
851 git reset --hard &&
852 git commit -s -m "hello: kitty" --allow-empty &&
853 git cat-file commit HEAD >raw &&
854 sed -e "1,/^$/d" raw >actual &&
855 test_line_count = 3 actual
859 test_expect_success 'commit -s places sob on third line after two empty lines' '
860 git commit -s --allow-empty --allow-empty-message &&
861 cat <<-EOF >expect &&
864 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
867 sed -e "/^#/d" -e "s/^:.*//" .git/COMMIT_EDITMSG >actual &&
868 test_cmp expect actual
871 write_script .git/FAKE_EDITOR <<\EOF
872 mv "$1" "$1.orig"
874 echo message
875 cat "$1.orig"
876 ) >"$1"
879 echo '## Custom template' >template
881 try_commit () {
882 git reset --hard &&
883 echo >>negative &&
884 GIT_EDITOR=.git/FAKE_EDITOR git commit -a $* $use_template &&
885 case "$use_template" in
887 test_grep ! "^## Custom template" .git/COMMIT_EDITMSG ;;
889 test_grep "^## Custom template" .git/COMMIT_EDITMSG ;;
890 esac
893 try_commit_status_combo () {
895 test_expect_success 'commit' '
896 try_commit "" &&
897 test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
900 test_expect_success 'commit --status' '
901 try_commit --status &&
902 test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
905 test_expect_success 'commit --no-status' '
906 try_commit --no-status &&
907 test_grep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
910 test_expect_success 'commit with commit.status = yes' '
911 test_config commit.status yes &&
912 try_commit "" &&
913 test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
916 test_expect_success 'commit with commit.status = no' '
917 test_config commit.status no &&
918 try_commit "" &&
919 test_grep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
922 test_expect_success 'commit --status with commit.status = yes' '
923 test_config commit.status yes &&
924 try_commit --status &&
925 test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
928 test_expect_success 'commit --no-status with commit.status = yes' '
929 test_config commit.status yes &&
930 try_commit --no-status &&
931 test_grep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
934 test_expect_success 'commit --status with commit.status = no' '
935 test_config commit.status no &&
936 try_commit --status &&
937 test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
940 test_expect_success 'commit --no-status with commit.status = no' '
941 test_config commit.status no &&
942 try_commit --no-status &&
943 test_grep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
948 try_commit_status_combo
950 use_template="-t template"
952 try_commit_status_combo
954 test_expect_success 'commit --status with custom comment character' '
955 test_config core.commentchar ";" &&
956 try_commit --status &&
957 test_grep "^; Changes to be committed:" .git/COMMIT_EDITMSG
960 test_expect_success 'switch core.commentchar' '
961 test_commit "#foo" foo &&
962 GIT_EDITOR=.git/FAKE_EDITOR git -c core.commentChar=auto commit --amend &&
963 test_grep "^; Changes to be committed:" .git/COMMIT_EDITMSG
966 test_expect_success 'switch core.commentchar but out of options' '
967 cat >text <<\EOF &&
977 : 10
979 git commit --amend -F text &&
981 test_set_editor .git/FAKE_EDITOR &&
982 test_must_fail git -c core.commentChar=auto commit --amend
986 test_done