ci: avoid bare "gcc" for osx-gcc job
[git.git] / t / t6200-fmt-merge-msg.sh
blob5a221f8ef1fd810731a4dd8b0d5cdab988084ed8
1 #!/bin/sh
3 # Copyright (c) 2006, Junio C Hamano
6 test_description='fmt-merge-msg test'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 . ./test-lib.sh
12 . "$TEST_DIRECTORY/lib-gpg.sh"
14 test_expect_success setup '
15 echo one >one &&
16 git add one &&
17 test_tick &&
18 git commit -m "Initial" &&
20 git clone . remote &&
22 echo uno >one &&
23 echo dos >two &&
24 git add two &&
25 test_tick &&
26 git commit -a -m "Second" &&
28 git checkout -b left &&
30 echo "c1" >one &&
31 test_tick &&
32 git commit -a -m "Common #1" &&
34 echo "c2" >one &&
35 test_tick &&
36 git commit -a -m "Common #2" &&
38 git branch right &&
40 echo "l3" >two &&
41 test_tick &&
42 GIT_COMMITTER_NAME="Another Committer" \
43 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
45 echo "l4" >two &&
46 test_tick &&
47 GIT_COMMITTER_NAME="Another Committer" \
48 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
50 echo "l5" >two &&
51 test_tick &&
52 GIT_COMMITTER_NAME="Another Committer" \
53 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
54 git tag tag-l5 &&
56 git checkout right &&
58 echo "r3" >three &&
59 git add three &&
60 test_tick &&
61 git commit -a -m "Right #3" &&
62 git tag tag-r3 &&
64 echo "r4" >three &&
65 test_tick &&
66 git commit -a -m "Right #4" &&
68 echo "r5" >three &&
69 test_tick &&
70 git commit -a -m "Right #5" &&
72 git checkout -b long &&
73 test_commit_bulk --start=0 --message=%s --filename=one 30 &&
75 git show-branch &&
77 apos="'\''"
80 test_expect_success GPG 'set up a signed tag' '
81 git tag -s -m signed-tag-msg signed-good-tag left
84 test_expect_success GPGSSH 'created ssh signed commit and tag' '
85 test_config gpg.format ssh &&
86 git checkout -b signed-ssh &&
87 touch file &&
88 git add file &&
89 git commit -m "ssh signed" -S"${GPGSSH_KEY_PRIMARY}" &&
90 git tag -s -u"${GPGSSH_KEY_PRIMARY}" -m signed-ssh-tag-msg signed-good-ssh-tag left &&
91 git tag -s -u"${GPGSSH_KEY_UNTRUSTED}" -m signed-ssh-tag-msg-untrusted signed-untrusted-ssh-tag left
94 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' '
95 test_when_finished "test_unconfig commit.gpgsign" &&
96 test_config gpg.format ssh &&
97 git checkout -b signed-expiry-ssh &&
98 touch file &&
99 git add file &&
101 echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" &&
102 git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed &&
104 echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" &&
105 git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed &&
107 echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" &&
108 git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed &&
110 echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" &&
111 git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed
114 test_expect_success 'message for merging local branch' '
115 echo "Merge branch ${apos}left${apos}" >expected &&
117 git checkout main &&
118 git fetch . left &&
120 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
121 test_cmp expected actual
124 test_expect_success GPG 'message for merging local tag signed by good key' '
125 git checkout main &&
126 git fetch . signed-good-tag &&
127 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
128 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
129 grep "^signed-tag-msg" actual &&
130 grep "^# gpg: Signature made" actual &&
131 grep "^# gpg: Good signature from" actual
134 test_expect_success GPG 'message for merging local tag signed by unknown key' '
135 git checkout main &&
136 git fetch . signed-good-tag &&
137 GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual &&
138 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
139 grep "^signed-tag-msg" actual &&
140 grep "^# gpg: Signature made" actual &&
141 grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual
144 test_expect_success GPGSSH 'message for merging local tag signed by good ssh key' '
145 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
146 git checkout main &&
147 git fetch . signed-good-ssh-tag &&
148 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
149 grep "^Merge tag ${apos}signed-good-ssh-tag${apos}" actual &&
150 grep "^signed-ssh-tag-msg" actual &&
151 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
152 ! grep "${GPGSSH_BAD_SIGNATURE}" actual
155 test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh key' '
156 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
157 git checkout main &&
158 git fetch . signed-untrusted-ssh-tag &&
159 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
160 grep "^Merge tag ${apos}signed-untrusted-ssh-tag${apos}" actual &&
161 grep "^signed-ssh-tag-msg-untrusted" actual &&
162 grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual &&
163 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
164 grep "${GPGSSH_KEY_NOT_TRUSTED}" actual
167 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by expired ssh key' '
168 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
169 git checkout main &&
170 git fetch . expired-signed &&
171 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
172 grep "^Merge tag ${apos}expired-signed${apos}" actual &&
173 grep "^expired-signed" actual &&
174 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
177 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by not yet valid ssh key' '
178 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
179 git checkout main &&
180 git fetch . notyetvalid-signed &&
181 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
182 grep "^Merge tag ${apos}notyetvalid-signed${apos}" actual &&
183 grep "^notyetvalid-signed" actual &&
184 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
187 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by valid timeboxed ssh key' '
188 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
189 git checkout main &&
190 git fetch . timeboxedvalid-signed &&
191 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
192 grep "^Merge tag ${apos}timeboxedvalid-signed${apos}" actual &&
193 grep "^timeboxedvalid-signed" actual &&
194 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
195 ! grep "${GPGSSH_BAD_SIGNATURE}" actual
198 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by invalid timeboxed ssh key' '
199 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
200 git checkout main &&
201 git fetch . timeboxedinvalid-signed &&
202 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
203 grep "^Merge tag ${apos}timeboxedinvalid-signed${apos}" actual &&
204 grep "^timeboxedinvalid-signed" actual &&
205 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
208 test_expect_success 'message for merging external branch' '
209 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
211 git checkout main &&
212 git fetch "$(pwd)" left &&
214 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
215 test_cmp expected actual
218 test_expect_success '[merge] summary/log configuration' '
219 cat >expected <<-EOF &&
220 Merge branch ${apos}left${apos}
222 # By Another Author (3) and A U Thor (2)
223 # Via Another Committer
224 * left:
225 Left #5
226 Left #4
227 Left #3
228 Common #2
229 Common #1
232 test_config merge.log true &&
233 test_unconfig merge.summary &&
235 git checkout main &&
236 test_tick &&
237 git fetch . left &&
239 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
241 test_unconfig merge.log &&
242 test_config merge.summary true &&
244 git checkout main &&
245 test_tick &&
246 git fetch . left &&
248 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
250 test_cmp expected actual1 &&
251 test_cmp expected actual2
254 test_expect_success 'setup FETCH_HEAD' '
255 git checkout main &&
256 test_tick &&
257 git fetch . left
260 test_expect_success 'merge.log=3 limits shortlog length' '
261 cat >expected <<-EOF &&
262 Merge branch ${apos}left${apos}
264 # By Another Author (3) and A U Thor (2)
265 # Via Another Committer
266 * left: (5 commits)
267 Left #5
268 Left #4
269 Left #3
273 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
274 test_cmp expected actual
277 test_expect_success 'merge.log=5 shows all 5 commits' '
278 cat >expected <<-EOF &&
279 Merge branch ${apos}left${apos}
281 # By Another Author (3) and A U Thor (2)
282 # Via Another Committer
283 * left:
284 Left #5
285 Left #4
286 Left #3
287 Common #2
288 Common #1
291 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
292 test_cmp expected actual
295 test_expect_success '--log=5 with custom comment character' '
296 cat >expected <<-EOF &&
297 Merge branch ${apos}left${apos}
299 x By Another Author (3) and A U Thor (2)
300 x Via Another Committer
301 * left:
302 Left #5
303 Left #4
304 Left #3
305 Common #2
306 Common #1
309 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
310 test_cmp expected actual
313 test_expect_success 'merge.log=0 disables shortlog' '
314 echo "Merge branch ${apos}left${apos}" >expected &&
315 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
316 test_cmp expected actual
319 test_expect_success '--log=3 limits shortlog length' '
320 cat >expected <<-EOF &&
321 Merge branch ${apos}left${apos}
323 # By Another Author (3) and A U Thor (2)
324 # Via Another Committer
325 * left: (5 commits)
326 Left #5
327 Left #4
328 Left #3
332 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
333 test_cmp expected actual
336 test_expect_success '--log=5 shows all 5 commits' '
337 cat >expected <<-EOF &&
338 Merge branch ${apos}left${apos}
340 # By Another Author (3) and A U Thor (2)
341 # Via Another Committer
342 * left:
343 Left #5
344 Left #4
345 Left #3
346 Common #2
347 Common #1
350 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
351 test_cmp expected actual
354 test_expect_success '--no-log disables shortlog' '
355 echo "Merge branch ${apos}left${apos}" >expected &&
356 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
357 test_cmp expected actual
360 test_expect_success '--log=0 disables shortlog' '
361 echo "Merge branch ${apos}left${apos}" >expected &&
362 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
363 test_cmp expected actual
366 test_expect_success 'fmt-merge-msg -m' '
367 echo "Sync with left" >expected &&
368 cat >expected.log <<-EOF &&
369 Sync with left
371 # By Another Author (3) and A U Thor (2)
372 # Via Another Committer
373 * ${apos}left${apos} of $(pwd):
374 Left #5
375 Left #4
376 Left #3
377 Common #2
378 Common #1
381 test_unconfig merge.log &&
382 test_unconfig merge.summary &&
383 git checkout main &&
384 git fetch "$(pwd)" left &&
385 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
386 git fmt-merge-msg --log -m "Sync with left" \
387 <.git/FETCH_HEAD >actual.log &&
388 test_config merge.log true &&
389 git fmt-merge-msg -m "Sync with left" \
390 <.git/FETCH_HEAD >actual.log-config &&
391 git fmt-merge-msg --no-log -m "Sync with left" \
392 <.git/FETCH_HEAD >actual.nolog &&
394 test_cmp expected actual &&
395 test_cmp expected.log actual.log &&
396 test_cmp expected.log actual.log-config &&
397 test_cmp expected actual.nolog
400 test_expect_success 'setup: expected shortlog for two branches' '
401 cat >expected <<-EOF
402 Merge branches ${apos}left${apos} and ${apos}right${apos}
404 # By Another Author (3) and A U Thor (2)
405 # Via Another Committer
406 * left:
407 Left #5
408 Left #4
409 Left #3
410 Common #2
411 Common #1
413 * right:
414 Right #5
415 Right #4
416 Right #3
417 Common #2
418 Common #1
422 test_expect_success 'shortlog for two branches' '
423 test_config merge.log true &&
424 test_unconfig merge.summary &&
425 git checkout main &&
426 test_tick &&
427 git fetch . left right &&
428 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
430 test_unconfig merge.log &&
431 test_config merge.summary true &&
432 git checkout main &&
433 test_tick &&
434 git fetch . left right &&
435 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
437 test_config merge.log yes &&
438 test_unconfig merge.summary &&
439 git checkout main &&
440 test_tick &&
441 git fetch . left right &&
442 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
444 test_unconfig merge.log &&
445 test_config merge.summary yes &&
446 git checkout main &&
447 test_tick &&
448 git fetch . left right &&
449 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
451 test_cmp expected actual1 &&
452 test_cmp expected actual2 &&
453 test_cmp expected actual3 &&
454 test_cmp expected actual4
457 test_expect_success 'merge-msg -F' '
458 test_unconfig merge.log &&
459 test_config merge.summary yes &&
460 git checkout main &&
461 test_tick &&
462 git fetch . left right &&
463 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
464 test_cmp expected actual
467 test_expect_success 'merge-msg -F in subdirectory' '
468 test_unconfig merge.log &&
469 test_config merge.summary yes &&
470 git checkout main &&
471 test_tick &&
472 git fetch . left right &&
473 mkdir sub &&
474 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
476 cd sub &&
477 git fmt-merge-msg -F FETCH_HEAD >../actual
478 ) &&
479 test_cmp expected actual
482 test_expect_success 'merge-msg with nothing to merge' '
483 test_unconfig merge.log &&
484 test_config merge.summary yes &&
487 cd remote &&
488 git checkout -b unrelated &&
489 test_tick &&
490 git fetch origin &&
491 git fmt-merge-msg <.git/FETCH_HEAD >../actual
492 ) &&
494 test_must_be_empty actual
497 test_expect_success 'merge-msg tag' '
498 cat >expected <<-EOF &&
499 Merge tag ${apos}tag-r3${apos}
501 * tag ${apos}tag-r3${apos}:
502 Right #3
503 Common #2
504 Common #1
507 test_unconfig merge.log &&
508 test_config merge.summary yes &&
510 git checkout main &&
511 test_tick &&
512 git fetch . tag tag-r3 &&
514 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
515 test_cmp expected actual
518 test_expect_success 'merge-msg two tags' '
519 cat >expected <<-EOF &&
520 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
522 * tag ${apos}tag-r3${apos}:
523 Right #3
524 Common #2
525 Common #1
527 # By Another Author (3) and A U Thor (2)
528 # Via Another Committer
529 * tag ${apos}tag-l5${apos}:
530 Left #5
531 Left #4
532 Left #3
533 Common #2
534 Common #1
537 test_unconfig merge.log &&
538 test_config merge.summary yes &&
540 git checkout main &&
541 test_tick &&
542 git fetch . tag tag-r3 tag tag-l5 &&
544 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
545 test_cmp expected actual
548 test_expect_success 'merge-msg tag and branch' '
549 cat >expected <<-EOF &&
550 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
552 * tag ${apos}tag-r3${apos}:
553 Right #3
554 Common #2
555 Common #1
557 # By Another Author (3) and A U Thor (2)
558 # Via Another Committer
559 * left:
560 Left #5
561 Left #4
562 Left #3
563 Common #2
564 Common #1
567 test_unconfig merge.log &&
568 test_config merge.summary yes &&
570 git checkout main &&
571 test_tick &&
572 git fetch . tag tag-r3 left &&
574 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
575 test_cmp expected actual
578 test_expect_success 'merge-msg lots of commits' '
580 cat <<-EOF &&
581 Merge branch ${apos}long${apos}
583 * long: (35 commits)
586 i=29 &&
587 while test $i -gt 9
589 echo " $i" &&
590 i=$(($i-1)) || return 1
591 done &&
592 echo " ..."
593 } >expected &&
595 test_config merge.summary yes &&
597 git checkout main &&
598 test_tick &&
599 git fetch . long &&
601 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
602 test_cmp expected actual
605 test_expect_success 'merge-msg with "merging" an annotated tag' '
606 test_config merge.log true &&
608 git checkout main^0 &&
609 git commit --allow-empty -m "One step ahead" &&
610 git tag -a -m "An annotated one" annote HEAD &&
612 git checkout main &&
613 git fetch . annote &&
615 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
617 cat <<-\EOF
618 Merge tag '\''annote'\''
620 An annotated one
622 * tag '\''annote'\'':
623 One step ahead
625 } >expected &&
626 test_cmp expected actual &&
628 test_when_finished "git reset --hard" &&
629 annote=$(git rev-parse annote) &&
630 git merge --no-commit --no-ff $annote &&
632 cat <<-EOF
633 Merge tag '\''$annote'\''
635 An annotated one
637 * tag '\''$annote'\'':
638 One step ahead
640 } >expected &&
641 test_cmp expected .git/MERGE_MSG
644 test_expect_success 'merge --into-name=<name>' '
645 test_when_finished "git checkout main" &&
646 git checkout -B side main &&
647 git commit --allow-empty -m "One step ahead" &&
649 git checkout --detach main &&
650 git merge --no-ff side &&
651 git show -s --format="%s" >full.0 &&
652 head -n1 full.0 >actual &&
653 # expect that HEAD is shown as-is
654 grep -e "Merge branch .side. into HEAD$" actual &&
656 git reset --hard main &&
657 git merge --no-ff --into-name=main side &&
658 git show -s --format="%s" >full.1 &&
659 head -n1 full.1 >actual &&
660 # expect that we pretend to be merging to main, that is suppressed
661 grep -e "Merge branch .side.$" actual &&
663 git checkout -b throwaway main &&
664 git merge --no-ff --into-name=main side &&
665 git show -s --format="%s" >full.2 &&
666 head -n1 full.2 >actual &&
667 # expect that we pretend to be merging to main, that is suppressed
668 grep -e "Merge branch .side.$" actual
671 test_expect_success 'merge.suppressDest configuration' '
672 test_when_finished "git checkout main" &&
673 git checkout -B side main &&
674 git commit --allow-empty -m "One step ahead" &&
675 git checkout main &&
676 git fetch . side &&
678 git -c merge.suppressDest="" fmt-merge-msg <.git/FETCH_HEAD >full.1 &&
679 head -n1 full.1 >actual &&
680 grep -e "Merge branch .side. into main" actual &&
682 git -c merge.suppressDest="mast" fmt-merge-msg <.git/FETCH_HEAD >full.2 &&
683 head -n1 full.2 >actual &&
684 grep -e "Merge branch .side. into main$" actual &&
686 git -c merge.suppressDest="ma?*[rn]" fmt-merge-msg <.git/FETCH_HEAD >full.3 &&
687 head -n1 full.3 >actual &&
688 grep -e "Merge branch .side." actual &&
689 ! grep -e " into main$" actual &&
691 git checkout --detach HEAD &&
692 git -c merge.suppressDest="main" fmt-merge-msg <.git/FETCH_HEAD >full.4 &&
693 head -n1 full.4 >actual &&
694 grep -e "Merge branch .side. into HEAD$" actual &&
696 git -c merge.suppressDest="main" fmt-merge-msg \
697 --into-name=main <.git/FETCH_HEAD >full.5 &&
698 head -n1 full.5 >actual &&
699 grep -e "Merge branch .side." actual &&
700 ! grep -e " into main$" actual &&
701 ! grep -e " into HEAD$" actual
704 test_done