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