Merge branch 'en/stash-df-fix'
[git/debian.git] / t / t6200-fmt-merge-msg.sh
blob7544245f9026d5a705dd8ab00e645db5a2e19c36
1 #!/bin/sh
3 # Copyright (c) 2006, Junio C Hamano
6 test_description='fmt-merge-msg test'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 . ./test-lib.sh
12 . "$TEST_DIRECTORY/lib-gpg.sh"
14 test_expect_success setup '
15 echo one >one &&
16 git add one &&
17 test_tick &&
18 git commit -m "Initial" &&
20 git clone . remote &&
22 echo uno >one &&
23 echo dos >two &&
24 git add two &&
25 test_tick &&
26 git commit -a -m "Second" &&
28 git checkout -b left &&
30 echo "c1" >one &&
31 test_tick &&
32 git commit -a -m "Common #1" &&
34 echo "c2" >one &&
35 test_tick &&
36 git commit -a -m "Common #2" &&
38 git branch right &&
40 echo "l3" >two &&
41 test_tick &&
42 GIT_COMMITTER_NAME="Another Committer" \
43 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
45 echo "l4" >two &&
46 test_tick &&
47 GIT_COMMITTER_NAME="Another Committer" \
48 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
50 echo "l5" >two &&
51 test_tick &&
52 GIT_COMMITTER_NAME="Another Committer" \
53 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
54 git tag tag-l5 &&
56 git checkout right &&
58 echo "r3" >three &&
59 git add three &&
60 test_tick &&
61 git commit -a -m "Right #3" &&
62 git tag tag-r3 &&
64 echo "r4" >three &&
65 test_tick &&
66 git commit -a -m "Right #4" &&
68 echo "r5" >three &&
69 test_tick &&
70 git commit -a -m "Right #5" &&
72 git checkout -b long &&
73 test_commit_bulk --start=0 --message=%s --filename=one 30 &&
75 git show-branch &&
77 apos="'\''"
80 test_expect_success GPG 'set up a signed tag' '
81 git tag -s -m signed-tag-msg signed-good-tag left
84 test_expect_success GPGSSH 'created ssh signed commit and tag' '
85 test_config gpg.format ssh &&
86 git checkout -b signed-ssh &&
87 touch file &&
88 git add file &&
89 git commit -m "ssh signed" -S"${GPGSSH_KEY_PRIMARY}" &&
90 git tag -s -u"${GPGSSH_KEY_PRIMARY}" -m signed-ssh-tag-msg signed-good-ssh-tag left &&
91 git tag -s -u"${GPGSSH_KEY_UNTRUSTED}" -m signed-ssh-tag-msg-untrusted signed-untrusted-ssh-tag left
94 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' '
95 test_when_finished "test_unconfig commit.gpgsign" &&
96 test_config gpg.format ssh &&
97 git checkout -b signed-expiry-ssh &&
98 touch file &&
99 git add file &&
101 echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" &&
102 git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed &&
104 echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" &&
105 git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed &&
107 echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" &&
108 git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed &&
110 echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" &&
111 git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed
114 test_expect_success 'message for merging local branch' '
115 echo "Merge branch ${apos}left${apos}" >expected &&
117 git checkout main &&
118 git fetch . left &&
120 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
121 test_cmp expected actual
124 test_expect_success GPG 'message for merging local tag signed by good key' '
125 git checkout main &&
126 git fetch . signed-good-tag &&
127 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
128 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
129 grep "^# gpg: Signature made" actual &&
130 grep "^# gpg: Good signature from" actual
133 test_expect_success GPG 'message for merging local tag signed by unknown key' '
134 git checkout main &&
135 git fetch . signed-good-tag &&
136 GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual &&
137 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
138 grep "^# gpg: Signature made" actual &&
139 grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual
142 test_expect_success GPGSSH 'message for merging local tag signed by good ssh key' '
143 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
144 git checkout main &&
145 git fetch . signed-good-ssh-tag &&
146 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
147 grep "^Merge tag ${apos}signed-good-ssh-tag${apos}" actual &&
148 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
149 ! grep "${GPGSSH_BAD_SIGNATURE}" actual
152 test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh key' '
153 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
154 git checkout main &&
155 git fetch . signed-untrusted-ssh-tag &&
156 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
157 grep "^Merge tag ${apos}signed-untrusted-ssh-tag${apos}" actual &&
158 grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual &&
159 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
160 grep "${GPGSSH_KEY_NOT_TRUSTED}" actual
163 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by expired ssh key' '
164 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
165 git checkout main &&
166 git fetch . expired-signed &&
167 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
168 grep "^Merge tag ${apos}expired-signed${apos}" actual &&
169 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
172 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by not yet valid ssh key' '
173 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
174 git checkout main &&
175 git fetch . notyetvalid-signed &&
176 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
177 grep "^Merge tag ${apos}notyetvalid-signed${apos}" actual &&
178 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
181 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by valid timeboxed ssh key' '
182 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
183 git checkout main &&
184 git fetch . timeboxedvalid-signed &&
185 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
186 grep "^Merge tag ${apos}timeboxedvalid-signed${apos}" actual &&
187 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
188 ! grep "${GPGSSH_BAD_SIGNATURE}" actual
191 test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by invalid timeboxed ssh key' '
192 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
193 git checkout main &&
194 git fetch . timeboxedinvalid-signed &&
195 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
196 grep "^Merge tag ${apos}timeboxedinvalid-signed${apos}" actual &&
197 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
200 test_expect_success 'message for merging external branch' '
201 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
203 git checkout main &&
204 git fetch "$(pwd)" left &&
206 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
207 test_cmp expected actual
210 test_expect_success '[merge] summary/log configuration' '
211 cat >expected <<-EOF &&
212 Merge branch ${apos}left${apos}
214 # By Another Author (3) and A U Thor (2)
215 # Via Another Committer
216 * left:
217 Left #5
218 Left #4
219 Left #3
220 Common #2
221 Common #1
224 test_config merge.log true &&
225 test_unconfig merge.summary &&
227 git checkout main &&
228 test_tick &&
229 git fetch . left &&
231 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
233 test_unconfig merge.log &&
234 test_config merge.summary true &&
236 git checkout main &&
237 test_tick &&
238 git fetch . left &&
240 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
242 test_cmp expected actual1 &&
243 test_cmp expected actual2
246 test_expect_success 'setup FETCH_HEAD' '
247 git checkout main &&
248 test_tick &&
249 git fetch . left
252 test_expect_success 'merge.log=3 limits shortlog length' '
253 cat >expected <<-EOF &&
254 Merge branch ${apos}left${apos}
256 # By Another Author (3) and A U Thor (2)
257 # Via Another Committer
258 * left: (5 commits)
259 Left #5
260 Left #4
261 Left #3
265 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
266 test_cmp expected actual
269 test_expect_success 'merge.log=5 shows all 5 commits' '
270 cat >expected <<-EOF &&
271 Merge branch ${apos}left${apos}
273 # By Another Author (3) and A U Thor (2)
274 # Via Another Committer
275 * left:
276 Left #5
277 Left #4
278 Left #3
279 Common #2
280 Common #1
283 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
284 test_cmp expected actual
287 test_expect_success '--log=5 with custom comment character' '
288 cat >expected <<-EOF &&
289 Merge branch ${apos}left${apos}
291 x By Another Author (3) and A U Thor (2)
292 x Via Another Committer
293 * left:
294 Left #5
295 Left #4
296 Left #3
297 Common #2
298 Common #1
301 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
302 test_cmp expected actual
305 test_expect_success 'merge.log=0 disables shortlog' '
306 echo "Merge branch ${apos}left${apos}" >expected &&
307 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
308 test_cmp expected actual
311 test_expect_success '--log=3 limits shortlog length' '
312 cat >expected <<-EOF &&
313 Merge branch ${apos}left${apos}
315 # By Another Author (3) and A U Thor (2)
316 # Via Another Committer
317 * left: (5 commits)
318 Left #5
319 Left #4
320 Left #3
324 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
325 test_cmp expected actual
328 test_expect_success '--log=5 shows all 5 commits' '
329 cat >expected <<-EOF &&
330 Merge branch ${apos}left${apos}
332 # By Another Author (3) and A U Thor (2)
333 # Via Another Committer
334 * left:
335 Left #5
336 Left #4
337 Left #3
338 Common #2
339 Common #1
342 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
343 test_cmp expected actual
346 test_expect_success '--no-log disables shortlog' '
347 echo "Merge branch ${apos}left${apos}" >expected &&
348 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
349 test_cmp expected actual
352 test_expect_success '--log=0 disables shortlog' '
353 echo "Merge branch ${apos}left${apos}" >expected &&
354 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
355 test_cmp expected actual
358 test_expect_success 'fmt-merge-msg -m' '
359 echo "Sync with left" >expected &&
360 cat >expected.log <<-EOF &&
361 Sync with left
363 # By Another Author (3) and A U Thor (2)
364 # Via Another Committer
365 * ${apos}left${apos} of $(pwd):
366 Left #5
367 Left #4
368 Left #3
369 Common #2
370 Common #1
373 test_unconfig merge.log &&
374 test_unconfig merge.summary &&
375 git checkout main &&
376 git fetch "$(pwd)" left &&
377 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
378 git fmt-merge-msg --log -m "Sync with left" \
379 <.git/FETCH_HEAD >actual.log &&
380 test_config merge.log true &&
381 git fmt-merge-msg -m "Sync with left" \
382 <.git/FETCH_HEAD >actual.log-config &&
383 git fmt-merge-msg --no-log -m "Sync with left" \
384 <.git/FETCH_HEAD >actual.nolog &&
386 test_cmp expected actual &&
387 test_cmp expected.log actual.log &&
388 test_cmp expected.log actual.log-config &&
389 test_cmp expected actual.nolog
392 test_expect_success 'setup: expected shortlog for two branches' '
393 cat >expected <<-EOF
394 Merge branches ${apos}left${apos} and ${apos}right${apos}
396 # By Another Author (3) and A U Thor (2)
397 # Via Another Committer
398 * left:
399 Left #5
400 Left #4
401 Left #3
402 Common #2
403 Common #1
405 * right:
406 Right #5
407 Right #4
408 Right #3
409 Common #2
410 Common #1
414 test_expect_success 'shortlog for two branches' '
415 test_config merge.log true &&
416 test_unconfig merge.summary &&
417 git checkout main &&
418 test_tick &&
419 git fetch . left right &&
420 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
422 test_unconfig merge.log &&
423 test_config merge.summary true &&
424 git checkout main &&
425 test_tick &&
426 git fetch . left right &&
427 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
429 test_config merge.log yes &&
430 test_unconfig merge.summary &&
431 git checkout main &&
432 test_tick &&
433 git fetch . left right &&
434 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
436 test_unconfig merge.log &&
437 test_config merge.summary yes &&
438 git checkout main &&
439 test_tick &&
440 git fetch . left right &&
441 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
443 test_cmp expected actual1 &&
444 test_cmp expected actual2 &&
445 test_cmp expected actual3 &&
446 test_cmp expected actual4
449 test_expect_success 'merge-msg -F' '
450 test_unconfig merge.log &&
451 test_config merge.summary yes &&
452 git checkout main &&
453 test_tick &&
454 git fetch . left right &&
455 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
456 test_cmp expected actual
459 test_expect_success 'merge-msg -F in subdirectory' '
460 test_unconfig merge.log &&
461 test_config merge.summary yes &&
462 git checkout main &&
463 test_tick &&
464 git fetch . left right &&
465 mkdir sub &&
466 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
468 cd sub &&
469 git fmt-merge-msg -F FETCH_HEAD >../actual
470 ) &&
471 test_cmp expected actual
474 test_expect_success 'merge-msg with nothing to merge' '
475 test_unconfig merge.log &&
476 test_config merge.summary yes &&
479 cd remote &&
480 git checkout -b unrelated &&
481 test_tick &&
482 git fetch origin &&
483 git fmt-merge-msg <.git/FETCH_HEAD >../actual
484 ) &&
486 test_must_be_empty actual
489 test_expect_success 'merge-msg tag' '
490 cat >expected <<-EOF &&
491 Merge tag ${apos}tag-r3${apos}
493 * tag ${apos}tag-r3${apos}:
494 Right #3
495 Common #2
496 Common #1
499 test_unconfig merge.log &&
500 test_config merge.summary yes &&
502 git checkout main &&
503 test_tick &&
504 git fetch . tag tag-r3 &&
506 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
507 test_cmp expected actual
510 test_expect_success 'merge-msg two tags' '
511 cat >expected <<-EOF &&
512 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
514 * tag ${apos}tag-r3${apos}:
515 Right #3
516 Common #2
517 Common #1
519 # By Another Author (3) and A U Thor (2)
520 # Via Another Committer
521 * tag ${apos}tag-l5${apos}:
522 Left #5
523 Left #4
524 Left #3
525 Common #2
526 Common #1
529 test_unconfig merge.log &&
530 test_config merge.summary yes &&
532 git checkout main &&
533 test_tick &&
534 git fetch . tag tag-r3 tag tag-l5 &&
536 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
537 test_cmp expected actual
540 test_expect_success 'merge-msg tag and branch' '
541 cat >expected <<-EOF &&
542 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
544 * tag ${apos}tag-r3${apos}:
545 Right #3
546 Common #2
547 Common #1
549 # By Another Author (3) and A U Thor (2)
550 # Via Another Committer
551 * left:
552 Left #5
553 Left #4
554 Left #3
555 Common #2
556 Common #1
559 test_unconfig merge.log &&
560 test_config merge.summary yes &&
562 git checkout main &&
563 test_tick &&
564 git fetch . tag tag-r3 left &&
566 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
567 test_cmp expected actual
570 test_expect_success 'merge-msg lots of commits' '
572 cat <<-EOF &&
573 Merge branch ${apos}long${apos}
575 * long: (35 commits)
578 i=29 &&
579 while test $i -gt 9
581 echo " $i" &&
582 i=$(($i-1)) || return 1
583 done &&
584 echo " ..."
585 } >expected &&
587 test_config merge.summary yes &&
589 git checkout main &&
590 test_tick &&
591 git fetch . long &&
593 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
594 test_cmp expected actual
597 test_expect_success 'merge-msg with "merging" an annotated tag' '
598 test_config merge.log true &&
600 git checkout main^0 &&
601 git commit --allow-empty -m "One step ahead" &&
602 git tag -a -m "An annotated one" annote HEAD &&
604 git checkout main &&
605 git fetch . annote &&
607 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
609 cat <<-\EOF
610 Merge tag '\''annote'\''
612 An annotated one
614 * tag '\''annote'\'':
615 One step ahead
617 } >expected &&
618 test_cmp expected actual &&
620 test_when_finished "git reset --hard" &&
621 annote=$(git rev-parse annote) &&
622 git merge --no-commit --no-ff $annote &&
624 cat <<-EOF
625 Merge tag '\''$annote'\''
627 An annotated one
629 * tag '\''$annote'\'':
630 One step ahead
632 } >expected &&
633 test_cmp expected .git/MERGE_MSG
636 test_expect_success 'merge --into-name=<name>' '
637 test_when_finished "git checkout main" &&
638 git checkout -B side main &&
639 git commit --allow-empty -m "One step ahead" &&
641 git checkout --detach main &&
642 git merge --no-ff side &&
643 git show -s --format="%s" >full.0 &&
644 head -n1 full.0 >actual &&
645 # expect that HEAD is shown as-is
646 grep -e "Merge branch .side. into HEAD$" actual &&
648 git reset --hard main &&
649 git merge --no-ff --into-name=main side &&
650 git show -s --format="%s" >full.1 &&
651 head -n1 full.1 >actual &&
652 # expect that we pretend to be merging to main, that is suppressed
653 grep -e "Merge branch .side.$" actual &&
655 git checkout -b throwaway main &&
656 git merge --no-ff --into-name=main side &&
657 git show -s --format="%s" >full.2 &&
658 head -n1 full.2 >actual &&
659 # expect that we pretend to be merging to main, that is suppressed
660 grep -e "Merge branch .side.$" actual
663 test_expect_success 'merge.suppressDest configuration' '
664 test_when_finished "git checkout main" &&
665 git checkout -B side main &&
666 git commit --allow-empty -m "One step ahead" &&
667 git checkout main &&
668 git fetch . side &&
670 git -c merge.suppressDest="" fmt-merge-msg <.git/FETCH_HEAD >full.1 &&
671 head -n1 full.1 >actual &&
672 grep -e "Merge branch .side. into main" actual &&
674 git -c merge.suppressDest="mast" fmt-merge-msg <.git/FETCH_HEAD >full.2 &&
675 head -n1 full.2 >actual &&
676 grep -e "Merge branch .side. into main$" actual &&
678 git -c merge.suppressDest="ma?*[rn]" fmt-merge-msg <.git/FETCH_HEAD >full.3 &&
679 head -n1 full.3 >actual &&
680 grep -e "Merge branch .side." actual &&
681 ! grep -e " into main$" actual &&
683 git checkout --detach HEAD &&
684 git -c merge.suppressDest="main" fmt-merge-msg <.git/FETCH_HEAD >full.4 &&
685 head -n1 full.4 >actual &&
686 grep -e "Merge branch .side. into HEAD$" actual &&
688 git -c merge.suppressDest="main" fmt-merge-msg \
689 --into-name=main <.git/FETCH_HEAD >full.5 &&
690 head -n1 full.5 >actual &&
691 grep -e "Merge branch .side." actual &&
692 ! grep -e " into main$" actual &&
693 ! grep -e " into HEAD$" actual
696 test_done