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
13 .
"$TEST_DIRECTORY/lib-gpg.sh"
15 test_expect_success setup
'
19 git commit -m "Initial" &&
27 git commit -a -m "Second" &&
29 git checkout -b left &&
33 git commit -a -m "Common #1" &&
37 git commit -a -m "Common #2" &&
43 GIT_COMMITTER_NAME="Another Committer" \
44 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
48 GIT_COMMITTER_NAME="Another Committer" \
49 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
53 GIT_COMMITTER_NAME="Another Committer" \
54 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
62 git commit -a -m "Right #3" &&
67 git commit -a -m "Right #4" &&
71 git commit -a -m "Right #5" &&
73 git checkout -b long &&
74 test_commit_bulk --start=0 --message=%s --filename=one 30 &&
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 &&
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 &&
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 &&
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' '
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' '
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}" &&
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}" &&
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}" &&
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}" &&
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}" &&
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}" &&
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 &&
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
233 test_config merge.log true &&
234 test_unconfig merge.summary &&
240 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
242 test_unconfig merge.log &&
243 test_config merge.summary true &&
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' '
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
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
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
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
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
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 &&
372 # By Another Author (3) and A U Thor (2)
373 # Via Another Committer
374 * ${apos}left${apos} of $(pwd):
382 test_unconfig merge.log &&
383 test_unconfig merge.summary &&
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' '
403 Merge branches ${apos}left${apos} and ${apos}right${apos}
405 # By Another Author (3) and A U Thor (2)
406 # Via Another Committer
423 test_expect_success
'shortlog for two branches' '
424 test_config merge.log true &&
425 test_unconfig merge.summary &&
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 &&
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 &&
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 &&
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 &&
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 &&
473 git fetch . left right &&
475 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
478 git fmt-merge-msg -F FETCH_HEAD >../actual
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 &&
489 git checkout -b unrelated &&
492 git fmt-merge-msg <.git/FETCH_HEAD >../actual
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}:
508 test_unconfig merge.log &&
509 test_config merge.summary yes &&
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}:
528 # By Another Author (3) and A U Thor (2)
529 # Via Another Committer
530 * tag ${apos}tag-l5${apos}:
538 test_unconfig merge.log &&
539 test_config merge.summary yes &&
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}:
558 # By Another Author (3) and A U Thor (2)
559 # Via Another Committer
568 test_unconfig merge.log &&
569 test_config merge.summary yes &&
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' '
582 Merge branch ${apos}long${apos}
591 i=$(($i-1)) || return 1
596 test_config merge.summary yes &&
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 &&
614 git fetch . annote &&
616 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
619 Merge tag '\''annote'\''
623 * tag '\''annote'\'':
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 &&
634 Merge tag '\''$annote'\''
638 * tag '\''$annote'\'':
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" &&
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