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 git config merge.log true &&
116 test_might_fail git config --unset-all merge.summary &&
118 git checkout master &&
122 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
124 test_might_fail git config --unset-all merge.log &&
125 git 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: clear [merge] configuration' '
138 test_might_fail git config --unset-all merge.log &&
139 test_might_fail git config --unset-all merge.summary
142 test_expect_success
'setup FETCH_HEAD' '
143 git checkout master &&
148 test_expect_success
'merge.log=3 limits shortlog length' '
149 cat >expected <<-EOF &&
150 Merge branch ${apos}left${apos}
152 # By Another Author (3) and A U Thor (2)
153 # Via Another Committer
161 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
162 test_cmp expected actual
165 test_expect_success
'merge.log=5 shows all 5 commits' '
166 cat >expected <<-EOF &&
167 Merge branch ${apos}left${apos}
169 # By Another Author (3) and A U Thor (2)
170 # Via Another Committer
179 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
180 test_cmp expected actual
183 test_expect_success
'--log=5 with custom comment character' '
184 cat >expected <<-EOF &&
185 Merge branch ${apos}left${apos}
187 x By Another Author (3) and A U Thor (2)
188 x Via Another Committer
197 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
198 test_cmp expected actual
201 test_expect_success
'merge.log=0 disables shortlog' '
202 echo "Merge branch ${apos}left${apos}" >expected
203 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
204 test_cmp expected actual
207 test_expect_success
'--log=3 limits shortlog length' '
208 cat >expected <<-EOF &&
209 Merge branch ${apos}left${apos}
211 # By Another Author (3) and A U Thor (2)
212 # Via Another Committer
220 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
221 test_cmp expected actual
224 test_expect_success
'--log=5 shows all 5 commits' '
225 cat >expected <<-EOF &&
226 Merge branch ${apos}left${apos}
228 # By Another Author (3) and A U Thor (2)
229 # Via Another Committer
238 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
239 test_cmp expected actual
242 test_expect_success
'--no-log disables shortlog' '
243 echo "Merge branch ${apos}left${apos}" >expected &&
244 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
245 test_cmp expected actual
248 test_expect_success
'--log=0 disables shortlog' '
249 echo "Merge branch ${apos}left${apos}" >expected &&
250 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
251 test_cmp expected actual
254 test_expect_success
'fmt-merge-msg -m' '
255 echo "Sync with left" >expected &&
256 cat >expected.log <<-EOF &&
259 # By Another Author (3) and A U Thor (2)
260 # Via Another Committer
261 * ${apos}left${apos} of $(pwd):
269 test_might_fail git config --unset merge.log &&
270 test_might_fail git config --unset merge.summary &&
271 git checkout master &&
272 git fetch "$(pwd)" left &&
273 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
274 git fmt-merge-msg --log -m "Sync with left" \
275 <.git/FETCH_HEAD >actual.log &&
276 git config merge.log true &&
277 git fmt-merge-msg -m "Sync with left" \
278 <.git/FETCH_HEAD >actual.log-config &&
279 git fmt-merge-msg --no-log -m "Sync with left" \
280 <.git/FETCH_HEAD >actual.nolog &&
282 test_cmp expected actual &&
283 test_cmp expected.log actual.log &&
284 test_cmp expected.log actual.log-config &&
285 test_cmp expected actual.nolog
288 test_expect_success
'setup: expected shortlog for two branches' '
290 Merge branches ${apos}left${apos} and ${apos}right${apos}
292 # By Another Author (3) and A U Thor (2)
293 # Via Another Committer
310 test_expect_success
'shortlog for two branches' '
311 git config merge.log true &&
312 test_might_fail git config --unset-all merge.summary &&
313 git checkout master &&
315 git fetch . left right &&
316 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
318 test_might_fail git config --unset-all merge.log &&
319 git config merge.summary true &&
320 git checkout master &&
322 git fetch . left right &&
323 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
325 git config merge.log yes &&
326 test_might_fail git config --unset-all merge.summary &&
327 git checkout master &&
329 git fetch . left right &&
330 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
332 test_might_fail git config --unset-all merge.log &&
333 git config merge.summary yes &&
334 git checkout master &&
336 git fetch . left right &&
337 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
339 test_cmp expected actual1 &&
340 test_cmp expected actual2 &&
341 test_cmp expected actual3 &&
342 test_cmp expected actual4
345 test_expect_success
'merge-msg -F' '
346 test_might_fail git config --unset-all merge.log &&
347 git config merge.summary yes &&
348 git checkout master &&
350 git fetch . left right &&
351 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
352 test_cmp expected actual
355 test_expect_success
'merge-msg -F in subdirectory' '
356 test_might_fail git config --unset-all merge.log &&
357 git config merge.summary yes &&
358 git checkout master &&
360 git fetch . left right &&
362 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
365 git fmt-merge-msg -F FETCH_HEAD >../actual
367 test_cmp expected actual
370 test_expect_success
'merge-msg with nothing to merge' '
371 test_might_fail git config --unset-all merge.log &&
372 git config merge.summary yes &&
378 git checkout -b unrelated &&
381 git fmt-merge-msg <.git/FETCH_HEAD >../actual
384 test_cmp empty actual
387 test_expect_success
'merge-msg tag' '
388 cat >expected <<-EOF &&
389 Merge tag ${apos}tag-r3${apos}
391 * tag ${apos}tag-r3${apos}:
397 test_might_fail git config --unset-all merge.log &&
398 git config merge.summary yes &&
400 git checkout master &&
402 git fetch . tag tag-r3 &&
404 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
405 test_cmp expected actual
408 test_expect_success
'merge-msg two tags' '
409 cat >expected <<-EOF &&
410 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
412 * tag ${apos}tag-r3${apos}:
417 # By Another Author (3) and A U Thor (2)
418 # Via Another Committer
419 * tag ${apos}tag-l5${apos}:
427 test_might_fail git config --unset-all merge.log &&
428 git config merge.summary yes &&
430 git checkout master &&
432 git fetch . tag tag-r3 tag tag-l5 &&
434 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
435 test_cmp expected actual
438 test_expect_success
'merge-msg tag and branch' '
439 cat >expected <<-EOF &&
440 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
442 * tag ${apos}tag-r3${apos}:
447 # By Another Author (3) and A U Thor (2)
448 # Via Another Committer
457 test_might_fail git config --unset-all merge.log &&
458 git config merge.summary yes &&
460 git checkout master &&
462 git fetch . tag tag-r3 left &&
464 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
465 test_cmp expected actual
468 test_expect_success
'merge-msg lots of commits' '
471 Merge branch ${apos}long${apos}
485 git checkout master &&
489 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
490 test_cmp expected actual