Merge branch 'js/commit-graph-warning'
[git/debian.git] / t / t6200-fmt-merge-msg.sh
blob44f55d93fefbc766feca7e264df9319f7591feb9
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 'message for merging local branch' '
85 echo "Merge branch ${apos}left${apos}" >expected &&
87 git checkout main &&
88 git fetch . left &&
90 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
91 test_cmp expected actual
94 test_expect_success GPG 'message for merging local tag signed by good key' '
95 git checkout main &&
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
103 test_expect_success GPG 'message for merging local tag signed by unknown key' '
104 git checkout main &&
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 &&
109 grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual
112 test_expect_success 'message for merging external branch' '
113 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
115 git checkout main &&
116 git fetch "$(pwd)" left &&
118 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
119 test_cmp expected actual
122 test_expect_success '[merge] summary/log configuration' '
123 cat >expected <<-EOF &&
124 Merge branch ${apos}left${apos}
126 # By Another Author (3) and A U Thor (2)
127 # Via Another Committer
128 * left:
129 Left #5
130 Left #4
131 Left #3
132 Common #2
133 Common #1
136 test_config merge.log true &&
137 test_unconfig merge.summary &&
139 git checkout main &&
140 test_tick &&
141 git fetch . left &&
143 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
145 test_unconfig merge.log &&
146 test_config merge.summary true &&
148 git checkout main &&
149 test_tick &&
150 git fetch . left &&
152 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
154 test_cmp expected actual1 &&
155 test_cmp expected actual2
158 test_expect_success 'setup FETCH_HEAD' '
159 git checkout main &&
160 test_tick &&
161 git fetch . left
164 test_expect_success 'merge.log=3 limits shortlog length' '
165 cat >expected <<-EOF &&
166 Merge branch ${apos}left${apos}
168 # By Another Author (3) and A U Thor (2)
169 # Via Another Committer
170 * left: (5 commits)
171 Left #5
172 Left #4
173 Left #3
177 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
178 test_cmp expected actual
181 test_expect_success 'merge.log=5 shows all 5 commits' '
182 cat >expected <<-EOF &&
183 Merge branch ${apos}left${apos}
185 # By Another Author (3) and A U Thor (2)
186 # Via Another Committer
187 * left:
188 Left #5
189 Left #4
190 Left #3
191 Common #2
192 Common #1
195 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
196 test_cmp expected actual
199 test_expect_success '--log=5 with custom comment character' '
200 cat >expected <<-EOF &&
201 Merge branch ${apos}left${apos}
203 x By Another Author (3) and A U Thor (2)
204 x Via Another Committer
205 * left:
206 Left #5
207 Left #4
208 Left #3
209 Common #2
210 Common #1
213 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
214 test_cmp expected actual
217 test_expect_success 'merge.log=0 disables shortlog' '
218 echo "Merge branch ${apos}left${apos}" >expected &&
219 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
220 test_cmp expected actual
223 test_expect_success '--log=3 limits shortlog length' '
224 cat >expected <<-EOF &&
225 Merge branch ${apos}left${apos}
227 # By Another Author (3) and A U Thor (2)
228 # Via Another Committer
229 * left: (5 commits)
230 Left #5
231 Left #4
232 Left #3
236 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
237 test_cmp expected actual
240 test_expect_success '--log=5 shows all 5 commits' '
241 cat >expected <<-EOF &&
242 Merge branch ${apos}left${apos}
244 # By Another Author (3) and A U Thor (2)
245 # Via Another Committer
246 * left:
247 Left #5
248 Left #4
249 Left #3
250 Common #2
251 Common #1
254 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
255 test_cmp expected actual
258 test_expect_success '--no-log disables shortlog' '
259 echo "Merge branch ${apos}left${apos}" >expected &&
260 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
261 test_cmp expected actual
264 test_expect_success '--log=0 disables shortlog' '
265 echo "Merge branch ${apos}left${apos}" >expected &&
266 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
267 test_cmp expected actual
270 test_expect_success 'fmt-merge-msg -m' '
271 echo "Sync with left" >expected &&
272 cat >expected.log <<-EOF &&
273 Sync with left
275 # By Another Author (3) and A U Thor (2)
276 # Via Another Committer
277 * ${apos}left${apos} of $(pwd):
278 Left #5
279 Left #4
280 Left #3
281 Common #2
282 Common #1
285 test_unconfig merge.log &&
286 test_unconfig merge.summary &&
287 git checkout main &&
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 &&
292 test_config merge.log true &&
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 &&
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
304 test_expect_success 'setup: expected shortlog for two branches' '
305 cat >expected <<-EOF
306 Merge branches ${apos}left${apos} and ${apos}right${apos}
308 # By Another Author (3) and A U Thor (2)
309 # Via Another Committer
310 * left:
311 Left #5
312 Left #4
313 Left #3
314 Common #2
315 Common #1
317 * right:
318 Right #5
319 Right #4
320 Right #3
321 Common #2
322 Common #1
326 test_expect_success 'shortlog for two branches' '
327 test_config merge.log true &&
328 test_unconfig merge.summary &&
329 git checkout main &&
330 test_tick &&
331 git fetch . left right &&
332 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
334 test_unconfig merge.log &&
335 test_config merge.summary true &&
336 git checkout main &&
337 test_tick &&
338 git fetch . left right &&
339 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
341 test_config merge.log yes &&
342 test_unconfig merge.summary &&
343 git checkout main &&
344 test_tick &&
345 git fetch . left right &&
346 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
348 test_unconfig merge.log &&
349 test_config merge.summary yes &&
350 git checkout main &&
351 test_tick &&
352 git fetch . left right &&
353 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
355 test_cmp expected actual1 &&
356 test_cmp expected actual2 &&
357 test_cmp expected actual3 &&
358 test_cmp expected actual4
361 test_expect_success 'merge-msg -F' '
362 test_unconfig merge.log &&
363 test_config merge.summary yes &&
364 git checkout main &&
365 test_tick &&
366 git fetch . left right &&
367 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
368 test_cmp expected actual
371 test_expect_success 'merge-msg -F in subdirectory' '
372 test_unconfig merge.log &&
373 test_config merge.summary yes &&
374 git checkout main &&
375 test_tick &&
376 git fetch . left right &&
377 mkdir sub &&
378 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
380 cd sub &&
381 git fmt-merge-msg -F FETCH_HEAD >../actual
382 ) &&
383 test_cmp expected actual
386 test_expect_success 'merge-msg with nothing to merge' '
387 test_unconfig merge.log &&
388 test_config merge.summary yes &&
391 cd remote &&
392 git checkout -b unrelated &&
393 test_tick &&
394 git fetch origin &&
395 git fmt-merge-msg <.git/FETCH_HEAD >../actual
396 ) &&
398 test_must_be_empty actual
401 test_expect_success 'merge-msg tag' '
402 cat >expected <<-EOF &&
403 Merge tag ${apos}tag-r3${apos}
405 * tag ${apos}tag-r3${apos}:
406 Right #3
407 Common #2
408 Common #1
411 test_unconfig merge.log &&
412 test_config merge.summary yes &&
414 git checkout main &&
415 test_tick &&
416 git fetch . tag tag-r3 &&
418 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
419 test_cmp expected actual
422 test_expect_success 'merge-msg two tags' '
423 cat >expected <<-EOF &&
424 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
426 * tag ${apos}tag-r3${apos}:
427 Right #3
428 Common #2
429 Common #1
431 # By Another Author (3) and A U Thor (2)
432 # Via Another Committer
433 * tag ${apos}tag-l5${apos}:
434 Left #5
435 Left #4
436 Left #3
437 Common #2
438 Common #1
441 test_unconfig merge.log &&
442 test_config merge.summary yes &&
444 git checkout main &&
445 test_tick &&
446 git fetch . tag tag-r3 tag tag-l5 &&
448 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
449 test_cmp expected actual
452 test_expect_success 'merge-msg tag and branch' '
453 cat >expected <<-EOF &&
454 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
456 * tag ${apos}tag-r3${apos}:
457 Right #3
458 Common #2
459 Common #1
461 # By Another Author (3) and A U Thor (2)
462 # Via Another Committer
463 * left:
464 Left #5
465 Left #4
466 Left #3
467 Common #2
468 Common #1
471 test_unconfig merge.log &&
472 test_config merge.summary yes &&
474 git checkout main &&
475 test_tick &&
476 git fetch . tag tag-r3 left &&
478 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
479 test_cmp expected actual
482 test_expect_success 'merge-msg lots of commits' '
484 cat <<-EOF &&
485 Merge branch ${apos}long${apos}
487 * long: (35 commits)
490 i=29 &&
491 while test $i -gt 9
493 echo " $i" &&
494 i=$(($i-1))
495 done &&
496 echo " ..."
497 } >expected &&
499 test_config merge.summary yes &&
501 git checkout main &&
502 test_tick &&
503 git fetch . long &&
505 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
506 test_cmp expected actual
509 test_expect_success 'merge-msg with "merging" an annotated tag' '
510 test_config merge.log true &&
512 git checkout main^0 &&
513 git commit --allow-empty -m "One step ahead" &&
514 git tag -a -m "An annotated one" annote HEAD &&
516 git checkout main &&
517 git fetch . annote &&
519 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
521 cat <<-\EOF
522 Merge tag '\''annote'\''
524 An annotated one
526 * tag '\''annote'\'':
527 One step ahead
529 } >expected &&
530 test_cmp expected actual &&
532 test_when_finished "git reset --hard" &&
533 annote=$(git rev-parse annote) &&
534 git merge --no-commit --no-ff $annote &&
536 cat <<-EOF
537 Merge tag '\''$annote'\''
539 An annotated one
541 * tag '\''$annote'\'':
542 One step ahead
544 } >expected &&
545 test_cmp expected .git/MERGE_MSG
548 test_expect_success 'merge.suppressDest configuration' '
549 git checkout -B side main &&
550 git commit --allow-empty -m "One step ahead" &&
551 git checkout main &&
552 git fetch . side &&
554 git -c merge.suppressDest="" fmt-merge-msg <.git/FETCH_HEAD >full.1 &&
555 head -n1 full.1 >actual &&
556 grep -e "Merge branch .side. into main" actual &&
558 git -c merge.suppressDest="mast" fmt-merge-msg <.git/FETCH_HEAD >full.2 &&
559 head -n1 full.2 >actual &&
560 grep -e "Merge branch .side. into main$" actual &&
562 git -c merge.suppressDest="ma?*[rn]" fmt-merge-msg <.git/FETCH_HEAD >full.3 &&
563 head -n1 full.3 >actual &&
564 grep -e "Merge branch .side." actual &&
565 ! grep -e " into main$" actual
568 test_done