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
'merge.log=0 disables shortlog' '
179 echo "Merge branch ${apos}left${apos}" >expected
180 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
181 test_cmp expected actual
184 test_expect_success
'--log=3 limits shortlog length' '
185 cat >expected <<-EOF &&
186 Merge branch ${apos}left${apos}
188 # By Another Author (3) and A U Thor (2)
189 # Via Another Committer
197 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
198 test_cmp expected actual
201 test_expect_success
'--log=5 shows all 5 commits' '
202 cat >expected <<-EOF &&
203 Merge branch ${apos}left${apos}
205 # By Another Author (3) and A U Thor (2)
206 # Via Another Committer
215 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
216 test_cmp expected actual
219 test_expect_success
'--no-log disables shortlog' '
220 echo "Merge branch ${apos}left${apos}" >expected &&
221 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
222 test_cmp expected actual
225 test_expect_success
'--log=0 disables shortlog' '
226 echo "Merge branch ${apos}left${apos}" >expected &&
227 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
228 test_cmp expected actual
231 test_expect_success
'fmt-merge-msg -m' '
232 echo "Sync with left" >expected &&
233 cat >expected.log <<-EOF &&
236 # By Another Author (3) and A U Thor (2)
237 # Via Another Committer
238 * ${apos}left${apos} of $(pwd):
246 test_unconfig merge.log &&
247 test_unconfig merge.summary &&
248 git checkout master &&
249 git fetch "$(pwd)" left &&
250 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
251 git fmt-merge-msg --log -m "Sync with left" \
252 <.git/FETCH_HEAD >actual.log &&
253 test_config merge.log true &&
254 git fmt-merge-msg -m "Sync with left" \
255 <.git/FETCH_HEAD >actual.log-config &&
256 git fmt-merge-msg --no-log -m "Sync with left" \
257 <.git/FETCH_HEAD >actual.nolog &&
259 test_cmp expected actual &&
260 test_cmp expected.log actual.log &&
261 test_cmp expected.log actual.log-config &&
262 test_cmp expected actual.nolog
265 test_expect_success
'setup: expected shortlog for two branches' '
267 Merge branches ${apos}left${apos} and ${apos}right${apos}
269 # By Another Author (3) and A U Thor (2)
270 # Via Another Committer
287 test_expect_success
'shortlog for two branches' '
288 test_config merge.log true &&
289 test_unconfig merge.summary &&
290 git checkout master &&
292 git fetch . left right &&
293 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
295 test_unconfig merge.log &&
296 test_config merge.summary true &&
297 git checkout master &&
299 git fetch . left right &&
300 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
302 test_config merge.log yes &&
303 test_unconfig merge.summary &&
304 git checkout master &&
306 git fetch . left right &&
307 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
309 test_unconfig merge.log &&
310 test_config merge.summary yes &&
311 git checkout master &&
313 git fetch . left right &&
314 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
316 test_cmp expected actual1 &&
317 test_cmp expected actual2 &&
318 test_cmp expected actual3 &&
319 test_cmp expected actual4
322 test_expect_success
'merge-msg -F' '
323 test_unconfig merge.log &&
324 test_config merge.summary yes &&
325 git checkout master &&
327 git fetch . left right &&
328 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
329 test_cmp expected actual
332 test_expect_success
'merge-msg -F in subdirectory' '
333 test_unconfig merge.log &&
334 test_config merge.summary yes &&
335 git checkout master &&
337 git fetch . left right &&
339 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
342 git fmt-merge-msg -F FETCH_HEAD >../actual
344 test_cmp expected actual
347 test_expect_success
'merge-msg with nothing to merge' '
348 test_unconfig merge.log &&
349 test_config merge.summary yes &&
355 git checkout -b unrelated &&
358 git fmt-merge-msg <.git/FETCH_HEAD >../actual
361 test_cmp empty actual
364 test_expect_success
'merge-msg tag' '
365 cat >expected <<-EOF &&
366 Merge tag ${apos}tag-r3${apos}
368 * tag ${apos}tag-r3${apos}:
374 test_unconfig merge.log &&
375 test_config merge.summary yes &&
377 git checkout master &&
379 git fetch . tag tag-r3 &&
381 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
382 test_cmp expected actual
385 test_expect_success
'merge-msg two tags' '
386 cat >expected <<-EOF &&
387 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
389 * tag ${apos}tag-r3${apos}:
394 # By Another Author (3) and A U Thor (2)
395 # Via Another Committer
396 * tag ${apos}tag-l5${apos}:
404 test_unconfig merge.log &&
405 test_config merge.summary yes &&
407 git checkout master &&
409 git fetch . tag tag-r3 tag tag-l5 &&
411 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
412 test_cmp expected actual
415 test_expect_success
'merge-msg tag and branch' '
416 cat >expected <<-EOF &&
417 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
419 * tag ${apos}tag-r3${apos}:
424 # By Another Author (3) and A U Thor (2)
425 # Via Another Committer
434 test_unconfig merge.log &&
435 test_config merge.summary yes &&
437 git checkout master &&
439 git fetch . tag tag-r3 left &&
441 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
442 test_cmp expected actual
445 test_expect_success
'merge-msg lots of commits' '
448 Merge branch ${apos}long${apos}
462 test_config merge.summary yes &&
464 git checkout master &&
468 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
469 test_cmp expected actual
472 test_expect_success
'merge-msg with "merging" an annotated tag' '
473 test_config merge.log true &&
475 git checkout master^0 &&
476 git commit --allow-empty -m "One step ahead" &&
477 git tag -a -m "An annotated one" annote HEAD &&
479 git checkout master &&
480 git fetch . annote &&
482 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
485 Merge tag '\''annote'\''
489 * tag '\''annote'\'':
493 test_cmp expected actual &&
495 test_when_finished "git reset --hard" &&
496 annote=$(git rev-parse annote) &&
497 git merge --no-commit $annote &&
500 Merge tag '\''$annote'\''
504 * tag '\''$annote'\'':
508 test_cmp expected .git/MERGE_MSG