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