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 &&
69 test_commit_bulk --start=0 --message=%s --filename=one 30 &&
76 test_expect_success 'message for merging local branch' '
77 echo "Merge branch ${apos}left${apos}" >expected &&
79 git checkout master &&
82 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
83 test_cmp expected actual
86 test_expect_success 'message for merging external branch' '
87 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
89 git checkout master &&
90 git fetch "$(pwd)" left &&
92 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
93 test_cmp expected actual
96 test_expect_success '[merge] summary/log configuration' '
97 cat >expected <<-EOF &&
98 Merge branch ${apos}left${apos}
100 # By Another Author (3) and A U Thor (2)
101 # Via Another Committer
110 test_config merge.log true &&
111 test_unconfig merge.summary &&
113 git checkout master &&
117 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
119 test_unconfig merge.log &&
120 test_config merge.summary true &&
122 git checkout master &&
126 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
128 test_cmp expected actual1 &&
129 test_cmp expected actual2
132 test_expect_success 'setup FETCH_HEAD' '
133 git checkout master &&
138 test_expect_success 'merge.log=3 limits shortlog length' '
139 cat >expected <<-EOF &&
140 Merge branch ${apos}left${apos}
142 # By Another Author (3) and A U Thor (2)
143 # Via Another Committer
151 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
152 test_cmp expected actual
155 test_expect_success 'merge.log=5 shows all 5 commits' '
156 cat >expected <<-EOF &&
157 Merge branch ${apos}left${apos}
159 # By Another Author (3) and A U Thor (2)
160 # Via Another Committer
169 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
170 test_cmp expected actual
173 test_expect_success '--log=5 with custom comment character' '
174 cat >expected <<-EOF &&
175 Merge branch ${apos}left${apos}
177 x By Another Author (3) and A U Thor (2)
178 x Via Another Committer
187 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
188 test_cmp expected actual
191 test_expect_success 'merge.log=0 disables shortlog' '
192 echo "Merge branch ${apos}left${apos}" >expected &&
193 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
194 test_cmp expected actual
197 test_expect_success '--log=3 limits shortlog length' '
198 cat >expected <<-EOF &&
199 Merge branch ${apos}left${apos}
201 # By Another Author (3) and A U Thor (2)
202 # Via Another Committer
210 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
211 test_cmp expected actual
214 test_expect_success '--log=5 shows all 5 commits' '
215 cat >expected <<-EOF &&
216 Merge branch ${apos}left${apos}
218 # By Another Author (3) and A U Thor (2)
219 # Via Another Committer
228 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
229 test_cmp expected actual
232 test_expect_success '--no-log disables shortlog' '
233 echo "Merge branch ${apos}left${apos}" >expected &&
234 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
235 test_cmp expected actual
238 test_expect_success '--log=0 disables shortlog' '
239 echo "Merge branch ${apos}left${apos}" >expected &&
240 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
241 test_cmp expected actual
244 test_expect_success 'fmt-merge-msg -m' '
245 echo "Sync with left" >expected &&
246 cat >expected.log <<-EOF &&
249 # By Another Author (3) and A U Thor (2)
250 # Via Another Committer
251 * ${apos}left${apos} of $(pwd):
259 test_unconfig merge.log &&
260 test_unconfig merge.summary &&
261 git checkout master &&
262 git fetch "$(pwd)" left &&
263 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
264 git fmt-merge-msg --log -m "Sync with left" \
265 <.git/FETCH_HEAD >actual.log &&
266 test_config merge.log true &&
267 git fmt-merge-msg -m "Sync with left" \
268 <.git/FETCH_HEAD >actual.log-config &&
269 git fmt-merge-msg --no-log -m "Sync with left" \
270 <.git/FETCH_HEAD >actual.nolog &&
272 test_cmp expected actual &&
273 test_cmp expected.log actual.log &&
274 test_cmp expected.log actual.log-config &&
275 test_cmp expected actual.nolog
278 test_expect_success 'setup: expected shortlog for two branches' '
280 Merge branches ${apos}left${apos} and ${apos}right${apos}
282 # By Another Author (3) and A U Thor (2)
283 # Via Another Committer
300 test_expect_success 'shortlog for two branches' '
301 test_config merge.log true &&
302 test_unconfig merge.summary &&
303 git checkout master &&
305 git fetch . left right &&
306 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
308 test_unconfig merge.log &&
309 test_config merge.summary true &&
310 git checkout master &&
312 git fetch . left right &&
313 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
315 test_config merge.log yes &&
316 test_unconfig merge.summary &&
317 git checkout master &&
319 git fetch . left right &&
320 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
322 test_unconfig merge.log &&
323 test_config merge.summary yes &&
324 git checkout master &&
326 git fetch . left right &&
327 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
329 test_cmp expected actual1 &&
330 test_cmp expected actual2 &&
331 test_cmp expected actual3 &&
332 test_cmp expected actual4
335 test_expect_success 'merge-msg -F' '
336 test_unconfig merge.log &&
337 test_config merge.summary yes &&
338 git checkout master &&
340 git fetch . left right &&
341 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
342 test_cmp expected actual
345 test_expect_success 'merge-msg -F in subdirectory' '
346 test_unconfig merge.log &&
347 test_config merge.summary yes &&
348 git checkout master &&
350 git fetch . left right &&
352 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
355 git fmt-merge-msg -F FETCH_HEAD >../actual
357 test_cmp expected actual
360 test_expect_success 'merge-msg with nothing to merge' '
361 test_unconfig merge.log &&
362 test_config merge.summary yes &&
366 git checkout -b unrelated &&
369 git fmt-merge-msg <.git/FETCH_HEAD >../actual
372 test_must_be_empty actual
375 test_expect_success 'merge-msg tag' '
376 cat >expected <<-EOF &&
377 Merge tag ${apos}tag-r3${apos}
379 * tag ${apos}tag-r3${apos}:
385 test_unconfig merge.log &&
386 test_config merge.summary yes &&
388 git checkout master &&
390 git fetch . tag tag-r3 &&
392 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
393 test_cmp expected actual
396 test_expect_success 'merge-msg two tags' '
397 cat >expected <<-EOF &&
398 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
400 * tag ${apos}tag-r3${apos}:
405 # By Another Author (3) and A U Thor (2)
406 # Via Another Committer
407 * tag ${apos}tag-l5${apos}:
415 test_unconfig merge.log &&
416 test_config merge.summary yes &&
418 git checkout master &&
420 git fetch . tag tag-r3 tag tag-l5 &&
422 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
423 test_cmp expected actual
426 test_expect_success 'merge-msg tag and branch' '
427 cat >expected <<-EOF &&
428 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
430 * tag ${apos}tag-r3${apos}:
435 # By Another Author (3) and A U Thor (2)
436 # Via Another Committer
445 test_unconfig merge.log &&
446 test_config merge.summary yes &&
448 git checkout master &&
450 git fetch . tag tag-r3 left &&
452 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
453 test_cmp expected actual
456 test_expect_success 'merge-msg lots of commits' '
459 Merge branch ${apos}long${apos}
473 test_config merge.summary yes &&
475 git checkout master &&
479 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
480 test_cmp expected actual
483 test_expect_success 'merge-msg with "merging" an annotated tag' '
484 test_config merge.log true &&
486 git checkout master^0 &&
487 git commit --allow-empty -m "One step ahead" &&
488 git tag -a -m "An annotated one" annote HEAD &&
490 git checkout master &&
491 git fetch . annote &&
493 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
496 Merge tag '\''annote'\''
500 * tag '\''annote'\'':
504 test_cmp expected actual &&
506 test_when_finished "git reset --hard" &&
507 annote=$(git rev-parse annote) &&
508 git merge --no-commit --no-ff $annote &&
511 Merge tag '\''$annote'\''
515 * tag '\''$annote'\'':
519 test_cmp expected .git/MERGE_MSG