blob: d33a3cb331b6c022343aff0bb7091cf8219b40df [file] [log] [blame]
Junio C Hamanob468f0c2007-11-22 16:21:49 -08001#!/bin/sh
2
3test_description='git commit porcelain-ish'
4
5. ./test-lib.sh
6
Ralf Thielow51fb3a32013-01-10 18:45:59 +01007commit_msg_is () {
8 expect=commit_msg_is.expect
9 actual=commit_msg_is.actual
10
11 printf "%s" "$(git log --pretty=format:%s%b -1)" >$actual &&
12 printf "%s" "$1" >$expect &&
13 test_i18ncmp $expect $actual
14}
15
Tay Ray Chuancee9f2b2010-05-27 23:34:51 +080016# Arguments: [<prefix] [<commit message>] [<commit options>]
Tay Ray Chuanfc6fa0d2010-05-27 23:34:50 +080017check_summary_oneline() {
18 test_tick &&
Tay Ray Chuancee9f2b2010-05-27 23:34:51 +080019 git commit ${3+"$3"} -m "$2" | head -1 > act &&
Tay Ray Chuanfc6fa0d2010-05-27 23:34:50 +080020
21 # branch name
22 SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" &&
23
24 # append the "special" prefix, like "root-commit", "detached HEAD"
25 if test -n "$1"
26 then
27 SUMMARY_PREFIX="$SUMMARY_PREFIX ($1)"
28 fi
29
30 # abbrev SHA-1
31 SUMMARY_POSTFIX="$(git log -1 --pretty='format:%h')"
32 echo "[$SUMMARY_PREFIX $SUMMARY_POSTFIX] $2" >exp &&
33
Junio C Hamanof79ce8d2011-04-13 16:17:50 -070034 test_i18ncmp exp act
Tay Ray Chuanfc6fa0d2010-05-27 23:34:50 +080035}
36
37test_expect_success 'output summary format' '
38
39 echo new >file1 &&
40 git add file1 &&
41 check_summary_oneline "root-commit" "initial" &&
42
43 echo change >>file1 &&
Ævar Arnfjörð Bjarmason7f5673d2011-02-22 23:41:47 +000044 git add file1
45'
46
47test_expect_success 'output summary format: root-commit' '
Tay Ray Chuanfc6fa0d2010-05-27 23:34:50 +080048 check_summary_oneline "" "a change"
49'
50
Tay Ray Chuana45e1a82010-06-12 22:15:39 +080051test_expect_success 'output summary format for commit with an empty diff' '
Tay Ray Chuancee9f2b2010-05-27 23:34:51 +080052
53 check_summary_oneline "" "empty" "--allow-empty"
54'
55
Tay Ray Chuana45e1a82010-06-12 22:15:39 +080056test_expect_success 'output summary format for merges' '
Tay Ray Chuancee9f2b2010-05-27 23:34:51 +080057
58 git checkout -b recursive-base &&
59 test_commit base file1 &&
60
61 git checkout -b recursive-a recursive-base &&
62 test_commit commit-a file1 &&
63
64 git checkout -b recursive-b recursive-base &&
65 test_commit commit-b file1 &&
66
67 # conflict
68 git checkout recursive-a &&
69 test_must_fail git merge recursive-b &&
70 # resolve the conflict
71 echo commit-a > file1 &&
72 git add file1 &&
73 check_summary_oneline "" "Merge"
74'
75
Tay Ray Chuanfc6fa0d2010-05-27 23:34:50 +080076output_tests_cleanup() {
77 # this is needed for "do not fire editor in the presence of conflicts"
78 git checkout master &&
79
80 # this is needed for the "partial removal" test to pass
81 git rm file1 &&
82 git commit -m "cleanup"
83}
84
Junio C Hamanob468f0c2007-11-22 16:21:49 -080085test_expect_success 'the basics' '
86
Tay Ray Chuanfc6fa0d2010-05-27 23:34:50 +080087 output_tests_cleanup &&
88
Junio C Hamanob468f0c2007-11-22 16:21:49 -080089 echo doing partial >"commit is" &&
90 mkdir not &&
91 echo very much encouraged but we should >not/forbid &&
92 git add "commit is" not &&
93 echo update added "commit is" file >"commit is" &&
94 echo also update another >not/forbid &&
95 test_tick &&
96 git commit -a -m "initial with -a" &&
97
98 git cat-file blob HEAD:"commit is" >current.1 &&
99 git cat-file blob HEAD:not/forbid >current.2 &&
100
101 cmp current.1 "commit is" &&
102 cmp current.2 not/forbid
103
104'
105
106test_expect_success 'partial' '
107
108 echo another >"commit is" &&
109 echo another >not/forbid &&
110 test_tick &&
111 git commit -m "partial commit to handle a file" "commit is" &&
112
113 changed=$(git diff-tree --name-only HEAD^ HEAD) &&
114 test "$changed" = "commit is"
115
116'
117
Tay Ray Chuane8f30162010-05-24 16:51:17 +0800118test_expect_success 'partial modification in a subdirectory' '
Junio C Hamanob468f0c2007-11-22 16:21:49 -0800119
120 test_tick &&
121 git commit -m "partial commit to subdirectory" not &&
122
123 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
124 test "$changed" = "not/forbid"
125
126'
127
128test_expect_success 'partial removal' '
129
130 git rm not/forbid &&
131 git commit -m "partial commit to remove not/forbid" not &&
132
133 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
134 test "$changed" = "not/forbid" &&
135 remain=$(git ls-tree -r --name-only HEAD) &&
136 test "$remain" = "commit is"
137
138'
139
140test_expect_success 'sign off' '
141
142 >positive &&
143 git add positive &&
144 git commit -s -m "thank you" &&
145 actual=$(git cat-file commit HEAD | sed -ne "s/Signed-off-by: //p") &&
146 expected=$(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/") &&
147 test "z$actual" = "z$expected"
148
149'
150
151test_expect_success 'multiple -m' '
152
153 >negative &&
154 git add negative &&
155 git commit -m "one" -m "two" -m "three" &&
156 actual=$(git cat-file commit HEAD | sed -e "1,/^\$/d") &&
157 expected=$(echo one; echo; echo two; echo; echo three) &&
158 test "z$actual" = "z$expected"
159
160'
161
162test_expect_success 'verbose' '
163
164 echo minus >negative &&
165 git add negative &&
166 git status -v | sed -ne "/^diff --git /p" >actual &&
167 echo "diff --git a/negative b/negative" >expect &&
Jeff King82ebb0b2008-03-12 17:36:36 -0400168 test_cmp expect actual
Junio C Hamanob468f0c2007-11-22 16:21:49 -0800169
170'
171
Jeff King4f672ad2008-10-26 00:49:35 -0400172test_expect_success 'verbose respects diff config' '
173
Jeff King0fcf7602017-10-03 09:43:47 -0400174 test_config diff.noprefix true &&
Jeff King4f672ad2008-10-26 00:49:35 -0400175 git status -v >actual &&
Jeff King0fcf7602017-10-03 09:43:47 -0400176 grep "diff --git negative negative" actual
Jeff King4f672ad2008-10-26 00:49:35 -0400177'
178
Brandon Casey5b012c82013-02-18 20:17:05 -0800179mesg_with_comment_and_newlines='
180# text
181
182'
183
184test_expect_success 'prepare file with comment line and trailing newlines' '
185 printf "%s" "$mesg_with_comment_and_newlines" >expect
186'
187
Ralf Thielow51fb3a32013-01-10 18:45:59 +0100188test_expect_success 'cleanup commit messages (verbatim option,-t)' '
Alex Riesen5f065732007-12-22 19:46:24 +0100189
190 echo >>negative &&
Brandon Casey67dabab2013-02-18 20:17:04 -0800191 git commit --cleanup=verbatim --no-status -t expect -a &&
192 git cat-file -p HEAD |sed -e "1,/^\$/d" >actual &&
Jeff King82ebb0b2008-03-12 17:36:36 -0400193 test_cmp expect actual
Alex Riesen5f065732007-12-22 19:46:24 +0100194
195'
196
Ralf Thielow51fb3a32013-01-10 18:45:59 +0100197test_expect_success 'cleanup commit messages (verbatim option,-F)' '
Alex Riesen5f065732007-12-22 19:46:24 +0100198
199 echo >>negative &&
200 git commit --cleanup=verbatim -F expect -a &&
201 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
Jeff King82ebb0b2008-03-12 17:36:36 -0400202 test_cmp expect actual
Alex Riesen5f065732007-12-22 19:46:24 +0100203
204'
205
Brandon Caseya24a41e2013-02-18 20:17:06 -0800206test_expect_success 'cleanup commit messages (verbatim option,-m)' '
Alex Riesen5f065732007-12-22 19:46:24 +0100207
208 echo >>negative &&
Brandon Casey5b012c82013-02-18 20:17:05 -0800209 git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a &&
Alex Riesen5f065732007-12-22 19:46:24 +0100210 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
Jeff King82ebb0b2008-03-12 17:36:36 -0400211 test_cmp expect actual
Alex Riesen5f065732007-12-22 19:46:24 +0100212
213'
214
Ralf Thielow51fb3a32013-01-10 18:45:59 +0100215test_expect_success 'cleanup commit messages (whitespace option,-F)' '
Alex Riesen5f065732007-12-22 19:46:24 +0100216
217 echo >>negative &&
218 { echo;echo "# text";echo; } >text &&
219 echo "# text" >expect &&
220 git commit --cleanup=whitespace -F text -a &&
221 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
Jeff King82ebb0b2008-03-12 17:36:36 -0400222 test_cmp expect actual
Alex Riesen5f065732007-12-22 19:46:24 +0100223
224'
225
Nguyễn Thái Ngọc Duy75df1f42014-02-17 19:15:32 +0700226test_expect_success 'cleanup commit messages (scissors option,-F,-e)' '
227
228 echo >>negative &&
229 cat >text <<EOF &&
230
231# to be kept
SZEDER Gáborfbfa0972015-06-09 02:28:34 +0200232
233 # ------------------------ >8 ------------------------
234# to be kept, too
Nguyễn Thái Ngọc Duy75df1f42014-02-17 19:15:32 +0700235# ------------------------ >8 ------------------------
236to be removed
SZEDER Gáborfbfa0972015-06-09 02:28:34 +0200237# ------------------------ >8 ------------------------
238to be removed, too
Nguyễn Thái Ngọc Duy75df1f42014-02-17 19:15:32 +0700239EOF
SZEDER Gáborfbfa0972015-06-09 02:28:34 +0200240
241 cat >expect <<EOF &&
242# to be kept
243
244 # ------------------------ >8 ------------------------
245# to be kept, too
246EOF
Nguyễn Thái Ngọc Duy75df1f42014-02-17 19:15:32 +0700247 git commit --cleanup=scissors -e -F text -a &&
248 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
249 test_cmp expect actual
SZEDER Gáborfbfa0972015-06-09 02:28:34 +0200250'
Nguyễn Thái Ngọc Duy75df1f42014-02-17 19:15:32 +0700251
SZEDER Gáborfbfa0972015-06-09 02:28:34 +0200252test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line)' '
253
254 echo >>negative &&
255 cat >text <<EOF &&
256# ------------------------ >8 ------------------------
257to be removed
258EOF
259 git commit --cleanup=scissors -e -F text -a --allow-empty-message &&
260 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
261 test_must_be_empty actual
Nguyễn Thái Ngọc Duy75df1f42014-02-17 19:15:32 +0700262'
263
Ralf Thielow51fb3a32013-01-10 18:45:59 +0100264test_expect_success 'cleanup commit messages (strip option,-F)' '
Alex Riesen5f065732007-12-22 19:46:24 +0100265
266 echo >>negative &&
267 { echo;echo "# text";echo sample;echo; } >text &&
268 echo sample >expect &&
269 git commit --cleanup=strip -F text -a &&
270 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
Jeff King82ebb0b2008-03-12 17:36:36 -0400271 test_cmp expect actual
Alex Riesen5f065732007-12-22 19:46:24 +0100272
273'
274
Ralf Thielow51fb3a32013-01-10 18:45:59 +0100275test_expect_success 'cleanup commit messages (strip option,-F,-e)' '
Alex Riesen5f065732007-12-22 19:46:24 +0100276
277 echo >>negative &&
278 { echo;echo sample;echo; } >text &&
279 git commit -e -F text -a &&
Ævar Arnfjörð Bjarmason0b430a12011-02-22 23:41:48 +0000280 head -n 4 .git/COMMIT_EDITMSG >actual
281'
Alex Riesen5f065732007-12-22 19:46:24 +0100282
Ævar Arnfjörð Bjarmason0b430a12011-02-22 23:41:48 +0000283echo "sample
284
285# Please enter the commit message for your changes. Lines starting
286# with '#' will be ignored, and an empty message aborts the commit." >expect
287
Ralf Thielow51fb3a32013-01-10 18:45:59 +0100288test_expect_success 'cleanup commit messages (strip option,-F,-e): output' '
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700289 test_i18ncmp expect actual
Alex Riesen5f065732007-12-22 19:46:24 +0100290'
291
Ralf Thielow51fb3a32013-01-10 18:45:59 +0100292test_expect_success 'cleanup commit message (fail on invalid cleanup mode option)' '
293 test_must_fail git commit --cleanup=non-existent
294'
295
296test_expect_success 'cleanup commit message (fail on invalid cleanup mode configuration)' '
297 test_must_fail git -c commit.cleanup=non-existent commit
298'
299
300test_expect_success 'cleanup commit message (no config and no option uses default)' '
301 echo content >>file &&
302 git add file &&
Brandon Casey24e099f2013-02-22 15:13:00 -0800303 (
304 test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
305 git commit --no-status
306 ) &&
Ralf Thielow51fb3a32013-01-10 18:45:59 +0100307 commit_msg_is "commit message"
308'
309
310test_expect_success 'cleanup commit message (option overrides default)' '
311 echo content >>file &&
312 git add file &&
Brandon Casey24e099f2013-02-22 15:13:00 -0800313 (
314 test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
315 git commit --cleanup=whitespace --no-status
316 ) &&
Ralf Thielow51fb3a32013-01-10 18:45:59 +0100317 commit_msg_is "commit message # comment"
318'
319
320test_expect_success 'cleanup commit message (config overrides default)' '
321 echo content >>file &&
322 git add file &&
Brandon Casey24e099f2013-02-22 15:13:00 -0800323 (
324 test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
325 git -c commit.cleanup=whitespace commit --no-status
326 ) &&
Ralf Thielow51fb3a32013-01-10 18:45:59 +0100327 commit_msg_is "commit message # comment"
328'
329
330test_expect_success 'cleanup commit message (option overrides config)' '
331 echo content >>file &&
332 git add file &&
Brandon Casey24e099f2013-02-22 15:13:00 -0800333 (
334 test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
335 git -c commit.cleanup=whitespace commit --cleanup=default
336 ) &&
Ralf Thielow51fb3a32013-01-10 18:45:59 +0100337 commit_msg_is "commit message"
338'
339
340test_expect_success 'cleanup commit message (default, -m)' '
341 echo content >>file &&
342 git add file &&
343 git commit -m "message #comment " &&
344 commit_msg_is "message #comment"
345'
346
347test_expect_success 'cleanup commit message (whitespace option, -m)' '
348 echo content >>file &&
349 git add file &&
350 git commit --cleanup=whitespace --no-status -m "message #comment " &&
351 commit_msg_is "message #comment"
352'
353
354test_expect_success 'cleanup commit message (whitespace config, -m)' '
355 echo content >>file &&
356 git add file &&
357 git -c commit.cleanup=whitespace commit --no-status -m "message #comment " &&
358 commit_msg_is "message #comment"
359'
360
Jeff King1f4bf342012-07-26 16:30:29 -0400361test_expect_success 'message shows author when it is not equal to committer' '
Santi Béjare83dbe82008-05-04 18:04:50 +0200362 echo >>negative &&
Jeff Kingceacd912012-07-26 16:31:15 -0400363 git commit -e -m "sample" -a &&
Jeff King1f4bf342012-07-26 16:30:29 -0400364 test_i18ngrep \
365 "^# Author: *A U Thor <author@example.com>\$" \
366 .git/COMMIT_EDITMSG
Santi Béjare83dbe82008-05-04 18:04:50 +0200367'
368
Jeff Kingb7242b82014-05-01 21:10:01 -0400369test_expect_success 'message shows date when it is explicitly set' '
370 git commit --allow-empty -e -m foo --date="2010-01-02T03:04:05" &&
371 test_i18ngrep \
372 "^# Date: *Sat Jan 2 03:04:05 2010 +0000" \
373 .git/COMMIT_EDITMSG
374'
375
Jeff King1d7dc262012-07-26 16:32:31 -0400376test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
Santi Béjarbb1ae3f2008-05-04 18:04:51 +0200377
378 echo >>negative &&
Junio C Hamano78459442008-06-03 18:08:08 -0700379 (
Elijah Newren00648ba2010-10-03 14:00:14 -0600380 sane_unset GIT_COMMITTER_EMAIL &&
381 sane_unset GIT_COMMITTER_NAME &&
Jeff King1d7dc262012-07-26 16:32:31 -0400382 git commit -e -m "sample" -a
Junio C Hamano78459442008-06-03 18:08:08 -0700383 ) &&
Jeff King1f4bf342012-07-26 16:30:29 -0400384 # the ident is calculated from the system, so we cannot
385 # check the actual value, only that it is there
386 test_i18ngrep "^# Committer: " .git/COMMIT_EDITMSG
Santi Béjarbb1ae3f2008-05-04 18:04:51 +0200387'
388
Jeff Kinga9ebc432012-07-26 16:27:55 -0400389write_script .git/FAKE_EDITOR <<EOF
390echo editor started > "$(pwd)/.git/result"
Paolo Bonziniec84bd02008-02-05 11:01:46 +0100391exit 0
392EOF
Paolo Bonziniec84bd02008-02-05 11:01:46 +0100393
Jeff King09feffb2012-11-14 16:33:40 -0800394test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' '
Ramsay Jonesf84df812015-04-28 13:04:44 +0100395 >.git/result &&
Jeff King8c8b3bc2012-07-26 16:32:50 -0400396 >expect &&
397
398 echo >>negative &&
399 (
400 sane_unset GIT_COMMITTER_EMAIL &&
401 sane_unset GIT_COMMITTER_NAME &&
402 GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" &&
403 export GIT_EDITOR &&
404 test_must_fail git commit -e -m sample -a
405 ) &&
406 test_cmp expect .git/result
407'
408
René Scharfe25206772013-05-25 23:43:34 +0200409test_expect_success 'do not fire editor if -m <msg> was given' '
410 echo tick >file &&
411 git add file &&
412 echo "editor not started" >.git/result &&
413 (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" git commit -m tick) &&
414 test "$(cat .git/result)" = "editor not started"
415'
416
417test_expect_success 'do not fire editor if -m "" was given' '
418 echo tock >file &&
419 git add file &&
420 echo "editor not started" >.git/result &&
421 (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" \
422 git commit -m "" --allow-empty-message) &&
423 test "$(cat .git/result)" = "editor not started"
424'
425
Paolo Bonziniec84bd02008-02-05 11:01:46 +0100426test_expect_success 'do not fire editor in the presence of conflicts' '
427
Junio C Hamanoa3c91e02008-06-03 18:10:08 -0700428 git clean -f &&
429 echo f >g &&
430 git add g &&
431 git commit -m "add g" &&
432 git branch second &&
433 echo master >g &&
434 echo g >h &&
435 git add g h &&
436 git commit -m "modify g and add h" &&
437 git checkout second &&
438 echo second >g &&
439 git add g &&
440 git commit -m second &&
441 # Must fail due to conflict
442 test_must_fail git cherry-pick -n master &&
443 echo "editor not started" >.git/result &&
Brandon Caseye2007832008-06-19 12:32:02 -0500444 (
Jeff King34565f22012-07-26 16:28:00 -0400445 GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" &&
Brandon Caseye2007832008-06-19 12:32:02 -0500446 export GIT_EDITOR &&
447 test_must_fail git commit
448 ) &&
Junio C Hamanoa3c91e02008-06-03 18:10:08 -0700449 test "$(cat .git/result)" = "editor not started"
Paolo Bonziniec84bd02008-02-05 11:01:46 +0100450'
451
Jeff Kinga9ebc432012-07-26 16:27:55 -0400452write_script .git/FAKE_EDITOR <<EOF
Paolo Bonziniad5fa3c2008-05-29 16:55:53 +0200453# kill -TERM command added below.
454EOF
455
Johannes Sixtfb9a2be2009-03-25 13:21:15 +0100456test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' '
Paolo Bonziniad5fa3c2008-05-29 16:55:53 +0200457 echo >>negative &&
Brandon Casey09b78bc2008-07-22 16:21:10 -0500458 ! "$SHELL_PATH" -c '\''
Paolo Bonziniad5fa3c2008-05-29 16:55:53 +0200459 echo kill -TERM $$ >> .git/FAKE_EDITOR
Brandon Casey09b78bc2008-07-22 16:21:10 -0500460 GIT_EDITOR=.git/FAKE_EDITOR
461 export GIT_EDITOR
462 exec git commit -a'\'' &&
463 test ! -f .git/index.lock
Paolo Bonziniad5fa3c2008-05-29 16:55:53 +0200464'
465
Junio C Hamano67bfc032008-06-02 22:17:42 -0700466rm -f .git/MERGE_MSG .git/COMMIT_EDITMSG
467git reset -q --hard
468
469test_expect_success 'Hand committing of a redundant merge removes dups' '
470
471 git rev-parse second master >expect &&
472 test_must_fail git merge second master &&
473 git checkout master g &&
474 EDITOR=: git commit -a &&
475 git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q" >actual &&
476 test_cmp expect actual
477
478'
479
Junio C Hamanoe5138432009-11-06 23:06:06 -0800480test_expect_success 'A single-liner subject with a token plus colon is not a footer' '
481
482 git reset --hard &&
483 git commit -s -m "hello: kitty" --allow-empty &&
484 git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
Stefano Lattarini3fb04592012-04-11 13:24:01 +0200485 test_line_count = 3 actual
Junio C Hamanoe5138432009-11-06 23:06:06 -0800486
487'
488
Brandon Casey8c613fd2013-02-22 14:05:27 -0800489test_expect_success 'commit -s places sob on third line after two empty lines' '
490 git commit -s --allow-empty --allow-empty-message &&
491 cat <<-EOF >expect &&
492
493
494 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
495
496 EOF
497 sed -e "/^#/d" -e "s/^:.*//" .git/COMMIT_EDITMSG >actual &&
498 test_cmp expect actual
499'
500
Jeff Kinga9ebc432012-07-26 16:27:55 -0400501write_script .git/FAKE_EDITOR <<\EOF
502mv "$1" "$1.orig"
Junio C Hamanof9c01812010-01-13 00:12:54 -0800503(
504 echo message
Jeff Kinga9ebc432012-07-26 16:27:55 -0400505 cat "$1.orig"
506) >"$1"
Junio C Hamanof9c01812010-01-13 00:12:54 -0800507EOF
508
509echo '## Custom template' >template
510
Junio C Hamanof9c01812010-01-13 00:12:54 -0800511try_commit () {
512 git reset --hard &&
513 echo >>negative &&
514 GIT_EDITOR=.git/FAKE_EDITOR git commit -a $* $use_template &&
515 case "$use_template" in
516 '')
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700517 test_i18ngrep ! "^## Custom template" .git/COMMIT_EDITMSG ;;
Junio C Hamanof9c01812010-01-13 00:12:54 -0800518 *)
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700519 test_i18ngrep "^## Custom template" .git/COMMIT_EDITMSG ;;
Junio C Hamanof9c01812010-01-13 00:12:54 -0800520 esac
521}
522
523try_commit_status_combo () {
524
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700525 test_expect_success 'commit' '
Junio C Hamanof9c01812010-01-13 00:12:54 -0800526 try_commit "" &&
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700527 test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
Junio C Hamanof9c01812010-01-13 00:12:54 -0800528 '
529
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700530 test_expect_success 'commit --status' '
Junio C Hamanof9c01812010-01-13 00:12:54 -0800531 try_commit --status &&
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700532 test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
Junio C Hamanof9c01812010-01-13 00:12:54 -0800533 '
534
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700535 test_expect_success 'commit --no-status' '
Jonathan Nieder2dec68c2010-10-31 02:30:58 -0500536 try_commit --no-status &&
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700537 test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
Junio C Hamanof9c01812010-01-13 00:12:54 -0800538 '
539
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700540 test_expect_success 'commit with commit.status = yes' '
Yann Droneaude023a312013-03-24 22:06:14 +0100541 test_config commit.status yes &&
Junio C Hamanof9c01812010-01-13 00:12:54 -0800542 try_commit "" &&
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700543 test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
Junio C Hamanof9c01812010-01-13 00:12:54 -0800544 '
545
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700546 test_expect_success 'commit with commit.status = no' '
Yann Droneaude023a312013-03-24 22:06:14 +0100547 test_config commit.status no &&
Junio C Hamanof9c01812010-01-13 00:12:54 -0800548 try_commit "" &&
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700549 test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
Junio C Hamanof9c01812010-01-13 00:12:54 -0800550 '
551
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700552 test_expect_success 'commit --status with commit.status = yes' '
Yann Droneaude023a312013-03-24 22:06:14 +0100553 test_config commit.status yes &&
Junio C Hamanof9c01812010-01-13 00:12:54 -0800554 try_commit --status &&
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700555 test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
Junio C Hamanof9c01812010-01-13 00:12:54 -0800556 '
557
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700558 test_expect_success 'commit --no-status with commit.status = yes' '
Yann Droneaude023a312013-03-24 22:06:14 +0100559 test_config commit.status yes &&
Junio C Hamanof9c01812010-01-13 00:12:54 -0800560 try_commit --no-status &&
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700561 test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
Junio C Hamanof9c01812010-01-13 00:12:54 -0800562 '
563
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700564 test_expect_success 'commit --status with commit.status = no' '
Yann Droneaude023a312013-03-24 22:06:14 +0100565 test_config commit.status no &&
Junio C Hamanof9c01812010-01-13 00:12:54 -0800566 try_commit --status &&
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700567 test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
Junio C Hamanof9c01812010-01-13 00:12:54 -0800568 '
569
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700570 test_expect_success 'commit --no-status with commit.status = no' '
Yann Droneaude023a312013-03-24 22:06:14 +0100571 test_config commit.status no &&
Junio C Hamanof9c01812010-01-13 00:12:54 -0800572 try_commit --no-status &&
Junio C Hamanof79ce8d2011-04-13 16:17:50 -0700573 test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
Junio C Hamanof9c01812010-01-13 00:12:54 -0800574 '
575
576}
577
578try_commit_status_combo
579
580use_template="-t template"
581
582try_commit_status_combo
583
Junio C Hamanoeff80a92013-01-16 20:18:48 +0100584test_expect_success 'commit --status with custom comment character' '
Yann Droneaud464be632013-03-24 22:06:10 +0100585 test_config core.commentchar ";" &&
Junio C Hamanoeff80a92013-01-16 20:18:48 +0100586 try_commit --status &&
587 test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG
588'
589
Nguyễn Thái Ngọc Duy84c9dc22014-05-17 08:52:23 +0700590test_expect_success 'switch core.commentchar' '
591 test_commit "#foo" foo &&
592 GIT_EDITOR=.git/FAKE_EDITOR git -c core.commentChar=auto commit --amend &&
593 test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG
594'
595
596test_expect_success 'switch core.commentchar but out of options' '
597 cat >text <<\EOF &&
598# 1
599; 2
600@ 3
601! 4
602$ 5
603% 6
604^ 7
605& 8
606| 9
607: 10
608EOF
609 git commit --amend -F text &&
610 (
611 test_set_editor .git/FAKE_EDITOR &&
612 test_must_fail git -c core.commentChar=auto commit --amend
613 )
614'
615
Junio C Hamanob468f0c2007-11-22 16:21:49 -0800616test_done