3 # Copyright (c) 2006, Junio C Hamano
6 test_description='fmt-merge-msg test'
9 . "$TEST_DIRECTORY/lib-gpg.sh"
11 test_expect_success setup '
15 git commit -m "Initial" &&
23 git commit -a -m "Second" &&
25 git checkout -b left &&
29 git commit -a -m "Common #1" &&
33 git commit -a -m "Common #2" &&
39 GIT_COMMITTER_NAME="Another Committer" \
40 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
44 GIT_COMMITTER_NAME="Another Committer" \
45 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
49 GIT_COMMITTER_NAME="Another Committer" \
50 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
58 git commit -a -m "Right #3" &&
63 git commit -a -m "Right #4" &&
67 git commit -a -m "Right #5" &&
69 git checkout -b long &&
70 test_commit_bulk --start=0 --message=%s --filename=one 30 &&
77 test_expect_success GPG 'set up a signed tag' '
78 git tag -s -m signed-tag-msg signed-good-tag left
81 test_expect_success 'message for merging local branch' '
82 echo "Merge branch ${apos}left${apos}" >expected &&
84 git checkout master &&
87 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
88 test_cmp expected actual
91 test_expect_success GPG 'message for merging local tag signed by good key' '
92 git checkout master &&
93 git fetch . signed-good-tag &&
94 git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
95 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
96 grep "^# gpg: Signature made" actual &&
97 grep "^# gpg: Good signature from" actual
100 test_expect_success GPG 'message for merging local tag signed by unknown key' '
101 git checkout master &&
102 git fetch . signed-good-tag &&
103 GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
104 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
105 grep "^# gpg: Signature made" actual &&
106 grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual
109 test_expect_success 'message for merging external branch' '
110 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
112 git checkout master &&
113 git fetch "$(pwd)" left &&
115 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
116 test_cmp expected actual
119 test_expect_success '[merge] summary/log configuration' '
120 cat >expected <<-EOF &&
121 Merge branch ${apos}left${apos}
123 # By Another Author (3) and A U Thor (2)
124 # Via Another Committer
133 test_config merge.log true &&
134 test_unconfig merge.summary &&
136 git checkout master &&
140 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
142 test_unconfig merge.log &&
143 test_config merge.summary true &&
145 git checkout master &&
149 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
151 test_cmp expected actual1 &&
152 test_cmp expected actual2
155 test_expect_success 'setup FETCH_HEAD' '
156 git checkout master &&
161 test_expect_success 'merge.log=3 limits shortlog length' '
162 cat >expected <<-EOF &&
163 Merge branch ${apos}left${apos}
165 # By Another Author (3) and A U Thor (2)
166 # Via Another Committer
174 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
175 test_cmp expected actual
178 test_expect_success 'merge.log=5 shows all 5 commits' '
179 cat >expected <<-EOF &&
180 Merge branch ${apos}left${apos}
182 # By Another Author (3) and A U Thor (2)
183 # Via Another Committer
192 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
193 test_cmp expected actual
196 test_expect_success '--log=5 with custom comment character' '
197 cat >expected <<-EOF &&
198 Merge branch ${apos}left${apos}
200 x By Another Author (3) and A U Thor (2)
201 x Via Another Committer
210 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
211 test_cmp expected actual
214 test_expect_success 'merge.log=0 disables shortlog' '
215 echo "Merge branch ${apos}left${apos}" >expected &&
216 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
217 test_cmp expected actual
220 test_expect_success '--log=3 limits shortlog length' '
221 cat >expected <<-EOF &&
222 Merge branch ${apos}left${apos}
224 # By Another Author (3) and A U Thor (2)
225 # Via Another Committer
233 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
234 test_cmp expected actual
237 test_expect_success '--log=5 shows all 5 commits' '
238 cat >expected <<-EOF &&
239 Merge branch ${apos}left${apos}
241 # By Another Author (3) and A U Thor (2)
242 # Via Another Committer
251 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
252 test_cmp expected actual
255 test_expect_success '--no-log disables shortlog' '
256 echo "Merge branch ${apos}left${apos}" >expected &&
257 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
258 test_cmp expected actual
261 test_expect_success '--log=0 disables shortlog' '
262 echo "Merge branch ${apos}left${apos}" >expected &&
263 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
264 test_cmp expected actual
267 test_expect_success 'fmt-merge-msg -m' '
268 echo "Sync with left" >expected &&
269 cat >expected.log <<-EOF &&
272 # By Another Author (3) and A U Thor (2)
273 # Via Another Committer
274 * ${apos}left${apos} of $(pwd):
282 test_unconfig merge.log &&
283 test_unconfig merge.summary &&
284 git checkout master &&
285 git fetch "$(pwd)" left &&
286 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
287 git fmt-merge-msg --log -m "Sync with left" \
288 <.git/FETCH_HEAD >actual.log &&
289 test_config merge.log true &&
290 git fmt-merge-msg -m "Sync with left" \
291 <.git/FETCH_HEAD >actual.log-config &&
292 git fmt-merge-msg --no-log -m "Sync with left" \
293 <.git/FETCH_HEAD >actual.nolog &&
295 test_cmp expected actual &&
296 test_cmp expected.log actual.log &&
297 test_cmp expected.log actual.log-config &&
298 test_cmp expected actual.nolog
301 test_expect_success 'setup: expected shortlog for two branches' '
303 Merge branches ${apos}left${apos} and ${apos}right${apos}
305 # By Another Author (3) and A U Thor (2)
306 # Via Another Committer
323 test_expect_success 'shortlog for two branches' '
324 test_config merge.log true &&
325 test_unconfig merge.summary &&
326 git checkout master &&
328 git fetch . left right &&
329 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
331 test_unconfig merge.log &&
332 test_config merge.summary true &&
333 git checkout master &&
335 git fetch . left right &&
336 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
338 test_config merge.log yes &&
339 test_unconfig merge.summary &&
340 git checkout master &&
342 git fetch . left right &&
343 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
345 test_unconfig merge.log &&
346 test_config merge.summary yes &&
347 git checkout master &&
349 git fetch . left right &&
350 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
352 test_cmp expected actual1 &&
353 test_cmp expected actual2 &&
354 test_cmp expected actual3 &&
355 test_cmp expected actual4
358 test_expect_success 'merge-msg -F' '
359 test_unconfig merge.log &&
360 test_config merge.summary yes &&
361 git checkout master &&
363 git fetch . left right &&
364 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
365 test_cmp expected actual
368 test_expect_success 'merge-msg -F in subdirectory' '
369 test_unconfig merge.log &&
370 test_config merge.summary yes &&
371 git checkout master &&
373 git fetch . left right &&
375 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
378 git fmt-merge-msg -F FETCH_HEAD >../actual
380 test_cmp expected actual
383 test_expect_success 'merge-msg with nothing to merge' '
384 test_unconfig merge.log &&
385 test_config merge.summary yes &&
389 git checkout -b unrelated &&
392 git fmt-merge-msg <.git/FETCH_HEAD >../actual
395 test_must_be_empty actual
398 test_expect_success 'merge-msg tag' '
399 cat >expected <<-EOF &&
400 Merge tag ${apos}tag-r3${apos}
402 * tag ${apos}tag-r3${apos}:
408 test_unconfig merge.log &&
409 test_config merge.summary yes &&
411 git checkout master &&
413 git fetch . tag tag-r3 &&
415 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
416 test_cmp expected actual
419 test_expect_success 'merge-msg two tags' '
420 cat >expected <<-EOF &&
421 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
423 * tag ${apos}tag-r3${apos}:
428 # By Another Author (3) and A U Thor (2)
429 # Via Another Committer
430 * tag ${apos}tag-l5${apos}:
438 test_unconfig merge.log &&
439 test_config merge.summary yes &&
441 git checkout master &&
443 git fetch . tag tag-r3 tag tag-l5 &&
445 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
446 test_cmp expected actual
449 test_expect_success 'merge-msg tag and branch' '
450 cat >expected <<-EOF &&
451 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
453 * tag ${apos}tag-r3${apos}:
458 # By Another Author (3) and A U Thor (2)
459 # Via Another Committer
468 test_unconfig merge.log &&
469 test_config merge.summary yes &&
471 git checkout master &&
473 git fetch . tag tag-r3 left &&
475 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
476 test_cmp expected actual
479 test_expect_success 'merge-msg lots of commits' '
482 Merge branch ${apos}long${apos}
496 test_config merge.summary yes &&
498 git checkout master &&
502 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
503 test_cmp expected actual
506 test_expect_success 'merge-msg with "merging" an annotated tag' '
507 test_config merge.log true &&
509 git checkout master^0 &&
510 git commit --allow-empty -m "One step ahead" &&
511 git tag -a -m "An annotated one" annote HEAD &&
513 git checkout master &&
514 git fetch . annote &&
516 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
519 Merge tag '\''annote'\''
523 * tag '\''annote'\'':
527 test_cmp expected actual &&
529 test_when_finished "git reset --hard" &&
530 annote=$(git rev-parse annote) &&
531 git merge --no-commit --no-ff $annote &&
534 Merge tag '\''$annote'\''
538 * tag '\''$annote'\'':
542 test_cmp expected .git/MERGE_MSG
545 test_expect_success 'merge.suppressDest configuration' '
546 git checkout -B side master &&
547 git commit --allow-empty -m "One step ahead" &&
548 git checkout master &&
551 git -c merge.suppressDest="" fmt-merge-msg <.git/FETCH_HEAD >full.1 &&
552 head -n1 full.1 >actual &&
553 grep -e "Merge branch .side. into master" actual &&
555 git -c merge.suppressDest="mast" fmt-merge-msg <.git/FETCH_HEAD >full.2 &&
556 head -n1 full.2 >actual &&
557 grep -e "Merge branch .side. into master$" actual &&
559 git -c merge.suppressDest="ma??er" fmt-merge-msg <.git/FETCH_HEAD >full.3 &&
560 head -n1 full.3 >actual &&
561 grep -e "Merge branch .side." actual &&
562 ! grep -e " into master$" actual