Merge branch 'master' of git://git.kernel.org/pub/scm/git/git
[git/jnareb-git.git] / t / t6200-fmt-merge-msg.sh
blobf73eceabfbcd0a763b8908a8d829894a5e36055b
1 #!/bin/sh
3 # Copyright (c) 2006, Junio C Hamano
6 test_description='fmt-merge-msg test'
8 . ./test-lib.sh
10 test_expect_success setup '
11 echo one >one &&
12 git add one &&
13 test_tick &&
14 git commit -m "Initial" &&
16 git clone . remote &&
18 echo uno >one &&
19 echo dos >two &&
20 git add two &&
21 test_tick &&
22 git commit -a -m "Second" &&
24 git checkout -b left &&
26 echo "c1" >one &&
27 test_tick &&
28 git commit -a -m "Common #1" &&
30 echo "c2" >one &&
31 test_tick &&
32 git commit -a -m "Common #2" &&
34 git branch right &&
36 echo "l3" >two &&
37 test_tick &&
38 GIT_COMMITTER_NAME="Another Committer" \
39 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
41 echo "l4" >two &&
42 test_tick &&
43 GIT_COMMITTER_NAME="Another Committer" \
44 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
46 echo "l5" >two &&
47 test_tick &&
48 GIT_COMMITTER_NAME="Another Committer" \
49 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
50 git tag tag-l5 &&
52 git checkout right &&
54 echo "r3" >three &&
55 git add three &&
56 test_tick &&
57 git commit -a -m "Right #3" &&
58 git tag tag-r3 &&
60 echo "r4" >three &&
61 test_tick &&
62 git commit -a -m "Right #4" &&
64 echo "r5" >three &&
65 test_tick &&
66 git commit -a -m "Right #5" &&
68 git checkout -b long &&
69 i=0 &&
70 while test $i -lt 30
72 test_commit $i one &&
73 i=$(($i+1))
74 done &&
76 git show-branch &&
78 apos="'\''"
81 test_expect_success 'message for merging local branch' '
82 echo "Merge branch ${apos}left${apos}" >expected &&
84 git checkout master &&
85 git fetch . left &&
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
107 * left:
108 Left #5
109 Left #4
110 Left #3
111 Common #2
112 Common #1
115 test_config merge.log true &&
116 test_unconfig merge.summary &&
118 git checkout master &&
119 test_tick &&
120 git fetch . left &&
122 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
124 test_unconfig merge.log &&
125 test_config merge.summary true &&
127 git checkout master &&
128 test_tick &&
129 git fetch . left &&
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 &&
139 test_tick &&
140 git fetch . left
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
149 * left: (5 commits)
150 Left #5
151 Left #4
152 Left #3
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
166 * left:
167 Left #5
168 Left #4
169 Left #3
170 Common #2
171 Common #1
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
190 * left: (5 commits)
191 Left #5
192 Left #4
193 Left #3
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
207 * left:
208 Left #5
209 Left #4
210 Left #3
211 Common #2
212 Common #1
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 &&
234 Sync with left
236 # By Another Author (3) and A U Thor (2)
237 # Via Another Committer
238 * ${apos}left${apos} of $(pwd):
239 Left #5
240 Left #4
241 Left #3
242 Common #2
243 Common #1
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' '
266 cat >expected <<-EOF
267 Merge branches ${apos}left${apos} and ${apos}right${apos}
269 # By Another Author (3) and A U Thor (2)
270 # Via Another Committer
271 * left:
272 Left #5
273 Left #4
274 Left #3
275 Common #2
276 Common #1
278 * right:
279 Right #5
280 Right #4
281 Right #3
282 Common #2
283 Common #1
287 test_expect_success 'shortlog for two branches' '
288 test_config merge.log true &&
289 test_unconfig merge.summary &&
290 git checkout master &&
291 test_tick &&
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 &&
298 test_tick &&
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 &&
305 test_tick &&
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 &&
312 test_tick &&
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 &&
326 test_tick &&
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 &&
336 test_tick &&
337 git fetch . left right &&
338 mkdir sub &&
339 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
341 cd sub &&
342 git fmt-merge-msg -F FETCH_HEAD >../actual
343 ) &&
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 &&
351 >empty &&
354 cd remote &&
355 git checkout -b unrelated &&
356 test_tick &&
357 git fetch origin &&
358 git fmt-merge-msg <.git/FETCH_HEAD >../actual
359 ) &&
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}:
369 Right #3
370 Common #2
371 Common #1
374 test_unconfig merge.log &&
375 test_config merge.summary yes &&
377 git checkout master &&
378 test_tick &&
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}:
390 Right #3
391 Common #2
392 Common #1
394 # By Another Author (3) and A U Thor (2)
395 # Via Another Committer
396 * tag ${apos}tag-l5${apos}:
397 Left #5
398 Left #4
399 Left #3
400 Common #2
401 Common #1
404 test_unconfig merge.log &&
405 test_config merge.summary yes &&
407 git checkout master &&
408 test_tick &&
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}:
420 Right #3
421 Common #2
422 Common #1
424 # By Another Author (3) and A U Thor (2)
425 # Via Another Committer
426 * left:
427 Left #5
428 Left #4
429 Left #3
430 Common #2
431 Common #1
434 test_unconfig merge.log &&
435 test_config merge.summary yes &&
437 git checkout master &&
438 test_tick &&
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' '
447 cat <<-EOF &&
448 Merge branch ${apos}long${apos}
450 * long: (35 commits)
453 i=29 &&
454 while test $i -gt 9
456 echo " $i" &&
457 i=$(($i-1))
458 done &&
459 echo " ..."
460 } >expected &&
462 test_config merge.summary yes &&
464 git checkout master &&
465 test_tick &&
466 git fetch . long &&
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 &&
484 cat <<-\EOF
485 Merge tag '\''annote'\''
487 An annotated one
489 * tag '\''annote'\'':
490 One step ahead
492 } >expected &&
493 test_cmp expected actual &&
495 test_when_finished "git reset --hard" &&
496 annote=$(git rev-parse annote) &&
497 git merge --no-commit $annote &&
499 cat <<-EOF
500 Merge tag '\''$annote'\''
502 An annotated one
504 * tag '\''$annote'\'':
505 One step ahead
507 } >expected &&
508 test_cmp expected .git/MERGE_MSG
511 test_done