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
'message for merging local branch' '
95 echo "Merge branch ${apos}left${apos}" >expected &&
100 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
101 test_cmp expected actual
104 test_expect_success GPG
'message for merging local tag signed by good key' '
106 git fetch . signed-good-tag &&
107 git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
108 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
109 grep "^# gpg: Signature made" actual &&
110 grep "^# gpg: Good signature from" actual
113 test_expect_success GPG
'message for merging local tag signed by unknown key' '
115 git fetch . signed-good-tag &&
116 GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
117 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
118 grep "^# gpg: Signature made" actual &&
119 grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual
122 test_expect_success GPGSSH
'message for merging local tag signed by good ssh key' '
123 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
125 git fetch . signed-good-ssh-tag &&
126 git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
127 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
128 ! grep "${GPGSSH_BAD_SIGNATURE}" actual
131 test_expect_success GPGSSH
'message for merging local tag signed by unknown ssh key' '
132 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
134 git fetch . signed-untrusted-ssh-tag &&
135 git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
136 grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual &&
137 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
138 grep "${GPGSSH_KEY_NOT_TRUSTED}" actual
140 test_expect_success
'message for merging external branch' '
141 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
144 git fetch "$(pwd)" left &&
146 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
147 test_cmp expected actual
150 test_expect_success
'[merge] summary/log configuration' '
151 cat >expected <<-EOF &&
152 Merge branch ${apos}left${apos}
154 # By Another Author (3) and A U Thor (2)
155 # Via Another Committer
164 test_config merge.log true &&
165 test_unconfig merge.summary &&
171 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
173 test_unconfig merge.log &&
174 test_config merge.summary true &&
180 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
182 test_cmp expected actual1 &&
183 test_cmp expected actual2
186 test_expect_success
'setup FETCH_HEAD' '
192 test_expect_success
'merge.log=3 limits shortlog length' '
193 cat >expected <<-EOF &&
194 Merge branch ${apos}left${apos}
196 # By Another Author (3) and A U Thor (2)
197 # Via Another Committer
205 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
206 test_cmp expected actual
209 test_expect_success
'merge.log=5 shows all 5 commits' '
210 cat >expected <<-EOF &&
211 Merge branch ${apos}left${apos}
213 # By Another Author (3) and A U Thor (2)
214 # Via Another Committer
223 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
224 test_cmp expected actual
227 test_expect_success
'--log=5 with custom comment character' '
228 cat >expected <<-EOF &&
229 Merge branch ${apos}left${apos}
231 x By Another Author (3) and A U Thor (2)
232 x Via Another Committer
241 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
242 test_cmp expected actual
245 test_expect_success
'merge.log=0 disables shortlog' '
246 echo "Merge branch ${apos}left${apos}" >expected &&
247 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
248 test_cmp expected actual
251 test_expect_success
'--log=3 limits shortlog length' '
252 cat >expected <<-EOF &&
253 Merge branch ${apos}left${apos}
255 # By Another Author (3) and A U Thor (2)
256 # Via Another Committer
264 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
265 test_cmp expected actual
268 test_expect_success
'--log=5 shows all 5 commits' '
269 cat >expected <<-EOF &&
270 Merge branch ${apos}left${apos}
272 # By Another Author (3) and A U Thor (2)
273 # Via Another Committer
282 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
283 test_cmp expected actual
286 test_expect_success
'--no-log disables shortlog' '
287 echo "Merge branch ${apos}left${apos}" >expected &&
288 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
289 test_cmp expected actual
292 test_expect_success
'--log=0 disables shortlog' '
293 echo "Merge branch ${apos}left${apos}" >expected &&
294 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
295 test_cmp expected actual
298 test_expect_success
'fmt-merge-msg -m' '
299 echo "Sync with left" >expected &&
300 cat >expected.log <<-EOF &&
303 # By Another Author (3) and A U Thor (2)
304 # Via Another Committer
305 * ${apos}left${apos} of $(pwd):
313 test_unconfig merge.log &&
314 test_unconfig merge.summary &&
316 git fetch "$(pwd)" left &&
317 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
318 git fmt-merge-msg --log -m "Sync with left" \
319 <.git/FETCH_HEAD >actual.log &&
320 test_config merge.log true &&
321 git fmt-merge-msg -m "Sync with left" \
322 <.git/FETCH_HEAD >actual.log-config &&
323 git fmt-merge-msg --no-log -m "Sync with left" \
324 <.git/FETCH_HEAD >actual.nolog &&
326 test_cmp expected actual &&
327 test_cmp expected.log actual.log &&
328 test_cmp expected.log actual.log-config &&
329 test_cmp expected actual.nolog
332 test_expect_success
'setup: expected shortlog for two branches' '
334 Merge branches ${apos}left${apos} and ${apos}right${apos}
336 # By Another Author (3) and A U Thor (2)
337 # Via Another Committer
354 test_expect_success
'shortlog for two branches' '
355 test_config merge.log true &&
356 test_unconfig merge.summary &&
359 git fetch . left right &&
360 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
362 test_unconfig merge.log &&
363 test_config merge.summary true &&
366 git fetch . left right &&
367 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
369 test_config merge.log yes &&
370 test_unconfig merge.summary &&
373 git fetch . left right &&
374 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
376 test_unconfig merge.log &&
377 test_config merge.summary yes &&
380 git fetch . left right &&
381 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
383 test_cmp expected actual1 &&
384 test_cmp expected actual2 &&
385 test_cmp expected actual3 &&
386 test_cmp expected actual4
389 test_expect_success
'merge-msg -F' '
390 test_unconfig merge.log &&
391 test_config merge.summary yes &&
394 git fetch . left right &&
395 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
396 test_cmp expected actual
399 test_expect_success
'merge-msg -F in subdirectory' '
400 test_unconfig merge.log &&
401 test_config merge.summary yes &&
404 git fetch . left right &&
406 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
409 git fmt-merge-msg -F FETCH_HEAD >../actual
411 test_cmp expected actual
414 test_expect_success
'merge-msg with nothing to merge' '
415 test_unconfig merge.log &&
416 test_config merge.summary yes &&
420 git checkout -b unrelated &&
423 git fmt-merge-msg <.git/FETCH_HEAD >../actual
426 test_must_be_empty actual
429 test_expect_success
'merge-msg tag' '
430 cat >expected <<-EOF &&
431 Merge tag ${apos}tag-r3${apos}
433 * tag ${apos}tag-r3${apos}:
439 test_unconfig merge.log &&
440 test_config merge.summary yes &&
444 git fetch . tag tag-r3 &&
446 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
447 test_cmp expected actual
450 test_expect_success
'merge-msg two tags' '
451 cat >expected <<-EOF &&
452 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
454 * tag ${apos}tag-r3${apos}:
459 # By Another Author (3) and A U Thor (2)
460 # Via Another Committer
461 * tag ${apos}tag-l5${apos}:
469 test_unconfig merge.log &&
470 test_config merge.summary yes &&
474 git fetch . tag tag-r3 tag tag-l5 &&
476 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
477 test_cmp expected actual
480 test_expect_success
'merge-msg tag and branch' '
481 cat >expected <<-EOF &&
482 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
484 * tag ${apos}tag-r3${apos}:
489 # By Another Author (3) and A U Thor (2)
490 # Via Another Committer
499 test_unconfig merge.log &&
500 test_config merge.summary yes &&
504 git fetch . tag tag-r3 left &&
506 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
507 test_cmp expected actual
510 test_expect_success
'merge-msg lots of commits' '
513 Merge branch ${apos}long${apos}
527 test_config merge.summary yes &&
533 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
534 test_cmp expected actual
537 test_expect_success
'merge-msg with "merging" an annotated tag' '
538 test_config merge.log true &&
540 git checkout main^0 &&
541 git commit --allow-empty -m "One step ahead" &&
542 git tag -a -m "An annotated one" annote HEAD &&
545 git fetch . annote &&
547 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
550 Merge tag '\''annote'\''
554 * tag '\''annote'\'':
558 test_cmp expected actual &&
560 test_when_finished "git reset --hard" &&
561 annote=$(git rev-parse annote) &&
562 git merge --no-commit --no-ff $annote &&
565 Merge tag '\''$annote'\''
569 * tag '\''$annote'\'':
573 test_cmp expected .git/MERGE_MSG
576 test_expect_success
'merge.suppressDest configuration' '
577 git checkout -B side main &&
578 git commit --allow-empty -m "One step ahead" &&
582 git -c merge.suppressDest="" fmt-merge-msg <.git/FETCH_HEAD >full.1 &&
583 head -n1 full.1 >actual &&
584 grep -e "Merge branch .side. into main" actual &&
586 git -c merge.suppressDest="mast" fmt-merge-msg <.git/FETCH_HEAD >full.2 &&
587 head -n1 full.2 >actual &&
588 grep -e "Merge branch .side. into main$" actual &&
590 git -c merge.suppressDest="ma?*[rn]" fmt-merge-msg <.git/FETCH_HEAD >full.3 &&
591 head -n1 full.3 >actual &&
592 grep -e "Merge branch .side." actual &&
593 ! grep -e " into main$" actual