]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6200-fmt-merge-msg.sh
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
[thirdparty/git.git] / t / t6200-fmt-merge-msg.sh
CommitLineData
30a95f30
JH
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
30a95f30
JH
10test_expect_success setup '
11 echo one >one &&
12 git add one &&
6183a6ad 13 test_tick &&
30a95f30
JH
14 git commit -m "Initial" &&
15
419fe5bc
SB
16 git clone . remote &&
17
30a95f30
JH
18 echo uno >one &&
19 echo dos >two &&
20 git add two &&
6183a6ad 21 test_tick &&
30a95f30
JH
22 git commit -a -m "Second" &&
23
24 git checkout -b left &&
25
6183a6ad
SB
26 echo "c1" >one &&
27 test_tick &&
30a95f30
JH
28 git commit -a -m "Common #1" &&
29
6183a6ad
SB
30 echo "c2" >one &&
31 test_tick &&
30a95f30
JH
32 git commit -a -m "Common #2" &&
33
34 git branch right &&
35
6183a6ad
SB
36 echo "l3" >two &&
37 test_tick &&
418a1435
JH
38 GIT_COMMITTER_NAME="Another Committer" \
39 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
30a95f30 40
6183a6ad
SB
41 echo "l4" >two &&
42 test_tick &&
418a1435
JH
43 GIT_COMMITTER_NAME="Another Committer" \
44 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
30a95f30 45
6183a6ad
SB
46 echo "l5" >two &&
47 test_tick &&
418a1435
JH
48 GIT_COMMITTER_NAME="Another Committer" \
49 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
6183a6ad 50 git tag tag-l5 &&
30a95f30
JH
51
52 git checkout right &&
53
6183a6ad 54 echo "r3" >three &&
30a95f30 55 git add three &&
6183a6ad 56 test_tick &&
30a95f30 57 git commit -a -m "Right #3" &&
6183a6ad 58 git tag tag-r3 &&
30a95f30 59
6183a6ad
SB
60 echo "r4" >three &&
61 test_tick &&
30a95f30
JH
62 git commit -a -m "Right #4" &&
63
6183a6ad
SB
64 echo "r5" >three &&
65 test_tick &&
30a95f30
JH
66 git commit -a -m "Right #5" &&
67
6d6f6e68
SB
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
d834c96a 76 git show-branch &&
30a95f30 77
d834c96a
JN
78 apos="'\''"
79'
30a95f30 80
d834c96a
JN
81test_expect_success 'message for merging local branch' '
82 echo "Merge branch ${apos}left${apos}" >expected &&
30a95f30
JH
83
84 git checkout master &&
85 git fetch . left &&
86
87 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
3af82863 88 test_cmp expected actual
30a95f30
JH
89'
90
d834c96a
JN
91test_expect_success 'message for merging external branch' '
92 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
30a95f30
JH
93
94 git checkout master &&
4114156a 95 git fetch "$(pwd)" left &&
30a95f30
JH
96
97 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
3af82863 98 test_cmp expected actual
30a95f30
JH
99'
100
d834c96a
JN
101test_expect_success '[merge] summary/log configuration' '
102 cat >expected <<-EOF &&
103 Merge branch ${apos}left${apos}
30a95f30 104
9830a9ca
JH
105 # By Another Author (3) and A U Thor (2)
106 # Via Another Committer
d834c96a
JN
107 * left:
108 Left #5
109 Left #4
110 Left #3
111 Common #2
112 Common #1
113 EOF
30a95f30 114
9a94dba0
JH
115 test_config merge.log true &&
116 test_unconfig merge.summary &&
6cd9cfef
SG
117
118 git checkout master &&
6183a6ad 119 test_tick &&
6cd9cfef
SG
120 git fetch . left &&
121
d834c96a 122 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
6cd9cfef 123
9a94dba0
JH
124 test_unconfig merge.log &&
125 test_config merge.summary true &&
30a95f30
JH
126
127 git checkout master &&
6183a6ad 128 test_tick &&
30a95f30
JH
129 git fetch . left &&
130
d834c96a 131 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
30a95f30 132
d834c96a
JN
133 test_cmp expected actual1 &&
134 test_cmp expected actual2
135'
30a95f30 136
b928cbf1
RR
137test_expect_success 'setup FETCH_HEAD' '
138 git checkout master &&
139 test_tick &&
140 git fetch . left
141'
142
143test_expect_success 'merge.log=3 limits shortlog length' '
144 cat >expected <<-EOF &&
145 Merge branch ${apos}left${apos}
146
9830a9ca
JH
147 # By Another Author (3) and A U Thor (2)
148 # Via Another Committer
b928cbf1
RR
149 * left: (5 commits)
150 Left #5
151 Left #4
152 Left #3
153 ...
154 EOF
155
156 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
157 test_cmp expected actual
158'
159
160test_expect_success 'merge.log=5 shows all 5 commits' '
161 cat >expected <<-EOF &&
162 Merge branch ${apos}left${apos}
163
9830a9ca
JH
164 # By Another Author (3) and A U Thor (2)
165 # Via Another Committer
b928cbf1
RR
166 * left:
167 Left #5
168 Left #4
169 Left #3
170 Common #2
171 Common #1
172 EOF
173
174 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
175 test_cmp expected actual
176'
177
9927ebed
RT
178test_expect_success '--log=5 with custom comment character' '
179 cat >expected <<-EOF &&
180 Merge branch ${apos}left${apos}
181
16a794de
JS
182 x By Another Author (3) and A U Thor (2)
183 x Via Another Committer
9927ebed
RT
184 * left:
185 Left #5
186 Left #4
187 Left #3
188 Common #2
189 Common #1
190 EOF
191
16a794de 192 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
9927ebed
RT
193 test_cmp expected actual
194'
195
b928cbf1 196test_expect_success 'merge.log=0 disables shortlog' '
99094a7a 197 echo "Merge branch ${apos}left${apos}" >expected &&
b928cbf1
RR
198 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
199 test_cmp expected actual
200'
201
bd2549ca
RR
202test_expect_success '--log=3 limits shortlog length' '
203 cat >expected <<-EOF &&
204 Merge branch ${apos}left${apos}
205
9830a9ca
JH
206 # By Another Author (3) and A U Thor (2)
207 # Via Another Committer
bd2549ca
RR
208 * left: (5 commits)
209 Left #5
210 Left #4
211 Left #3
212 ...
213 EOF
214
215 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
216 test_cmp expected actual
217'
218
219test_expect_success '--log=5 shows all 5 commits' '
220 cat >expected <<-EOF &&
221 Merge branch ${apos}left${apos}
222
9830a9ca
JH
223 # By Another Author (3) and A U Thor (2)
224 # Via Another Committer
bd2549ca
RR
225 * left:
226 Left #5
227 Left #4
228 Left #3
229 Common #2
230 Common #1
231 EOF
232
233 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
234 test_cmp expected actual
235'
236
237test_expect_success '--no-log disables shortlog' '
238 echo "Merge branch ${apos}left${apos}" >expected &&
239 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
240 test_cmp expected actual
241'
242
243test_expect_success '--log=0 disables shortlog' '
244 echo "Merge branch ${apos}left${apos}" >expected &&
245 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
246 test_cmp expected actual
247'
248
2102440c
JN
249test_expect_success 'fmt-merge-msg -m' '
250 echo "Sync with left" >expected &&
251 cat >expected.log <<-EOF &&
252 Sync with left
253
9830a9ca
JH
254 # By Another Author (3) and A U Thor (2)
255 # Via Another Committer
2102440c
JN
256 * ${apos}left${apos} of $(pwd):
257 Left #5
258 Left #4
259 Left #3
260 Common #2
261 Common #1
262 EOF
263
9a94dba0
JH
264 test_unconfig merge.log &&
265 test_unconfig merge.summary &&
2102440c
JN
266 git checkout master &&
267 git fetch "$(pwd)" left &&
268 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
269 git fmt-merge-msg --log -m "Sync with left" \
270 <.git/FETCH_HEAD >actual.log &&
9a94dba0 271 test_config merge.log true &&
2102440c
JN
272 git fmt-merge-msg -m "Sync with left" \
273 <.git/FETCH_HEAD >actual.log-config &&
274 git fmt-merge-msg --no-log -m "Sync with left" \
275 <.git/FETCH_HEAD >actual.nolog &&
276
277 test_cmp expected actual &&
278 test_cmp expected.log actual.log &&
279 test_cmp expected.log actual.log-config &&
280 test_cmp expected actual.nolog
281'
282
d834c96a
JN
283test_expect_success 'setup: expected shortlog for two branches' '
284 cat >expected <<-EOF
285 Merge branches ${apos}left${apos} and ${apos}right${apos}
286
9830a9ca
JH
287 # By Another Author (3) and A U Thor (2)
288 # Via Another Committer
d834c96a
JN
289 * left:
290 Left #5
291 Left #4
292 Left #3
293 Common #2
294 Common #1
295
296 * right:
297 Right #5
298 Right #4
299 Right #3
300 Common #2
301 Common #1
302 EOF
303'
6cd9cfef 304
d834c96a 305test_expect_success 'shortlog for two branches' '
9a94dba0
JH
306 test_config merge.log true &&
307 test_unconfig merge.summary &&
6cd9cfef 308 git checkout master &&
6183a6ad 309 test_tick &&
6cd9cfef 310 git fetch . left right &&
d834c96a 311 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
6cd9cfef 312
9a94dba0
JH
313 test_unconfig merge.log &&
314 test_config merge.summary true &&
30a95f30 315 git checkout master &&
6183a6ad 316 test_tick &&
30a95f30 317 git fetch . left right &&
d834c96a 318 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
30a95f30 319
9a94dba0
JH
320 test_config merge.log yes &&
321 test_unconfig merge.summary &&
6cd9cfef 322 git checkout master &&
6183a6ad 323 test_tick &&
6cd9cfef 324 git fetch . left right &&
d834c96a 325 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
6cd9cfef 326
9a94dba0
JH
327 test_unconfig merge.log &&
328 test_config merge.summary yes &&
30a95f30 329 git checkout master &&
6183a6ad 330 test_tick &&
30a95f30 331 git fetch . left right &&
d834c96a 332 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
30a95f30 333
d834c96a
JN
334 test_cmp expected actual1 &&
335 test_cmp expected actual2 &&
336 test_cmp expected actual3 &&
337 test_cmp expected actual4
30a95f30
JH
338'
339
4c8d4c14 340test_expect_success 'merge-msg -F' '
9a94dba0
JH
341 test_unconfig merge.log &&
342 test_config merge.summary yes &&
4c8d4c14 343 git checkout master &&
6183a6ad 344 test_tick &&
4c8d4c14 345 git fetch . left right &&
4c8d4c14
SB
346 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
347 test_cmp expected actual
348'
349
350test_expect_success 'merge-msg -F in subdirectory' '
9a94dba0
JH
351 test_unconfig merge.log &&
352 test_config merge.summary yes &&
4c8d4c14 353 git checkout master &&
6183a6ad 354 test_tick &&
4c8d4c14
SB
355 git fetch . left right &&
356 mkdir sub &&
357 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
358 (
359 cd sub &&
360 git fmt-merge-msg -F FETCH_HEAD >../actual
361 ) &&
362 test_cmp expected actual
363'
364
419fe5bc 365test_expect_success 'merge-msg with nothing to merge' '
9a94dba0
JH
366 test_unconfig merge.log &&
367 test_config merge.summary yes &&
419fe5bc
SB
368
369 (
370 cd remote &&
371 git checkout -b unrelated &&
6183a6ad 372 test_tick &&
419fe5bc
SB
373 git fetch origin &&
374 git fmt-merge-msg <.git/FETCH_HEAD >../actual
375 ) &&
376
1c5e94f4 377 test_must_be_empty actual
419fe5bc
SB
378'
379
6d6f6e68 380test_expect_success 'merge-msg tag' '
d834c96a
JN
381 cat >expected <<-EOF &&
382 Merge tag ${apos}tag-r3${apos}
383
384 * tag ${apos}tag-r3${apos}:
385 Right #3
386 Common #2
387 Common #1
388 EOF
6d6f6e68 389
9a94dba0
JH
390 test_unconfig merge.log &&
391 test_config merge.summary yes &&
6d6f6e68
SB
392
393 git checkout master &&
394 test_tick &&
395 git fetch . tag tag-r3 &&
396
397 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
398 test_cmp expected actual
399'
400
6d6f6e68 401test_expect_success 'merge-msg two tags' '
d834c96a
JN
402 cat >expected <<-EOF &&
403 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
404
405 * tag ${apos}tag-r3${apos}:
406 Right #3
407 Common #2
408 Common #1
409
9830a9ca
JH
410 # By Another Author (3) and A U Thor (2)
411 # Via Another Committer
d834c96a
JN
412 * tag ${apos}tag-l5${apos}:
413 Left #5
414 Left #4
415 Left #3
416 Common #2
417 Common #1
418 EOF
419
9a94dba0
JH
420 test_unconfig merge.log &&
421 test_config merge.summary yes &&
6d6f6e68
SB
422
423 git checkout master &&
424 test_tick &&
425 git fetch . tag tag-r3 tag tag-l5 &&
426
427 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
428 test_cmp expected actual
429'
430
6d6f6e68 431test_expect_success 'merge-msg tag and branch' '
d834c96a
JN
432 cat >expected <<-EOF &&
433 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
434
435 * tag ${apos}tag-r3${apos}:
436 Right #3
437 Common #2
438 Common #1
439
9830a9ca
JH
440 # By Another Author (3) and A U Thor (2)
441 # Via Another Committer
d834c96a
JN
442 * left:
443 Left #5
444 Left #4
445 Left #3
446 Common #2
447 Common #1
448 EOF
449
9a94dba0
JH
450 test_unconfig merge.log &&
451 test_config merge.summary yes &&
6d6f6e68
SB
452
453 git checkout master &&
454 test_tick &&
455 git fetch . tag tag-r3 left &&
456
457 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
458 test_cmp expected actual
459'
460
6d6f6e68 461test_expect_success 'merge-msg lots of commits' '
d834c96a
JN
462 {
463 cat <<-EOF &&
464 Merge branch ${apos}long${apos}
465
466 * long: (35 commits)
467 EOF
468
469 i=29 &&
470 while test $i -gt 9
471 do
472 echo " $i" &&
473 i=$(($i-1))
474 done &&
475 echo " ..."
476 } >expected &&
6d6f6e68 477
9a94dba0
JH
478 test_config merge.summary yes &&
479
6d6f6e68
SB
480 git checkout master &&
481 test_tick &&
482 git fetch . long &&
483
6d6f6e68
SB
484 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
485 test_cmp expected actual
486'
487
a38d3d76
JH
488test_expect_success 'merge-msg with "merging" an annotated tag' '
489 test_config merge.log true &&
490
491 git checkout master^0 &&
492 git commit --allow-empty -m "One step ahead" &&
493 git tag -a -m "An annotated one" annote HEAD &&
494
495 git checkout master &&
496 git fetch . annote &&
497
498 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
499 {
500 cat <<-\EOF
501 Merge tag '\''annote'\''
502
503 An annotated one
504
505 * tag '\''annote'\'':
506 One step ahead
507 EOF
508 } >expected &&
509 test_cmp expected actual &&
510
511 test_when_finished "git reset --hard" &&
512 annote=$(git rev-parse annote) &&
adcc94a0 513 git merge --no-commit --no-ff $annote &&
a38d3d76
JH
514 {
515 cat <<-EOF
516 Merge tag '\''$annote'\''
517
518 An annotated one
519
520 * tag '\''$annote'\'':
521 One step ahead
522 EOF
523 } >expected &&
524 test_cmp expected .git/MERGE_MSG
525'
526
30a95f30 527test_done