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