]>
Commit | Line | Data |
---|---|---|
b468f0ce JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git commit porcelain-ish' | |
4 | ||
1e2ae142 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
b468f0ce JH |
8 | . ./test-lib.sh |
9 | ||
51fb3a3d RT |
10 | commit_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 && | |
1108cea7 | 16 | test_cmp $expect $actual |
51fb3a3d RT |
17 | } |
18 | ||
cee9f2b3 | 19 | # Arguments: [<prefix] [<commit message>] [<commit options>] |
fc6fa0d0 TRC |
20 | check_summary_oneline() { |
21 | test_tick && | |
94ca361b DL |
22 | git commit ${3+"$3"} -m "$2" >raw && |
23 | head -n 1 raw >act && | |
fc6fa0d0 TRC |
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 | ||
1108cea7 | 38 | test_cmp exp act |
fc6fa0d0 TRC |
39 | } |
40 | ||
2daae3d1 ZH |
41 | trailer_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 | ||
fc6fa0d0 TRC |
51 | test_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 && | |
7f5673d7 ÆAB |
58 | git add file1 |
59 | ' | |
60 | ||
61 | test_expect_success 'output summary format: root-commit' ' | |
fc6fa0d0 TRC |
62 | check_summary_oneline "" "a change" |
63 | ' | |
64 | ||
a45e1a87 | 65 | test_expect_success 'output summary format for commit with an empty diff' ' |
cee9f2b3 TRC |
66 | |
67 | check_summary_oneline "" "empty" "--allow-empty" | |
68 | ' | |
69 | ||
a45e1a87 | 70 | test_expect_success 'output summary format for merges' ' |
cee9f2b3 TRC |
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 | |
94ca361b | 85 | echo commit-a >file1 && |
cee9f2b3 TRC |
86 | git add file1 && |
87 | check_summary_oneline "" "Merge" | |
88 | ' | |
89 | ||
fc6fa0d0 TRC |
90 | output_tests_cleanup() { |
91 | # this is needed for "do not fire editor in the presence of conflicts" | |
1e2ae142 | 92 | git checkout main && |
fc6fa0d0 TRC |
93 | |
94 | # this is needed for the "partial removal" test to pass | |
95 | git rm file1 && | |
96 | git commit -m "cleanup" | |
97 | } | |
98 | ||
b468f0ce JH |
99 | test_expect_success 'the basics' ' |
100 | ||
fc6fa0d0 TRC |
101 | output_tests_cleanup && |
102 | ||
b468f0ce JH |
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 | ||
120 | test_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 | ||
e8f30160 | 132 | test_expect_success 'partial modification in a subdirectory' ' |
b468f0ce JH |
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 | ||
142 | test_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 | ||
154 | test_expect_success 'sign off' ' | |
155 | ||
156 | >positive && | |
157 | git add positive && | |
158 | git commit -s -m "thank you" && | |
94ca361b DL |
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 | |
b468f0ce JH |
164 | |
165 | ' | |
166 | ||
2daae3d1 ZH |
167 | test_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 | ||
183 | test_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 | ||
203 | test_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 | ||
225 | test_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 | ||
246 | test_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 | ||
267 | test_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 | ||
288 | test_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 | ||
310 | test_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 | ||
331 | test_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 | ||
352 | test_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 | ||
374 | test_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 | ||
395 | test_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 | ||
417 | test_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 | ||
432 | test_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 | ||
448 | test_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 && | |
be3d6543 JK |
465 | sed -e "1,/^\$/d" commit.msg >actual && |
466 | test_cmp expected actual | |
467 | ' | |
468 | ||
469 | test_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 && | |
2daae3d1 ZH |
484 | sed -e "1,/^\$/d" commit.msg >actual && |
485 | test_cmp expected actual | |
486 | ' | |
487 | ||
b468f0ce JH |
488 | test_expect_success 'multiple -m' ' |
489 | ||
490 | >negative && | |
491 | git add negative && | |
492 | git commit -m "one" -m "two" -m "three" && | |
94ca361b DL |
493 | actual=$(git cat-file commit HEAD >tmp && sed -e "1,/^\$/d" tmp && rm tmp) && |
494 | expected=$(test_write_lines "one" "" "two" "" "three") && | |
b468f0ce JH |
495 | test "z$actual" = "z$expected" |
496 | ||
497 | ' | |
498 | ||
499 | test_expect_success 'verbose' ' | |
500 | ||
501 | echo minus >negative && | |
502 | git add negative && | |
94ca361b DL |
503 | git status -v >raw && |
504 | sed -ne "/^diff --git /p" raw >actual && | |
b468f0ce | 505 | echo "diff --git a/negative b/negative" >expect && |
82ebb0b6 | 506 | test_cmp expect actual |
b468f0ce JH |
507 | |
508 | ' | |
509 | ||
4f672ad6 JK |
510 | test_expect_success 'verbose respects diff config' ' |
511 | ||
0fcf760e | 512 | test_config diff.noprefix true && |
4f672ad6 | 513 | git status -v >actual && |
0fcf760e | 514 | grep "diff --git negative negative" actual |
4f672ad6 JK |
515 | ' |
516 | ||
5b012c80 BC |
517 | mesg_with_comment_and_newlines=' |
518 | # text | |
519 | ||
520 | ' | |
521 | ||
522 | test_expect_success 'prepare file with comment line and trailing newlines' ' | |
523 | printf "%s" "$mesg_with_comment_and_newlines" >expect | |
524 | ' | |
525 | ||
51fb3a3d | 526 | test_expect_success 'cleanup commit messages (verbatim option,-t)' ' |
5f065737 AR |
527 | |
528 | echo >>negative && | |
67dabab0 | 529 | git commit --cleanup=verbatim --no-status -t expect -a && |
94ca361b DL |
530 | git cat-file -p HEAD >raw && |
531 | sed -e "1,/^\$/d" raw >actual && | |
82ebb0b6 | 532 | test_cmp expect actual |
5f065737 AR |
533 | |
534 | ' | |
535 | ||
51fb3a3d | 536 | test_expect_success 'cleanup commit messages (verbatim option,-F)' ' |
5f065737 AR |
537 | |
538 | echo >>negative && | |
539 | git commit --cleanup=verbatim -F expect -a && | |
94ca361b DL |
540 | git cat-file -p HEAD >raw && |
541 | sed -e "1,/^\$/d" raw >actual && | |
82ebb0b6 | 542 | test_cmp expect actual |
5f065737 AR |
543 | |
544 | ' | |
545 | ||
a24a41ea | 546 | test_expect_success 'cleanup commit messages (verbatim option,-m)' ' |
5f065737 AR |
547 | |
548 | echo >>negative && | |
5b012c80 | 549 | git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a && |
94ca361b DL |
550 | git cat-file -p HEAD >raw && |
551 | sed -e "1,/^\$/d" raw >actual && | |
82ebb0b6 | 552 | test_cmp expect actual |
5f065737 AR |
553 | |
554 | ' | |
555 | ||
51fb3a3d | 556 | test_expect_success 'cleanup commit messages (whitespace option,-F)' ' |
5f065737 AR |
557 | |
558 | echo >>negative && | |
94ca361b | 559 | test_write_lines "" "# text" "" >text && |
5f065737 AR |
560 | echo "# text" >expect && |
561 | git commit --cleanup=whitespace -F text -a && | |
94ca361b DL |
562 | git cat-file -p HEAD >raw && |
563 | sed -e "1,/^\$/d" raw >actual && | |
82ebb0b6 | 564 | test_cmp expect actual |
5f065737 AR |
565 | |
566 | ' | |
567 | ||
75df1f43 NTND |
568 | test_expect_success 'cleanup commit messages (scissors option,-F,-e)' ' |
569 | ||
570 | echo >>negative && | |
94ca361b | 571 | cat >text <<-\EOF && |
75df1f43 | 572 | |
94ca361b | 573 | # to be kept |
fbfa0973 | 574 | |
94ca361b DL |
575 | # ------------------------ >8 ------------------------ |
576 | # to be kept, too | |
577 | # ------------------------ >8 ------------------------ | |
578 | to be removed | |
579 | # ------------------------ >8 ------------------------ | |
580 | to be removed, too | |
581 | EOF | |
fbfa0973 | 582 | |
94ca361b DL |
583 | cat >expect <<-\EOF && |
584 | # to be kept | |
fbfa0973 | 585 | |
94ca361b DL |
586 | # ------------------------ >8 ------------------------ |
587 | # to be kept, too | |
588 | EOF | |
75df1f43 | 589 | git commit --cleanup=scissors -e -F text -a && |
94ca361b DL |
590 | git cat-file -p HEAD >raw && |
591 | sed -e "1,/^\$/d" raw >actual && | |
75df1f43 | 592 | test_cmp expect actual |
fbfa0973 | 593 | ' |
75df1f43 | 594 | |
fbfa0973 SG |
595 | test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line)' ' |
596 | ||
597 | echo >>negative && | |
94ca361b DL |
598 | cat >text <<-\EOF && |
599 | # ------------------------ >8 ------------------------ | |
600 | to be removed | |
601 | EOF | |
fbfa0973 | 602 | git commit --cleanup=scissors -e -F text -a --allow-empty-message && |
94ca361b DL |
603 | git cat-file -p HEAD >raw && |
604 | sed -e "1,/^\$/d" raw >actual && | |
fbfa0973 | 605 | test_must_be_empty actual |
75df1f43 NTND |
606 | ' |
607 | ||
51fb3a3d | 608 | test_expect_success 'cleanup commit messages (strip option,-F)' ' |
5f065737 AR |
609 | |
610 | echo >>negative && | |
94ca361b | 611 | test_write_lines "" "# text" "sample" "" >text && |
5f065737 AR |
612 | echo sample >expect && |
613 | git commit --cleanup=strip -F text -a && | |
94ca361b DL |
614 | git cat-file -p HEAD >raw && |
615 | sed -e "1,/^\$/d" raw >actual && | |
82ebb0b6 | 616 | test_cmp expect actual |
5f065737 AR |
617 | |
618 | ' | |
619 | ||
51fb3a3d | 620 | test_expect_success 'cleanup commit messages (strip option,-F,-e)' ' |
5f065737 AR |
621 | |
622 | echo >>negative && | |
94ca361b | 623 | test_write_lines "" "sample" "" >text && |
5f065737 | 624 | git commit -e -F text -a && |
0b430a17 ÆAB |
625 | head -n 4 .git/COMMIT_EDITMSG >actual |
626 | ' | |
627 | ||
628 | echo "sample | |
5f065737 | 629 | |
0b430a17 ÆAB |
630 | # Please enter the commit message for your changes. Lines starting |
631 | # with '#' will be ignored, and an empty message aborts the commit." >expect | |
632 | ||
51fb3a3d | 633 | test_expect_success 'cleanup commit messages (strip option,-F,-e): output' ' |
1108cea7 | 634 | test_cmp expect actual |
5f065737 AR |
635 | ' |
636 | ||
51fb3a3d RT |
637 | test_expect_success 'cleanup commit message (fail on invalid cleanup mode option)' ' |
638 | test_must_fail git commit --cleanup=non-existent | |
639 | ' | |
640 | ||
641 | test_expect_success 'cleanup commit message (fail on invalid cleanup mode configuration)' ' | |
642 | test_must_fail git -c commit.cleanup=non-existent commit | |
643 | ' | |
644 | ||
645 | test_expect_success 'cleanup commit message (no config and no option uses default)' ' | |
646 | echo content >>file && | |
647 | git add file && | |
24e099f4 BC |
648 | ( |
649 | test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment && | |
650 | git commit --no-status | |
651 | ) && | |
51fb3a3d RT |
652 | commit_msg_is "commit message" |
653 | ' | |
654 | ||
655 | test_expect_success 'cleanup commit message (option overrides default)' ' | |
656 | echo content >>file && | |
657 | git add file && | |
24e099f4 BC |
658 | ( |
659 | test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment && | |
660 | git commit --cleanup=whitespace --no-status | |
661 | ) && | |
51fb3a3d RT |
662 | commit_msg_is "commit message # comment" |
663 | ' | |
664 | ||
665 | test_expect_success 'cleanup commit message (config overrides default)' ' | |
666 | echo content >>file && | |
667 | git add file && | |
24e099f4 BC |
668 | ( |
669 | test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment && | |
670 | git -c commit.cleanup=whitespace commit --no-status | |
671 | ) && | |
51fb3a3d RT |
672 | commit_msg_is "commit message # comment" |
673 | ' | |
674 | ||
675 | test_expect_success 'cleanup commit message (option overrides config)' ' | |
676 | echo content >>file && | |
677 | git add file && | |
24e099f4 BC |
678 | ( |
679 | test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment && | |
680 | git -c commit.cleanup=whitespace commit --cleanup=default | |
681 | ) && | |
51fb3a3d RT |
682 | commit_msg_is "commit message" |
683 | ' | |
684 | ||
685 | test_expect_success 'cleanup commit message (default, -m)' ' | |
686 | echo content >>file && | |
687 | git add file && | |
688 | git commit -m "message #comment " && | |
689 | commit_msg_is "message #comment" | |
690 | ' | |
691 | ||
692 | test_expect_success 'cleanup commit message (whitespace option, -m)' ' | |
693 | echo content >>file && | |
694 | git add file && | |
695 | git commit --cleanup=whitespace --no-status -m "message #comment " && | |
696 | commit_msg_is "message #comment" | |
697 | ' | |
698 | ||
699 | test_expect_success 'cleanup commit message (whitespace config, -m)' ' | |
700 | echo content >>file && | |
701 | git add file && | |
702 | git -c commit.cleanup=whitespace commit --no-status -m "message #comment " && | |
703 | commit_msg_is "message #comment" | |
704 | ' | |
705 | ||
1f4bf345 | 706 | test_expect_success 'message shows author when it is not equal to committer' ' |
e83dbe80 | 707 | echo >>negative && |
ceacd91a | 708 | git commit -e -m "sample" -a && |
6789275d | 709 | test_grep \ |
1f4bf345 JK |
710 | "^# Author: *A U Thor <author@example.com>\$" \ |
711 | .git/COMMIT_EDITMSG | |
e83dbe80 SB |
712 | ' |
713 | ||
b7242b8c JK |
714 | test_expect_success 'message shows date when it is explicitly set' ' |
715 | git commit --allow-empty -e -m foo --date="2010-01-02T03:04:05" && | |
6789275d | 716 | test_grep \ |
b7242b8c JK |
717 | "^# Date: *Sat Jan 2 03:04:05 2010 +0000" \ |
718 | .git/COMMIT_EDITMSG | |
719 | ' | |
720 | ||
1d7dc264 | 721 | test_expect_success AUTOIDENT 'message shows committer when it is automatic' ' |
bb1ae3f6 SB |
722 | |
723 | echo >>negative && | |
7845944c | 724 | ( |
00648ba0 EN |
725 | sane_unset GIT_COMMITTER_EMAIL && |
726 | sane_unset GIT_COMMITTER_NAME && | |
1d7dc264 | 727 | git commit -e -m "sample" -a |
7845944c | 728 | ) && |
1f4bf345 JK |
729 | # the ident is calculated from the system, so we cannot |
730 | # check the actual value, only that it is there | |
6789275d | 731 | test_grep "^# Committer: " .git/COMMIT_EDITMSG |
bb1ae3f6 SB |
732 | ' |
733 | ||
a9ebc43b | 734 | write_script .git/FAKE_EDITOR <<EOF |
94ca361b | 735 | echo editor started >"$(pwd)/.git/result" |
ec84bd00 PB |
736 | exit 0 |
737 | EOF | |
ec84bd00 | 738 | |
cf7a8515 | 739 | test_expect_success !FAIL_PREREQS,!AUTOIDENT 'do not fire editor when committer is bogus' ' |
f84df81f | 740 | >.git/result && |
8c8b3bc3 JK |
741 | |
742 | echo >>negative && | |
743 | ( | |
744 | sane_unset GIT_COMMITTER_EMAIL && | |
745 | sane_unset GIT_COMMITTER_NAME && | |
746 | GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" && | |
747 | export GIT_EDITOR && | |
748 | test_must_fail git commit -e -m sample -a | |
749 | ) && | |
d3c6751b | 750 | test_must_be_empty .git/result |
8c8b3bc3 JK |
751 | ' |
752 | ||
25206778 RS |
753 | test_expect_success 'do not fire editor if -m <msg> was given' ' |
754 | echo tick >file && | |
755 | git add file && | |
756 | echo "editor not started" >.git/result && | |
757 | (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" git commit -m tick) && | |
758 | test "$(cat .git/result)" = "editor not started" | |
759 | ' | |
760 | ||
761 | test_expect_success 'do not fire editor if -m "" was given' ' | |
762 | echo tock >file && | |
763 | git add file && | |
764 | echo "editor not started" >.git/result && | |
765 | (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" \ | |
766 | git commit -m "" --allow-empty-message) && | |
767 | test "$(cat .git/result)" = "editor not started" | |
768 | ' | |
769 | ||
ec84bd00 PB |
770 | test_expect_success 'do not fire editor in the presence of conflicts' ' |
771 | ||
a3c91e08 JH |
772 | git clean -f && |
773 | echo f >g && | |
774 | git add g && | |
775 | git commit -m "add g" && | |
776 | git branch second && | |
1e2ae142 | 777 | echo main >g && |
a3c91e08 JH |
778 | echo g >h && |
779 | git add g h && | |
780 | git commit -m "modify g and add h" && | |
781 | git checkout second && | |
782 | echo second >g && | |
783 | git add g && | |
784 | git commit -m second && | |
785 | # Must fail due to conflict | |
1e2ae142 | 786 | test_must_fail git cherry-pick -n main && |
a3c91e08 | 787 | echo "editor not started" >.git/result && |
e2007832 | 788 | ( |
34565f27 | 789 | GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" && |
e2007832 BC |
790 | export GIT_EDITOR && |
791 | test_must_fail git commit | |
792 | ) && | |
a3c91e08 | 793 | test "$(cat .git/result)" = "editor not started" |
ec84bd00 PB |
794 | ' |
795 | ||
a9ebc43b | 796 | write_script .git/FAKE_EDITOR <<EOF |
ad5fa3cc PB |
797 | # kill -TERM command added below. |
798 | EOF | |
799 | ||
fb9a2bea | 800 | test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' ' |
ad5fa3cc | 801 | echo >>negative && |
09b78bc1 | 802 | ! "$SHELL_PATH" -c '\'' |
94ca361b | 803 | echo kill -TERM $$ >>.git/FAKE_EDITOR |
09b78bc1 BC |
804 | GIT_EDITOR=.git/FAKE_EDITOR |
805 | export GIT_EDITOR | |
806 | exec git commit -a'\'' && | |
807 | test ! -f .git/index.lock | |
ad5fa3cc PB |
808 | ' |
809 | ||
67bfc030 JH |
810 | rm -f .git/MERGE_MSG .git/COMMIT_EDITMSG |
811 | git reset -q --hard | |
812 | ||
813 | test_expect_success 'Hand committing of a redundant merge removes dups' ' | |
814 | ||
1e2ae142 JS |
815 | git rev-parse second main >expect && |
816 | test_must_fail git merge second main && | |
817 | git checkout main g && | |
67bfc030 | 818 | EDITOR=: git commit -a && |
94ca361b DL |
819 | git cat-file commit HEAD >raw && |
820 | sed -n -e "s/^parent //p" -e "/^$/q" raw >actual && | |
67bfc030 JH |
821 | test_cmp expect actual |
822 | ||
823 | ' | |
824 | ||
e5138436 JH |
825 | test_expect_success 'A single-liner subject with a token plus colon is not a footer' ' |
826 | ||
827 | git reset --hard && | |
828 | git commit -s -m "hello: kitty" --allow-empty && | |
94ca361b DL |
829 | git cat-file commit HEAD >raw && |
830 | sed -e "1,/^$/d" raw >actual && | |
3fb0459b | 831 | test_line_count = 3 actual |
e5138436 JH |
832 | |
833 | ' | |
834 | ||
8c613fd5 BC |
835 | test_expect_success 'commit -s places sob on third line after two empty lines' ' |
836 | git commit -s --allow-empty --allow-empty-message && | |
837 | cat <<-EOF >expect && | |
838 | ||
839 | ||
840 | Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> | |
841 | ||
842 | EOF | |
843 | sed -e "/^#/d" -e "s/^:.*//" .git/COMMIT_EDITMSG >actual && | |
844 | test_cmp expect actual | |
845 | ' | |
846 | ||
a9ebc43b JK |
847 | write_script .git/FAKE_EDITOR <<\EOF |
848 | mv "$1" "$1.orig" | |
f9c01817 JH |
849 | ( |
850 | echo message | |
a9ebc43b JK |
851 | cat "$1.orig" |
852 | ) >"$1" | |
f9c01817 JH |
853 | EOF |
854 | ||
855 | echo '## Custom template' >template | |
856 | ||
f9c01817 JH |
857 | try_commit () { |
858 | git reset --hard && | |
859 | echo >>negative && | |
860 | GIT_EDITOR=.git/FAKE_EDITOR git commit -a $* $use_template && | |
861 | case "$use_template" in | |
862 | '') | |
6789275d | 863 | test_grep ! "^## Custom template" .git/COMMIT_EDITMSG ;; |
f9c01817 | 864 | *) |
6789275d | 865 | test_grep "^## Custom template" .git/COMMIT_EDITMSG ;; |
f9c01817 JH |
866 | esac |
867 | } | |
868 | ||
869 | try_commit_status_combo () { | |
870 | ||
f79ce8db | 871 | test_expect_success 'commit' ' |
f9c01817 | 872 | try_commit "" && |
6789275d | 873 | test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
874 | ' |
875 | ||
f79ce8db | 876 | test_expect_success 'commit --status' ' |
f9c01817 | 877 | try_commit --status && |
6789275d | 878 | test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
879 | ' |
880 | ||
f79ce8db | 881 | test_expect_success 'commit --no-status' ' |
2dec68cf | 882 | try_commit --no-status && |
6789275d | 883 | test_grep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
884 | ' |
885 | ||
f79ce8db | 886 | test_expect_success 'commit with commit.status = yes' ' |
e023a31d | 887 | test_config commit.status yes && |
f9c01817 | 888 | try_commit "" && |
6789275d | 889 | test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
890 | ' |
891 | ||
f79ce8db | 892 | test_expect_success 'commit with commit.status = no' ' |
e023a31d | 893 | test_config commit.status no && |
f9c01817 | 894 | try_commit "" && |
6789275d | 895 | test_grep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
896 | ' |
897 | ||
f79ce8db | 898 | test_expect_success 'commit --status with commit.status = yes' ' |
e023a31d | 899 | test_config commit.status yes && |
f9c01817 | 900 | try_commit --status && |
6789275d | 901 | test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
902 | ' |
903 | ||
f79ce8db | 904 | test_expect_success 'commit --no-status with commit.status = yes' ' |
e023a31d | 905 | test_config commit.status yes && |
f9c01817 | 906 | try_commit --no-status && |
6789275d | 907 | test_grep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
908 | ' |
909 | ||
f79ce8db | 910 | test_expect_success 'commit --status with commit.status = no' ' |
e023a31d | 911 | test_config commit.status no && |
f9c01817 | 912 | try_commit --status && |
6789275d | 913 | test_grep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
914 | ' |
915 | ||
f79ce8db | 916 | test_expect_success 'commit --no-status with commit.status = no' ' |
e023a31d | 917 | test_config commit.status no && |
f9c01817 | 918 | try_commit --no-status && |
6789275d | 919 | test_grep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
920 | ' |
921 | ||
922 | } | |
923 | ||
924 | try_commit_status_combo | |
925 | ||
926 | use_template="-t template" | |
927 | ||
928 | try_commit_status_combo | |
929 | ||
eff80a9f | 930 | test_expect_success 'commit --status with custom comment character' ' |
464be630 | 931 | test_config core.commentchar ";" && |
eff80a9f | 932 | try_commit --status && |
6789275d | 933 | test_grep "^; Changes to be committed:" .git/COMMIT_EDITMSG |
eff80a9f JH |
934 | ' |
935 | ||
84c9dc2c NTND |
936 | test_expect_success 'switch core.commentchar' ' |
937 | test_commit "#foo" foo && | |
938 | GIT_EDITOR=.git/FAKE_EDITOR git -c core.commentChar=auto commit --amend && | |
6789275d | 939 | test_grep "^; Changes to be committed:" .git/COMMIT_EDITMSG |
84c9dc2c NTND |
940 | ' |
941 | ||
942 | test_expect_success 'switch core.commentchar but out of options' ' | |
943 | cat >text <<\EOF && | |
944 | # 1 | |
945 | ; 2 | |
946 | @ 3 | |
947 | ! 4 | |
948 | $ 5 | |
949 | % 6 | |
950 | ^ 7 | |
951 | & 8 | |
952 | | 9 | |
953 | : 10 | |
954 | EOF | |
955 | git commit --amend -F text && | |
956 | ( | |
957 | test_set_editor .git/FAKE_EDITOR && | |
958 | test_must_fail git -c core.commentChar=auto commit --amend | |
959 | ) | |
960 | ' | |
961 | ||
b468f0ce | 962 | test_done |