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
'message for merging local branch' '
85 echo "Merge branch ${apos}left${apos}" >expected &&
90 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
91 test_cmp expected actual
94 test_expect_success GPG
'message for merging local tag signed by good key' '
96 git fetch . signed-good-tag &&
97 git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
98 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
99 grep "^# gpg: Signature made" actual &&
100 grep "^# gpg: Good signature from" actual
103 test_expect_success GPG
'message for merging local tag signed by unknown key' '
105 git fetch . signed-good-tag &&
106 GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
107 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
108 grep "^# gpg: Signature made" actual &&
109 grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual
112 test_expect_success
'message for merging external branch' '
113 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
116 git fetch "$(pwd)" left &&
118 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
119 test_cmp expected actual
122 test_expect_success
'[merge] summary/log configuration' '
123 cat >expected <<-EOF &&
124 Merge branch ${apos}left${apos}
126 # By Another Author (3) and A U Thor (2)
127 # Via Another Committer
136 test_config merge.log true &&
137 test_unconfig merge.summary &&
143 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
145 test_unconfig merge.log &&
146 test_config merge.summary true &&
152 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
154 test_cmp expected actual1 &&
155 test_cmp expected actual2
158 test_expect_success
'setup FETCH_HEAD' '
164 test_expect_success
'merge.log=3 limits shortlog length' '
165 cat >expected <<-EOF &&
166 Merge branch ${apos}left${apos}
168 # By Another Author (3) and A U Thor (2)
169 # Via Another Committer
177 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
178 test_cmp expected actual
181 test_expect_success
'merge.log=5 shows all 5 commits' '
182 cat >expected <<-EOF &&
183 Merge branch ${apos}left${apos}
185 # By Another Author (3) and A U Thor (2)
186 # Via Another Committer
195 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
196 test_cmp expected actual
199 test_expect_success
'--log=5 with custom comment character' '
200 cat >expected <<-EOF &&
201 Merge branch ${apos}left${apos}
203 x By Another Author (3) and A U Thor (2)
204 x Via Another Committer
213 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
214 test_cmp expected actual
217 test_expect_success
'merge.log=0 disables shortlog' '
218 echo "Merge branch ${apos}left${apos}" >expected &&
219 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
220 test_cmp expected actual
223 test_expect_success
'--log=3 limits shortlog length' '
224 cat >expected <<-EOF &&
225 Merge branch ${apos}left${apos}
227 # By Another Author (3) and A U Thor (2)
228 # Via Another Committer
236 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
237 test_cmp expected actual
240 test_expect_success
'--log=5 shows all 5 commits' '
241 cat >expected <<-EOF &&
242 Merge branch ${apos}left${apos}
244 # By Another Author (3) and A U Thor (2)
245 # Via Another Committer
254 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
255 test_cmp expected actual
258 test_expect_success
'--no-log disables shortlog' '
259 echo "Merge branch ${apos}left${apos}" >expected &&
260 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
261 test_cmp expected actual
264 test_expect_success
'--log=0 disables shortlog' '
265 echo "Merge branch ${apos}left${apos}" >expected &&
266 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
267 test_cmp expected actual
270 test_expect_success
'fmt-merge-msg -m' '
271 echo "Sync with left" >expected &&
272 cat >expected.log <<-EOF &&
275 # By Another Author (3) and A U Thor (2)
276 # Via Another Committer
277 * ${apos}left${apos} of $(pwd):
285 test_unconfig merge.log &&
286 test_unconfig merge.summary &&
288 git fetch "$(pwd)" left &&
289 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
290 git fmt-merge-msg --log -m "Sync with left" \
291 <.git/FETCH_HEAD >actual.log &&
292 test_config merge.log true &&
293 git fmt-merge-msg -m "Sync with left" \
294 <.git/FETCH_HEAD >actual.log-config &&
295 git fmt-merge-msg --no-log -m "Sync with left" \
296 <.git/FETCH_HEAD >actual.nolog &&
298 test_cmp expected actual &&
299 test_cmp expected.log actual.log &&
300 test_cmp expected.log actual.log-config &&
301 test_cmp expected actual.nolog
304 test_expect_success
'setup: expected shortlog for two branches' '
306 Merge branches ${apos}left${apos} and ${apos}right${apos}
308 # By Another Author (3) and A U Thor (2)
309 # Via Another Committer
326 test_expect_success
'shortlog for two branches' '
327 test_config merge.log true &&
328 test_unconfig merge.summary &&
331 git fetch . left right &&
332 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
334 test_unconfig merge.log &&
335 test_config merge.summary true &&
338 git fetch . left right &&
339 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
341 test_config merge.log yes &&
342 test_unconfig merge.summary &&
345 git fetch . left right &&
346 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
348 test_unconfig merge.log &&
349 test_config merge.summary yes &&
352 git fetch . left right &&
353 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
355 test_cmp expected actual1 &&
356 test_cmp expected actual2 &&
357 test_cmp expected actual3 &&
358 test_cmp expected actual4
361 test_expect_success
'merge-msg -F' '
362 test_unconfig merge.log &&
363 test_config merge.summary yes &&
366 git fetch . left right &&
367 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
368 test_cmp expected actual
371 test_expect_success
'merge-msg -F in subdirectory' '
372 test_unconfig merge.log &&
373 test_config merge.summary yes &&
376 git fetch . left right &&
378 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
381 git fmt-merge-msg -F FETCH_HEAD >../actual
383 test_cmp expected actual
386 test_expect_success
'merge-msg with nothing to merge' '
387 test_unconfig merge.log &&
388 test_config merge.summary yes &&
392 git checkout -b unrelated &&
395 git fmt-merge-msg <.git/FETCH_HEAD >../actual
398 test_must_be_empty actual
401 test_expect_success
'merge-msg tag' '
402 cat >expected <<-EOF &&
403 Merge tag ${apos}tag-r3${apos}
405 * tag ${apos}tag-r3${apos}:
411 test_unconfig merge.log &&
412 test_config merge.summary yes &&
416 git fetch . tag tag-r3 &&
418 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
419 test_cmp expected actual
422 test_expect_success
'merge-msg two tags' '
423 cat >expected <<-EOF &&
424 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
426 * tag ${apos}tag-r3${apos}:
431 # By Another Author (3) and A U Thor (2)
432 # Via Another Committer
433 * tag ${apos}tag-l5${apos}:
441 test_unconfig merge.log &&
442 test_config merge.summary yes &&
446 git fetch . tag tag-r3 tag tag-l5 &&
448 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
449 test_cmp expected actual
452 test_expect_success
'merge-msg tag and branch' '
453 cat >expected <<-EOF &&
454 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
456 * tag ${apos}tag-r3${apos}:
461 # By Another Author (3) and A U Thor (2)
462 # Via Another Committer
471 test_unconfig merge.log &&
472 test_config merge.summary yes &&
476 git fetch . tag tag-r3 left &&
478 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
479 test_cmp expected actual
482 test_expect_success
'merge-msg lots of commits' '
485 Merge branch ${apos}long${apos}
499 test_config merge.summary yes &&
505 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
506 test_cmp expected actual
509 test_expect_success
'merge-msg with "merging" an annotated tag' '
510 test_config merge.log true &&
512 git checkout main^0 &&
513 git commit --allow-empty -m "One step ahead" &&
514 git tag -a -m "An annotated one" annote HEAD &&
517 git fetch . annote &&
519 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
522 Merge tag '\''annote'\''
526 * tag '\''annote'\'':
530 test_cmp expected actual &&
532 test_when_finished "git reset --hard" &&
533 annote=$(git rev-parse annote) &&
534 git merge --no-commit --no-ff $annote &&
537 Merge tag '\''$annote'\''
541 * tag '\''$annote'\'':
545 test_cmp expected .git/MERGE_MSG
548 test_expect_success
'merge.suppressDest configuration' '
549 git checkout -B side main &&
550 git commit --allow-empty -m "One step ahead" &&
554 git -c merge.suppressDest="" fmt-merge-msg <.git/FETCH_HEAD >full.1 &&
555 head -n1 full.1 >actual &&
556 grep -e "Merge branch .side. into main" actual &&
558 git -c merge.suppressDest="mast" fmt-merge-msg <.git/FETCH_HEAD >full.2 &&
559 head -n1 full.2 >actual &&
560 grep -e "Merge branch .side. into main$" actual &&
562 git -c merge.suppressDest="ma?*[rn]" fmt-merge-msg <.git/FETCH_HEAD >full.3 &&
563 head -n1 full.3 >actual &&
564 grep -e "Merge branch .side." actual &&
565 ! grep -e " into main$" actual