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
12 .
"$TEST_DIRECTORY/lib-gpg.sh"
14 test_expect_success setup
'
18 git commit -m "Initial" &&
26 git commit -a -m "Second" &&
28 git checkout -b left &&
32 git commit -a -m "Common #1" &&
36 git commit -a -m "Common #2" &&
42 GIT_COMMITTER_NAME="Another Committer" \
43 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
47 GIT_COMMITTER_NAME="Another Committer" \
48 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
52 GIT_COMMITTER_NAME="Another Committer" \
53 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
61 git commit -a -m "Right #3" &&
66 git commit -a -m "Right #4" &&
70 git commit -a -m "Right #5" &&
72 git checkout -b long &&
73 test_commit_bulk --start=0 --message=%s --filename=one 30 &&
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 &&
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 &&
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 &&
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' '
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 "^# gpg: Signature made" actual &&
130 grep "^# gpg: Good signature from" actual
133 test_expect_success GPG
'message for merging local tag signed by unknown key' '
135 git fetch . signed-good-tag &&
136 GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual &&
137 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
138 grep "^# gpg: Signature made" actual &&
139 grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual
142 test_expect_success GPGSSH
'message for merging local tag signed by good ssh key' '
143 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
145 git fetch . signed-good-ssh-tag &&
146 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
147 grep "^Merge tag ${apos}signed-good-ssh-tag${apos}" actual &&
148 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
149 ! grep "${GPGSSH_BAD_SIGNATURE}" actual
152 test_expect_success GPGSSH
'message for merging local tag signed by unknown ssh key' '
153 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
155 git fetch . signed-untrusted-ssh-tag &&
156 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
157 grep "^Merge tag ${apos}signed-untrusted-ssh-tag${apos}" actual &&
158 grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual &&
159 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
160 grep "${GPGSSH_KEY_NOT_TRUSTED}" actual
163 test_expect_success GPGSSH
,GPGSSH_VERIFYTIME
'message for merging local tag signed by expired ssh key' '
164 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
166 git fetch . expired-signed &&
167 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
168 grep "^Merge tag ${apos}expired-signed${apos}" actual &&
169 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
172 test_expect_success GPGSSH
,GPGSSH_VERIFYTIME
'message for merging local tag signed by not yet valid ssh key' '
173 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
175 git fetch . notyetvalid-signed &&
176 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
177 grep "^Merge tag ${apos}notyetvalid-signed${apos}" actual &&
178 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
181 test_expect_success GPGSSH
,GPGSSH_VERIFYTIME
'message for merging local tag signed by valid timeboxed ssh key' '
182 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
184 git fetch . timeboxedvalid-signed &&
185 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
186 grep "^Merge tag ${apos}timeboxedvalid-signed${apos}" actual &&
187 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
188 ! grep "${GPGSSH_BAD_SIGNATURE}" actual
191 test_expect_success GPGSSH
,GPGSSH_VERIFYTIME
'message for merging local tag signed by invalid timeboxed ssh key' '
192 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
194 git fetch . timeboxedinvalid-signed &&
195 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
196 grep "^Merge tag ${apos}timeboxedinvalid-signed${apos}" actual &&
197 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
200 test_expect_success
'message for merging external branch' '
201 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
204 git fetch "$(pwd)" left &&
206 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
207 test_cmp expected actual
210 test_expect_success
'[merge] summary/log configuration' '
211 cat >expected <<-EOF &&
212 Merge branch ${apos}left${apos}
214 # By Another Author (3) and A U Thor (2)
215 # Via Another Committer
224 test_config merge.log true &&
225 test_unconfig merge.summary &&
231 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
233 test_unconfig merge.log &&
234 test_config merge.summary true &&
240 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
242 test_cmp expected actual1 &&
243 test_cmp expected actual2
246 test_expect_success
'setup FETCH_HEAD' '
252 test_expect_success
'merge.log=3 limits shortlog length' '
253 cat >expected <<-EOF &&
254 Merge branch ${apos}left${apos}
256 # By Another Author (3) and A U Thor (2)
257 # Via Another Committer
265 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
266 test_cmp expected actual
269 test_expect_success
'merge.log=5 shows all 5 commits' '
270 cat >expected <<-EOF &&
271 Merge branch ${apos}left${apos}
273 # By Another Author (3) and A U Thor (2)
274 # Via Another Committer
283 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
284 test_cmp expected actual
287 test_expect_success
'--log=5 with custom comment character' '
288 cat >expected <<-EOF &&
289 Merge branch ${apos}left${apos}
291 x By Another Author (3) and A U Thor (2)
292 x Via Another Committer
301 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
302 test_cmp expected actual
305 test_expect_success
'merge.log=0 disables shortlog' '
306 echo "Merge branch ${apos}left${apos}" >expected &&
307 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
308 test_cmp expected actual
311 test_expect_success
'--log=3 limits shortlog length' '
312 cat >expected <<-EOF &&
313 Merge branch ${apos}left${apos}
315 # By Another Author (3) and A U Thor (2)
316 # Via Another Committer
324 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
325 test_cmp expected actual
328 test_expect_success
'--log=5 shows all 5 commits' '
329 cat >expected <<-EOF &&
330 Merge branch ${apos}left${apos}
332 # By Another Author (3) and A U Thor (2)
333 # Via Another Committer
342 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
343 test_cmp expected actual
346 test_expect_success
'--no-log disables shortlog' '
347 echo "Merge branch ${apos}left${apos}" >expected &&
348 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
349 test_cmp expected actual
352 test_expect_success
'--log=0 disables shortlog' '
353 echo "Merge branch ${apos}left${apos}" >expected &&
354 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
355 test_cmp expected actual
358 test_expect_success
'fmt-merge-msg -m' '
359 echo "Sync with left" >expected &&
360 cat >expected.log <<-EOF &&
363 # By Another Author (3) and A U Thor (2)
364 # Via Another Committer
365 * ${apos}left${apos} of $(pwd):
373 test_unconfig merge.log &&
374 test_unconfig merge.summary &&
376 git fetch "$(pwd)" left &&
377 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
378 git fmt-merge-msg --log -m "Sync with left" \
379 <.git/FETCH_HEAD >actual.log &&
380 test_config merge.log true &&
381 git fmt-merge-msg -m "Sync with left" \
382 <.git/FETCH_HEAD >actual.log-config &&
383 git fmt-merge-msg --no-log -m "Sync with left" \
384 <.git/FETCH_HEAD >actual.nolog &&
386 test_cmp expected actual &&
387 test_cmp expected.log actual.log &&
388 test_cmp expected.log actual.log-config &&
389 test_cmp expected actual.nolog
392 test_expect_success
'setup: expected shortlog for two branches' '
394 Merge branches ${apos}left${apos} and ${apos}right${apos}
396 # By Another Author (3) and A U Thor (2)
397 # Via Another Committer
414 test_expect_success
'shortlog for two branches' '
415 test_config merge.log true &&
416 test_unconfig merge.summary &&
419 git fetch . left right &&
420 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
422 test_unconfig merge.log &&
423 test_config merge.summary true &&
426 git fetch . left right &&
427 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
429 test_config merge.log yes &&
430 test_unconfig merge.summary &&
433 git fetch . left right &&
434 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
436 test_unconfig merge.log &&
437 test_config merge.summary yes &&
440 git fetch . left right &&
441 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
443 test_cmp expected actual1 &&
444 test_cmp expected actual2 &&
445 test_cmp expected actual3 &&
446 test_cmp expected actual4
449 test_expect_success
'merge-msg -F' '
450 test_unconfig merge.log &&
451 test_config merge.summary yes &&
454 git fetch . left right &&
455 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
456 test_cmp expected actual
459 test_expect_success
'merge-msg -F in subdirectory' '
460 test_unconfig merge.log &&
461 test_config merge.summary yes &&
464 git fetch . left right &&
466 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
469 git fmt-merge-msg -F FETCH_HEAD >../actual
471 test_cmp expected actual
474 test_expect_success
'merge-msg with nothing to merge' '
475 test_unconfig merge.log &&
476 test_config merge.summary yes &&
480 git checkout -b unrelated &&
483 git fmt-merge-msg <.git/FETCH_HEAD >../actual
486 test_must_be_empty actual
489 test_expect_success
'merge-msg tag' '
490 cat >expected <<-EOF &&
491 Merge tag ${apos}tag-r3${apos}
493 * tag ${apos}tag-r3${apos}:
499 test_unconfig merge.log &&
500 test_config merge.summary yes &&
504 git fetch . tag tag-r3 &&
506 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
507 test_cmp expected actual
510 test_expect_success
'merge-msg two tags' '
511 cat >expected <<-EOF &&
512 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
514 * tag ${apos}tag-r3${apos}:
519 # By Another Author (3) and A U Thor (2)
520 # Via Another Committer
521 * tag ${apos}tag-l5${apos}:
529 test_unconfig merge.log &&
530 test_config merge.summary yes &&
534 git fetch . tag tag-r3 tag tag-l5 &&
536 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
537 test_cmp expected actual
540 test_expect_success
'merge-msg tag and branch' '
541 cat >expected <<-EOF &&
542 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
544 * tag ${apos}tag-r3${apos}:
549 # By Another Author (3) and A U Thor (2)
550 # Via Another Committer
559 test_unconfig merge.log &&
560 test_config merge.summary yes &&
564 git fetch . tag tag-r3 left &&
566 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
567 test_cmp expected actual
570 test_expect_success
'merge-msg lots of commits' '
573 Merge branch ${apos}long${apos}
582 i=$(($i-1)) || return 1
587 test_config merge.summary yes &&
593 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
594 test_cmp expected actual
597 test_expect_success
'merge-msg with "merging" an annotated tag' '
598 test_config merge.log true &&
600 git checkout main^0 &&
601 git commit --allow-empty -m "One step ahead" &&
602 git tag -a -m "An annotated one" annote HEAD &&
605 git fetch . annote &&
607 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
610 Merge tag '\''annote'\''
614 * tag '\''annote'\'':
618 test_cmp expected actual &&
620 test_when_finished "git reset --hard" &&
621 annote=$(git rev-parse annote) &&
622 git merge --no-commit --no-ff $annote &&
625 Merge tag '\''$annote'\''
629 * tag '\''$annote'\'':
633 test_cmp expected .git/MERGE_MSG
636 test_expect_success
'merge --into-name=<name>' '
637 test_when_finished "git checkout main" &&
638 git checkout -B side main &&
639 git commit --allow-empty -m "One step ahead" &&
641 git checkout --detach main &&
642 git merge --no-ff side &&
643 git show -s --format="%s" >full.0 &&
644 head -n1 full.0 >actual &&
645 # expect that HEAD is shown as-is
646 grep -e "Merge branch .side. into HEAD$" actual &&
648 git reset --hard main &&
649 git merge --no-ff --into-name=main side &&
650 git show -s --format="%s" >full.1 &&
651 head -n1 full.1 >actual &&
652 # expect that we pretend to be merging to main, that is suppressed
653 grep -e "Merge branch .side.$" actual &&
655 git checkout -b throwaway main &&
656 git merge --no-ff --into-name=main side &&
657 git show -s --format="%s" >full.2 &&
658 head -n1 full.2 >actual &&
659 # expect that we pretend to be merging to main, that is suppressed
660 grep -e "Merge branch .side.$" actual
663 test_expect_success
'merge.suppressDest configuration' '
664 test_when_finished "git checkout main" &&
665 git checkout -B side main &&
666 git commit --allow-empty -m "One step ahead" &&
670 git -c merge.suppressDest="" fmt-merge-msg <.git/FETCH_HEAD >full.1 &&
671 head -n1 full.1 >actual &&
672 grep -e "Merge branch .side. into main" actual &&
674 git -c merge.suppressDest="mast" fmt-merge-msg <.git/FETCH_HEAD >full.2 &&
675 head -n1 full.2 >actual &&
676 grep -e "Merge branch .side. into main$" actual &&
678 git -c merge.suppressDest="ma?*[rn]" fmt-merge-msg <.git/FETCH_HEAD >full.3 &&
679 head -n1 full.3 >actual &&
680 grep -e "Merge branch .side." actual &&
681 ! grep -e " into main$" actual &&
683 git checkout --detach HEAD &&
684 git -c merge.suppressDest="main" fmt-merge-msg <.git/FETCH_HEAD >full.4 &&
685 head -n1 full.4 >actual &&
686 grep -e "Merge branch .side. into HEAD$" actual &&
688 git -c merge.suppressDest="main" fmt-merge-msg \
689 --into-name=main <.git/FETCH_HEAD >full.5 &&
690 head -n1 full.5 >actual &&
691 grep -e "Merge branch .side." actual &&
692 ! grep -e " into main$" actual &&
693 ! grep -e " into HEAD$" actual