3 # Copyright (c) 2006, Junio C Hamano
6 test_description='fmt-merge-msg test'
10 test_expect_success setup '
14 git commit -m "Initial" &&
22 git commit -a -m "Second" &&
24 git checkout -b left &&
28 git commit -a -m "Common #1" &&
32 git commit -a -m "Common #2" &&
38 GIT_COMMITTER_NAME="Another Committer" \
39 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
43 GIT_COMMITTER_NAME="Another Committer" \
44 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
48 GIT_COMMITTER_NAME="Another Committer" \
49 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
57 git commit -a -m "Right #3" &&
62 git commit -a -m "Right #4" &&
66 git commit -a -m "Right #5" &&
68 git checkout -b long &&
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 'message for merging external branch' '
92 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
94 git checkout master &&
95 git fetch "$(pwd)" left &&
97 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
98 test_cmp expected actual
101 test_expect_success '[merge] summary/log configuration' '
102 cat >expected <<-EOF &&
103 Merge branch ${apos}left${apos}
105 # By Another Author (3) and A U Thor (2)
106 # Via Another Committer
115 test_config merge.log true &&
116 test_unconfig merge.summary &&
118 git checkout master &&
122 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
124 test_unconfig merge.log &&
125 test_config merge.summary true &&
127 git checkout master &&
131 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
133 test_cmp expected actual1 &&
134 test_cmp expected actual2
137 test_expect_success 'setup FETCH_HEAD' '
138 git checkout master &&
143 test_expect_success 'merge.log=3 limits shortlog length' '
144 cat >expected <<-EOF &&
145 Merge branch ${apos}left${apos}
147 # By Another Author (3) and A U Thor (2)
148 # Via Another Committer
156 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
157 test_cmp expected actual
160 test_expect_success 'merge.log=5 shows all 5 commits' '
161 cat >expected <<-EOF &&
162 Merge branch ${apos}left${apos}
164 # By Another Author (3) and A U Thor (2)
165 # Via Another Committer
174 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
175 test_cmp expected actual
178 test_expect_success '--log=5 with custom comment character' '
179 cat >expected <<-EOF &&
180 Merge branch ${apos}left${apos}
182 x By Another Author (3) and A U Thor (2)
183 x Via Another Committer
192 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
193 test_cmp expected actual
196 test_expect_success 'merge.log=0 disables shortlog' '
197 echo "Merge branch ${apos}left${apos}" >expected &&
198 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
199 test_cmp expected actual
202 test_expect_success '--log=3 limits shortlog length' '
203 cat >expected <<-EOF &&
204 Merge branch ${apos}left${apos}
206 # By Another Author (3) and A U Thor (2)
207 # Via Another Committer
215 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
216 test_cmp expected actual
219 test_expect_success '--log=5 shows all 5 commits' '
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 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
234 test_cmp expected actual
237 test_expect_success '--no-log disables shortlog' '
238 echo "Merge branch ${apos}left${apos}" >expected &&
239 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
240 test_cmp expected actual
243 test_expect_success '--log=0 disables shortlog' '
244 echo "Merge branch ${apos}left${apos}" >expected &&
245 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
246 test_cmp expected actual
249 test_expect_success 'fmt-merge-msg -m' '
250 echo "Sync with left" >expected &&
251 cat >expected.log <<-EOF &&
254 # By Another Author (3) and A U Thor (2)
255 # Via Another Committer
256 * ${apos}left${apos} of $(pwd):
264 test_unconfig merge.log &&
265 test_unconfig merge.summary &&
266 git checkout master &&
267 git fetch "$(pwd)" left &&
268 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
269 git fmt-merge-msg --log -m "Sync with left" \
270 <.git/FETCH_HEAD >actual.log &&
271 test_config merge.log true &&
272 git fmt-merge-msg -m "Sync with left" \
273 <.git/FETCH_HEAD >actual.log-config &&
274 git fmt-merge-msg --no-log -m "Sync with left" \
275 <.git/FETCH_HEAD >actual.nolog &&
277 test_cmp expected actual &&
278 test_cmp expected.log actual.log &&
279 test_cmp expected.log actual.log-config &&
280 test_cmp expected actual.nolog
283 test_expect_success 'setup: expected shortlog for two branches' '
285 Merge branches ${apos}left${apos} and ${apos}right${apos}
287 # By Another Author (3) and A U Thor (2)
288 # Via Another Committer
305 test_expect_success 'shortlog for two branches' '
306 test_config merge.log true &&
307 test_unconfig merge.summary &&
308 git checkout master &&
310 git fetch . left right &&
311 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
313 test_unconfig merge.log &&
314 test_config merge.summary true &&
315 git checkout master &&
317 git fetch . left right &&
318 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
320 test_config merge.log yes &&
321 test_unconfig merge.summary &&
322 git checkout master &&
324 git fetch . left right &&
325 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
327 test_unconfig merge.log &&
328 test_config merge.summary yes &&
329 git checkout master &&
331 git fetch . left right &&
332 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
334 test_cmp expected actual1 &&
335 test_cmp expected actual2 &&
336 test_cmp expected actual3 &&
337 test_cmp expected actual4
340 test_expect_success 'merge-msg -F' '
341 test_unconfig merge.log &&
342 test_config merge.summary yes &&
343 git checkout master &&
345 git fetch . left right &&
346 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
347 test_cmp expected actual
350 test_expect_success 'merge-msg -F in subdirectory' '
351 test_unconfig merge.log &&
352 test_config merge.summary yes &&
353 git checkout master &&
355 git fetch . left right &&
357 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
360 git fmt-merge-msg -F FETCH_HEAD >../actual
362 test_cmp expected actual
365 test_expect_success 'merge-msg with nothing to merge' '
366 test_unconfig merge.log &&
367 test_config merge.summary yes &&
371 git checkout -b unrelated &&
374 git fmt-merge-msg <.git/FETCH_HEAD >../actual
377 test_must_be_empty actual
380 test_expect_success 'merge-msg tag' '
381 cat >expected <<-EOF &&
382 Merge tag ${apos}tag-r3${apos}
384 * tag ${apos}tag-r3${apos}:
390 test_unconfig merge.log &&
391 test_config merge.summary yes &&
393 git checkout master &&
395 git fetch . tag tag-r3 &&
397 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
398 test_cmp expected actual
401 test_expect_success 'merge-msg two tags' '
402 cat >expected <<-EOF &&
403 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
405 * tag ${apos}tag-r3${apos}:
410 # By Another Author (3) and A U Thor (2)
411 # Via Another Committer
412 * tag ${apos}tag-l5${apos}:
420 test_unconfig merge.log &&
421 test_config merge.summary yes &&
423 git checkout master &&
425 git fetch . tag tag-r3 tag tag-l5 &&
427 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
428 test_cmp expected actual
431 test_expect_success 'merge-msg tag and branch' '
432 cat >expected <<-EOF &&
433 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
435 * tag ${apos}tag-r3${apos}:
440 # By Another Author (3) and A U Thor (2)
441 # Via Another Committer
450 test_unconfig merge.log &&
451 test_config merge.summary yes &&
453 git checkout master &&
455 git fetch . tag tag-r3 left &&
457 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
458 test_cmp expected actual
461 test_expect_success 'merge-msg lots of commits' '
464 Merge branch ${apos}long${apos}
478 test_config merge.summary yes &&
480 git checkout master &&
484 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
485 test_cmp expected actual
488 test_expect_success 'merge-msg with "merging" an annotated tag' '
489 test_config merge.log true &&
491 git checkout master^0 &&
492 git commit --allow-empty -m "One step ahead" &&
493 git tag -a -m "An annotated one" annote HEAD &&
495 git checkout master &&
496 git fetch . annote &&
498 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
501 Merge tag '\''annote'\''
505 * tag '\''annote'\'':
509 test_cmp expected actual &&
511 test_when_finished "git reset --hard" &&
512 annote=$(git rev-parse annote) &&
513 git merge --no-commit --no-ff $annote &&
516 Merge tag '\''$annote'\''
520 * tag '\''$annote'\'':
524 test_cmp expected .git/MERGE_MSG