84e10fde6fde69e69c24f959d529a5f946117352
1#!/bin/sh
2#
3# Copyright (c) 2006, Junio C Hamano
4#
5
6test_description='fmt-merge-msg test'
7
8. ./test-lib.sh
9
10test_expect_success setup '
11 echo one >one &&
12 git add one &&
13 test_tick &&
14 git commit -m "Initial" &&
15
16 git clone . remote &&
17
18 echo uno >one &&
19 echo dos >two &&
20 git add two &&
21 test_tick &&
22 git commit -a -m "Second" &&
23
24 git checkout -b left &&
25
26 echo "c1" >one &&
27 test_tick &&
28 git commit -a -m "Common #1" &&
29
30 echo "c2" >one &&
31 test_tick &&
32 git commit -a -m "Common #2" &&
33
34 git branch right &&
35
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" &&
40
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" &&
45
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 &&
51
52 git checkout right &&
53
54 echo "r3" >three &&
55 git add three &&
56 test_tick &&
57 git commit -a -m "Right #3" &&
58 git tag tag-r3 &&
59
60 echo "r4" >three &&
61 test_tick &&
62 git commit -a -m "Right #4" &&
63
64 echo "r5" >three &&
65 test_tick &&
66 git commit -a -m "Right #5" &&
67
68 git checkout -b long &&
69 i=0 &&
70 while test $i -lt 30
71 do
72 test_commit $i one &&
73 i=$(($i+1))
74 done &&
75
76 git show-branch &&
77
78 apos="'\''"
79'
80
81test_expect_success 'message for merging local branch' '
82 echo "Merge branch ${apos}left${apos}" >expected &&
83
84 git checkout master &&
85 git fetch . left &&
86
87 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
88 test_cmp expected actual
89'
90
91test_expect_success 'message for merging external branch' '
92 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
93
94 git checkout master &&
95 git fetch "$(pwd)" left &&
96
97 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
98 test_cmp expected actual
99'
100
101test_expect_success '[merge] summary/log configuration' '
102 cat >expected <<-EOF &&
103 Merge branch ${apos}left${apos}
104
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
113 EOF
114
115 git config merge.log true &&
116 test_might_fail git config --unset-all merge.summary &&
117
118 git checkout master &&
119 test_tick &&
120 git fetch . left &&
121
122 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
123
124 test_might_fail git config --unset-all merge.log &&
125 git config merge.summary true &&
126
127 git checkout master &&
128 test_tick &&
129 git fetch . left &&
130
131 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
132
133 test_cmp expected actual1 &&
134 test_cmp expected actual2
135'
136
137test_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
140'
141
142test_expect_success 'setup FETCH_HEAD' '
143 git checkout master &&
144 test_tick &&
145 git fetch . left
146'
147
148test_expect_success 'merge.log=3 limits shortlog length' '
149 cat >expected <<-EOF &&
150 Merge branch ${apos}left${apos}
151
152 # By Another Author (3) and A U Thor (2)
153 # Via Another Committer
154 * left: (5 commits)
155 Left #5
156 Left #4
157 Left #3
158 ...
159 EOF
160
161 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
162 test_cmp expected actual
163'
164
165test_expect_success 'merge.log=5 shows all 5 commits' '
166 cat >expected <<-EOF &&
167 Merge branch ${apos}left${apos}
168
169 # By Another Author (3) and A U Thor (2)
170 # Via Another Committer
171 * left:
172 Left #5
173 Left #4
174 Left #3
175 Common #2
176 Common #1
177 EOF
178
179 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
180 test_cmp expected actual
181'
182
183test_expect_success '--log=5 with custom comment character' '
184 cat >expected <<-EOF &&
185 Merge branch ${apos}left${apos}
186
187 / By Another Author (3) and A U Thor (2)
188 / Via Another Committer
189 * left:
190 Left #5
191 Left #4
192 Left #3
193 Common #2
194 Common #1
195 EOF
196
197 git -c core.commentchar="/" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
198 test_cmp expected actual
199'
200
201test_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
205'
206
207test_expect_success '--log=3 limits shortlog length' '
208 cat >expected <<-EOF &&
209 Merge branch ${apos}left${apos}
210
211 # By Another Author (3) and A U Thor (2)
212 # Via Another Committer
213 * left: (5 commits)
214 Left #5
215 Left #4
216 Left #3
217 ...
218 EOF
219
220 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
221 test_cmp expected actual
222'
223
224test_expect_success '--log=5 shows all 5 commits' '
225 cat >expected <<-EOF &&
226 Merge branch ${apos}left${apos}
227
228 # By Another Author (3) and A U Thor (2)
229 # Via Another Committer
230 * left:
231 Left #5
232 Left #4
233 Left #3
234 Common #2
235 Common #1
236 EOF
237
238 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
239 test_cmp expected actual
240'
241
242test_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
246'
247
248test_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
252'
253
254test_expect_success 'fmt-merge-msg -m' '
255 echo "Sync with left" >expected &&
256 cat >expected.log <<-EOF &&
257 Sync with left
258
259 # By Another Author (3) and A U Thor (2)
260 # Via Another Committer
261 * ${apos}left${apos} of $(pwd):
262 Left #5
263 Left #4
264 Left #3
265 Common #2
266 Common #1
267 EOF
268
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 &&
281
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
286'
287
288test_expect_success 'setup: expected shortlog for two branches' '
289 cat >expected <<-EOF
290 Merge branches ${apos}left${apos} and ${apos}right${apos}
291
292 # By Another Author (3) and A U Thor (2)
293 # Via Another Committer
294 * left:
295 Left #5
296 Left #4
297 Left #3
298 Common #2
299 Common #1
300
301 * right:
302 Right #5
303 Right #4
304 Right #3
305 Common #2
306 Common #1
307 EOF
308'
309
310test_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 &&
314 test_tick &&
315 git fetch . left right &&
316 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
317
318 test_might_fail git config --unset-all merge.log &&
319 git config merge.summary true &&
320 git checkout master &&
321 test_tick &&
322 git fetch . left right &&
323 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
324
325 git config merge.log yes &&
326 test_might_fail git config --unset-all merge.summary &&
327 git checkout master &&
328 test_tick &&
329 git fetch . left right &&
330 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
331
332 test_might_fail git config --unset-all merge.log &&
333 git config merge.summary yes &&
334 git checkout master &&
335 test_tick &&
336 git fetch . left right &&
337 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
338
339 test_cmp expected actual1 &&
340 test_cmp expected actual2 &&
341 test_cmp expected actual3 &&
342 test_cmp expected actual4
343'
344
345test_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 &&
349 test_tick &&
350 git fetch . left right &&
351 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
352 test_cmp expected actual
353'
354
355test_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 &&
359 test_tick &&
360 git fetch . left right &&
361 mkdir sub &&
362 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
363 (
364 cd sub &&
365 git fmt-merge-msg -F FETCH_HEAD >../actual
366 ) &&
367 test_cmp expected actual
368'
369
370test_expect_success 'merge-msg with nothing to merge' '
371 test_might_fail git config --unset-all merge.log &&
372 git config merge.summary yes &&
373
374 >empty &&
375
376 (
377 cd remote &&
378 git checkout -b unrelated &&
379 test_tick &&
380 git fetch origin &&
381 git fmt-merge-msg <.git/FETCH_HEAD >../actual
382 ) &&
383
384 test_cmp empty actual
385'
386
387test_expect_success 'merge-msg tag' '
388 cat >expected <<-EOF &&
389 Merge tag ${apos}tag-r3${apos}
390
391 * tag ${apos}tag-r3${apos}:
392 Right #3
393 Common #2
394 Common #1
395 EOF
396
397 test_might_fail git config --unset-all merge.log &&
398 git config merge.summary yes &&
399
400 git checkout master &&
401 test_tick &&
402 git fetch . tag tag-r3 &&
403
404 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
405 test_cmp expected actual
406'
407
408test_expect_success 'merge-msg two tags' '
409 cat >expected <<-EOF &&
410 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
411
412 * tag ${apos}tag-r3${apos}:
413 Right #3
414 Common #2
415 Common #1
416
417 # By Another Author (3) and A U Thor (2)
418 # Via Another Committer
419 * tag ${apos}tag-l5${apos}:
420 Left #5
421 Left #4
422 Left #3
423 Common #2
424 Common #1
425 EOF
426
427 test_might_fail git config --unset-all merge.log &&
428 git config merge.summary yes &&
429
430 git checkout master &&
431 test_tick &&
432 git fetch . tag tag-r3 tag tag-l5 &&
433
434 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
435 test_cmp expected actual
436'
437
438test_expect_success 'merge-msg tag and branch' '
439 cat >expected <<-EOF &&
440 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
441
442 * tag ${apos}tag-r3${apos}:
443 Right #3
444 Common #2
445 Common #1
446
447 # By Another Author (3) and A U Thor (2)
448 # Via Another Committer
449 * left:
450 Left #5
451 Left #4
452 Left #3
453 Common #2
454 Common #1
455 EOF
456
457 test_might_fail git config --unset-all merge.log &&
458 git config merge.summary yes &&
459
460 git checkout master &&
461 test_tick &&
462 git fetch . tag tag-r3 left &&
463
464 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
465 test_cmp expected actual
466'
467
468test_expect_success 'merge-msg lots of commits' '
469 {
470 cat <<-EOF &&
471 Merge branch ${apos}long${apos}
472
473 * long: (35 commits)
474 EOF
475
476 i=29 &&
477 while test $i -gt 9
478 do
479 echo " $i" &&
480 i=$(($i-1))
481 done &&
482 echo " ..."
483 } >expected &&
484
485 git checkout master &&
486 test_tick &&
487 git fetch . long &&
488
489 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
490 test_cmp expected actual
491'
492
493test_done