The 19th batch
[alt-git.git] / t / t6200-fmt-merge-msg.sh
blobac57b0e4ae37698f10cd53a612c8043c4f85acda
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_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
13 . "$TEST_DIRECTORY/lib-gpg.sh"
15 test_expect_success setup '
16 echo one >one &&
17 git add one &&
18 test_tick &&
19 git commit -m "Initial" &&
21 git clone . remote &&
23 echo uno >one &&
24 echo dos >two &&
25 git add two &&
26 test_tick &&
27 git commit -a -m "Second" &&
29 git checkout -b left &&
31 echo "c1" >one &&
32 test_tick &&
33 git commit -a -m "Common #1" &&
35 echo "c2" >one &&
36 test_tick &&
37 git commit -a -m "Common #2" &&
39 git branch right &&
41 echo "l3" >two &&
42 test_tick &&
43 GIT_COMMITTER_NAME="Another Committer" \
44 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
46 echo "l4" >two &&
47 test_tick &&
48 GIT_COMMITTER_NAME="Another Committer" \
49 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
51 echo "l5" >two &&
52 test_tick &&
53 GIT_COMMITTER_NAME="Another Committer" \
54 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
55 git tag tag-l5 &&
57 git checkout right &&
59 echo "r3" >three &&
60 git add three &&
61 test_tick &&
62 git commit -a -m "Right #3" &&
63 git tag tag-r3 &&
65 echo "r4" >three &&
66 test_tick &&
67 git commit -a -m "Right #4" &&
69 echo "r5" >three &&
70 test_tick &&
71 git commit -a -m "Right #5" &&
73 git checkout -b long &&
74 test_commit_bulk --start=0 --message=%s --filename=one 30 &&
76 git show-branch &&
78 apos="'\''"
81 test_expect_success GPG 'set up a signed tag' '
82 git tag -s -m signed-tag-msg signed-good-tag left
85 test_expect_success GPGSSH 'created ssh signed commit and tag' '
86 test_config gpg.format ssh &&
87 git checkout -b signed-ssh &&
88 touch file &&
89 git add file &&
90 git commit -m "ssh signed" -S"${GPGSSH_KEY_PRIMARY}" &&
91 git tag -s -u"${GPGSSH_KEY_PRIMARY}" -m signed-ssh-tag-msg signed-good-ssh-tag left &&
92 git tag -s -u"${GPGSSH_KEY_UNTRUSTED}" -m signed-ssh-tag-msg-untrusted signed-untrusted-ssh-tag left
95 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' '
96 test_when_finished "test_unconfig commit.gpgsign" &&
97 test_config gpg.format ssh &&
98 git checkout -b signed-expiry-ssh &&
99 touch file &&
100 git add file &&
102 echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" &&
103 git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed &&
105 echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" &&
106 git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed &&
108 echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" &&
109 git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed &&
111 echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" &&
112 git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed
115 test_expect_success 'message for merging local branch' '
116 echo "Merge branch ${apos}left${apos}" >expected &&
118 git checkout main &&
119 git fetch . left &&
121 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
122 test_cmp expected actual
125 test_expect_success GPG 'message for merging local tag signed by good key' '
126 git checkout main &&
127 git fetch . signed-good-tag &&
128 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
129 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
130 grep "^signed-tag-msg" actual &&
131 grep "^# gpg: Signature made" actual &&
132 grep "^# gpg: Good signature from" actual
135 test_expect_success GPG 'message for merging local tag signed by unknown key' '
136 git checkout main &&
137 git fetch . signed-good-tag &&
138 GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual &&
139 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
140 grep "^signed-tag-msg" actual &&
141 grep "^# gpg: Signature made" actual &&
142 grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual
145 test_expect_success GPGSSH 'message for merging local tag signed by good ssh key' '
146 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
147 git checkout main &&
148 git fetch . signed-good-ssh-tag &&
149 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
150 grep "^Merge tag ${apos}signed-good-ssh-tag${apos}" actual &&
151 grep "^signed-ssh-tag-msg" actual &&
152 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
153 ! grep "${GPGSSH_BAD_SIGNATURE}" actual
156 test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh key' '
157 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
158 git checkout main &&
159 git fetch . signed-untrusted-ssh-tag &&
160 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
161 grep "^Merge tag ${apos}signed-untrusted-ssh-tag${apos}" actual &&
162 grep "^signed-ssh-tag-msg-untrusted" actual &&
163 grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual &&
164 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
165 grep "${GPGSSH_KEY_NOT_TRUSTED}" actual
168 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by expired ssh key' '
169 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
170 git checkout main &&
171 git fetch . expired-signed &&
172 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
173 grep "^Merge tag ${apos}expired-signed${apos}" actual &&
174 grep "^expired-signed" actual &&
175 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
178 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by not yet valid ssh key' '
179 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
180 git checkout main &&
181 git fetch . notyetvalid-signed &&
182 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
183 grep "^Merge tag ${apos}notyetvalid-signed${apos}" actual &&
184 grep "^notyetvalid-signed" actual &&
185 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
188 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by valid timeboxed ssh key' '
189 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
190 git checkout main &&
191 git fetch . timeboxedvalid-signed &&
192 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
193 grep "^Merge tag ${apos}timeboxedvalid-signed${apos}" actual &&
194 grep "^timeboxedvalid-signed" actual &&
195 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
196 ! grep "${GPGSSH_BAD_SIGNATURE}" actual
199 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by invalid timeboxed ssh key' '
200 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
201 git checkout main &&
202 git fetch . timeboxedinvalid-signed &&
203 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
204 grep "^Merge tag ${apos}timeboxedinvalid-signed${apos}" actual &&
205 grep "^timeboxedinvalid-signed" actual &&
206 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
209 test_expect_success 'message for merging external branch' '
210 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
212 git checkout main &&
213 git fetch "$(pwd)" left &&
215 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
216 test_cmp expected actual
219 test_expect_success '[merge] summary/log configuration' '
220 cat >expected <<-EOF &&
221 Merge branch ${apos}left${apos}
223 # By Another Author (3) and A U Thor (2)
224 # Via Another Committer
225 * left:
226 Left #5
227 Left #4
228 Left #3
229 Common #2
230 Common #1
233 test_config merge.log true &&
234 test_unconfig merge.summary &&
236 git checkout main &&
237 test_tick &&
238 git fetch . left &&
240 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
242 test_unconfig merge.log &&
243 test_config merge.summary true &&
245 git checkout main &&
246 test_tick &&
247 git fetch . left &&
249 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
251 test_cmp expected actual1 &&
252 test_cmp expected actual2
255 test_expect_success 'setup FETCH_HEAD' '
256 git checkout main &&
257 test_tick &&
258 git fetch . left
261 test_expect_success 'merge.log=3 limits shortlog length' '
262 cat >expected <<-EOF &&
263 Merge branch ${apos}left${apos}
265 # By Another Author (3) and A U Thor (2)
266 # Via Another Committer
267 * left: (5 commits)
268 Left #5
269 Left #4
270 Left #3
274 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
275 test_cmp expected actual
278 test_expect_success 'merge.log=5 shows all 5 commits' '
279 cat >expected <<-EOF &&
280 Merge branch ${apos}left${apos}
282 # By Another Author (3) and A U Thor (2)
283 # Via Another Committer
284 * left:
285 Left #5
286 Left #4
287 Left #3
288 Common #2
289 Common #1
292 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
293 test_cmp expected actual
296 test_expect_success '--log=5 with custom comment character' '
297 cat >expected <<-EOF &&
298 Merge branch ${apos}left${apos}
300 x By Another Author (3) and A U Thor (2)
301 x Via Another Committer
302 * left:
303 Left #5
304 Left #4
305 Left #3
306 Common #2
307 Common #1
310 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
311 test_cmp expected actual
314 test_expect_success 'merge.log=0 disables shortlog' '
315 echo "Merge branch ${apos}left${apos}" >expected &&
316 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
317 test_cmp expected actual
320 test_expect_success '--log=3 limits shortlog length' '
321 cat >expected <<-EOF &&
322 Merge branch ${apos}left${apos}
324 # By Another Author (3) and A U Thor (2)
325 # Via Another Committer
326 * left: (5 commits)
327 Left #5
328 Left #4
329 Left #3
333 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
334 test_cmp expected actual
337 test_expect_success '--log=5 shows all 5 commits' '
338 cat >expected <<-EOF &&
339 Merge branch ${apos}left${apos}
341 # By Another Author (3) and A U Thor (2)
342 # Via Another Committer
343 * left:
344 Left #5
345 Left #4
346 Left #3
347 Common #2
348 Common #1
351 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
352 test_cmp expected actual
355 test_expect_success '--no-log disables shortlog' '
356 echo "Merge branch ${apos}left${apos}" >expected &&
357 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
358 test_cmp expected actual
361 test_expect_success '--log=0 disables shortlog' '
362 echo "Merge branch ${apos}left${apos}" >expected &&
363 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
364 test_cmp expected actual
367 test_expect_success 'fmt-merge-msg -m' '
368 echo "Sync with left" >expected &&
369 cat >expected.log <<-EOF &&
370 Sync with left
372 # By Another Author (3) and A U Thor (2)
373 # Via Another Committer
374 * ${apos}left${apos} of $(pwd):
375 Left #5
376 Left #4
377 Left #3
378 Common #2
379 Common #1
382 test_unconfig merge.log &&
383 test_unconfig merge.summary &&
384 git checkout main &&
385 git fetch "$(pwd)" left &&
386 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
387 git fmt-merge-msg --log -m "Sync with left" \
388 <.git/FETCH_HEAD >actual.log &&
389 test_config merge.log true &&
390 git fmt-merge-msg -m "Sync with left" \
391 <.git/FETCH_HEAD >actual.log-config &&
392 git fmt-merge-msg --no-log -m "Sync with left" \
393 <.git/FETCH_HEAD >actual.nolog &&
395 test_cmp expected actual &&
396 test_cmp expected.log actual.log &&
397 test_cmp expected.log actual.log-config &&
398 test_cmp expected actual.nolog
401 test_expect_success 'setup: expected shortlog for two branches' '
402 cat >expected <<-EOF
403 Merge branches ${apos}left${apos} and ${apos}right${apos}
405 # By Another Author (3) and A U Thor (2)
406 # Via Another Committer
407 * left:
408 Left #5
409 Left #4
410 Left #3
411 Common #2
412 Common #1
414 * right:
415 Right #5
416 Right #4
417 Right #3
418 Common #2
419 Common #1
423 test_expect_success 'shortlog for two branches' '
424 test_config merge.log true &&
425 test_unconfig merge.summary &&
426 git checkout main &&
427 test_tick &&
428 git fetch . left right &&
429 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
431 test_unconfig merge.log &&
432 test_config merge.summary true &&
433 git checkout main &&
434 test_tick &&
435 git fetch . left right &&
436 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
438 test_config merge.log yes &&
439 test_unconfig merge.summary &&
440 git checkout main &&
441 test_tick &&
442 git fetch . left right &&
443 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
445 test_unconfig merge.log &&
446 test_config merge.summary yes &&
447 git checkout main &&
448 test_tick &&
449 git fetch . left right &&
450 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
452 test_cmp expected actual1 &&
453 test_cmp expected actual2 &&
454 test_cmp expected actual3 &&
455 test_cmp expected actual4
458 test_expect_success 'merge-msg -F' '
459 test_unconfig merge.log &&
460 test_config merge.summary yes &&
461 git checkout main &&
462 test_tick &&
463 git fetch . left right &&
464 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
465 test_cmp expected actual
468 test_expect_success 'merge-msg -F in subdirectory' '
469 test_unconfig merge.log &&
470 test_config merge.summary yes &&
471 git checkout main &&
472 test_tick &&
473 git fetch . left right &&
474 mkdir sub &&
475 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
477 cd sub &&
478 git fmt-merge-msg -F FETCH_HEAD >../actual
479 ) &&
480 test_cmp expected actual
483 test_expect_success 'merge-msg with nothing to merge' '
484 test_unconfig merge.log &&
485 test_config merge.summary yes &&
488 cd remote &&
489 git checkout -b unrelated &&
490 test_tick &&
491 git fetch origin &&
492 git fmt-merge-msg <.git/FETCH_HEAD >../actual
493 ) &&
495 test_must_be_empty actual
498 test_expect_success 'merge-msg tag' '
499 cat >expected <<-EOF &&
500 Merge tag ${apos}tag-r3${apos}
502 * tag ${apos}tag-r3${apos}:
503 Right #3
504 Common #2
505 Common #1
508 test_unconfig merge.log &&
509 test_config merge.summary yes &&
511 git checkout main &&
512 test_tick &&
513 git fetch . tag tag-r3 &&
515 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
516 test_cmp expected actual
519 test_expect_success 'merge-msg two tags' '
520 cat >expected <<-EOF &&
521 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
523 * tag ${apos}tag-r3${apos}:
524 Right #3
525 Common #2
526 Common #1
528 # By Another Author (3) and A U Thor (2)
529 # Via Another Committer
530 * tag ${apos}tag-l5${apos}:
531 Left #5
532 Left #4
533 Left #3
534 Common #2
535 Common #1
538 test_unconfig merge.log &&
539 test_config merge.summary yes &&
541 git checkout main &&
542 test_tick &&
543 git fetch . tag tag-r3 tag tag-l5 &&
545 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
546 test_cmp expected actual
549 test_expect_success 'merge-msg tag and branch' '
550 cat >expected <<-EOF &&
551 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
553 * tag ${apos}tag-r3${apos}:
554 Right #3
555 Common #2
556 Common #1
558 # By Another Author (3) and A U Thor (2)
559 # Via Another Committer
560 * left:
561 Left #5
562 Left #4
563 Left #3
564 Common #2
565 Common #1
568 test_unconfig merge.log &&
569 test_config merge.summary yes &&
571 git checkout main &&
572 test_tick &&
573 git fetch . tag tag-r3 left &&
575 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
576 test_cmp expected actual
579 test_expect_success 'merge-msg lots of commits' '
581 cat <<-EOF &&
582 Merge branch ${apos}long${apos}
584 * long: (35 commits)
587 i=29 &&
588 while test $i -gt 9
590 echo " $i" &&
591 i=$(($i-1)) || return 1
592 done &&
593 echo " ..."
594 } >expected &&
596 test_config merge.summary yes &&
598 git checkout main &&
599 test_tick &&
600 git fetch . long &&
602 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
603 test_cmp expected actual
606 test_expect_success 'merge-msg with "merging" an annotated tag' '
607 test_config merge.log true &&
609 git checkout main^0 &&
610 git commit --allow-empty -m "One step ahead" &&
611 git tag -a -m "An annotated one" annote HEAD &&
613 git checkout main &&
614 git fetch . annote &&
616 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
618 cat <<-\EOF
619 Merge tag '\''annote'\''
621 An annotated one
623 * tag '\''annote'\'':
624 One step ahead
626 } >expected &&
627 test_cmp expected actual &&
629 test_when_finished "git reset --hard" &&
630 annote=$(git rev-parse annote) &&
631 git merge --no-commit --no-ff $annote &&
633 cat <<-EOF
634 Merge tag '\''$annote'\''
636 An annotated one
638 * tag '\''$annote'\'':
639 One step ahead
641 } >expected &&
642 test_cmp expected .git/MERGE_MSG
645 test_expect_success 'merge --into-name=<name>' '
646 test_when_finished "git checkout main" &&
647 git checkout -B side main &&
648 git commit --allow-empty -m "One step ahead" &&
650 git checkout --detach main &&
651 git merge --no-ff side &&
652 git show -s --format="%s" >full.0 &&
653 head -n1 full.0 >actual &&
654 # expect that HEAD is shown as-is
655 grep -e "Merge branch .side. into HEAD$" actual &&
657 git reset --hard main &&
658 git merge --no-ff --into-name=main side &&
659 git show -s --format="%s" >full.1 &&
660 head -n1 full.1 >actual &&
661 # expect that we pretend to be merging to main, that is suppressed
662 grep -e "Merge branch .side.$" actual &&
664 git checkout -b throwaway main &&
665 git merge --no-ff --into-name=main side &&
666 git show -s --format="%s" >full.2 &&
667 head -n1 full.2 >actual &&
668 # expect that we pretend to be merging to main, that is suppressed
669 grep -e "Merge branch .side.$" actual
672 test_expect_success 'merge.suppressDest configuration' '
673 test_when_finished "git checkout main" &&
674 git checkout -B side main &&
675 git commit --allow-empty -m "One step ahead" &&
676 git checkout main &&
677 git fetch . side &&
679 git -c merge.suppressDest="" fmt-merge-msg <.git/FETCH_HEAD >full.1 &&
680 head -n1 full.1 >actual &&
681 grep -e "Merge branch .side. into main" actual &&
683 git -c merge.suppressDest="mast" fmt-merge-msg <.git/FETCH_HEAD >full.2 &&
684 head -n1 full.2 >actual &&
685 grep -e "Merge branch .side. into main$" actual &&
687 git -c merge.suppressDest="ma?*[rn]" fmt-merge-msg <.git/FETCH_HEAD >full.3 &&
688 head -n1 full.3 >actual &&
689 grep -e "Merge branch .side." actual &&
690 ! grep -e " into main$" actual &&
692 git checkout --detach HEAD &&
693 git -c merge.suppressDest="main" fmt-merge-msg <.git/FETCH_HEAD >full.4 &&
694 head -n1 full.4 >actual &&
695 grep -e "Merge branch .side. into HEAD$" actual &&
697 git -c merge.suppressDest="main" fmt-merge-msg \
698 --into-name=main <.git/FETCH_HEAD >full.5 &&
699 head -n1 full.5 >actual &&
700 grep -e "Merge branch .side." actual &&
701 ! grep -e " into main$" actual &&
702 ! grep -e " into HEAD$" actual
705 test_done