commit-graph: when incompatible with graphs, indicate why
[git] / t / t6200-fmt-merge-msg.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006, Junio C Hamano
4 #
5
6 test_description='fmt-merge-msg test'
7
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY/lib-gpg.sh"
10
11 test_expect_success setup '
12         echo one >one &&
13         git add one &&
14         test_tick &&
15         git commit -m "Initial" &&
16
17         git clone . remote &&
18
19         echo uno >one &&
20         echo dos >two &&
21         git add two &&
22         test_tick &&
23         git commit -a -m "Second" &&
24
25         git checkout -b left &&
26
27         echo "c1" >one &&
28         test_tick &&
29         git commit -a -m "Common #1" &&
30
31         echo "c2" >one &&
32         test_tick &&
33         git commit -a -m "Common #2" &&
34
35         git branch right &&
36
37         echo "l3" >two &&
38         test_tick &&
39         GIT_COMMITTER_NAME="Another Committer" \
40         GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
41
42         echo "l4" >two &&
43         test_tick &&
44         GIT_COMMITTER_NAME="Another Committer" \
45         GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
46
47         echo "l5" >two &&
48         test_tick &&
49         GIT_COMMITTER_NAME="Another Committer" \
50         GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
51         git tag tag-l5 &&
52
53         git checkout right &&
54
55         echo "r3" >three &&
56         git add three &&
57         test_tick &&
58         git commit -a -m "Right #3" &&
59         git tag tag-r3 &&
60
61         echo "r4" >three &&
62         test_tick &&
63         git commit -a -m "Right #4" &&
64
65         echo "r5" >three &&
66         test_tick &&
67         git commit -a -m "Right #5" &&
68
69         git checkout -b long &&
70         test_commit_bulk --start=0 --message=%s --filename=one 30 &&
71
72         git show-branch &&
73
74         apos="'\''"
75 '
76
77 test_expect_success GPG 'set up a signed tag' '
78         git tag -s -m signed-tag-msg signed-good-tag left
79 '
80
81 test_expect_success 'message for merging local branch' '
82         echo "Merge branch ${apos}left${apos}" >expected &&
83
84         git checkout master &&
85         git fetch . left &&
86
87         git fmt-merge-msg <.git/FETCH_HEAD >actual &&
88         test_cmp expected actual
89 '
90
91 test_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
100 test_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 &&
106         grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual
107 '
108
109 test_expect_success 'message for merging external branch' '
110         echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
111
112         git checkout master &&
113         git fetch "$(pwd)" left &&
114
115         git fmt-merge-msg <.git/FETCH_HEAD >actual &&
116         test_cmp expected actual
117 '
118
119 test_expect_success '[merge] summary/log configuration' '
120         cat >expected <<-EOF &&
121         Merge branch ${apos}left${apos}
122
123         # By Another Author (3) and A U Thor (2)
124         # Via Another Committer
125         * left:
126           Left #5
127           Left #4
128           Left #3
129           Common #2
130           Common #1
131         EOF
132
133         test_config merge.log true &&
134         test_unconfig merge.summary &&
135
136         git checkout master &&
137         test_tick &&
138         git fetch . left &&
139
140         git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
141
142         test_unconfig merge.log &&
143         test_config merge.summary true &&
144
145         git checkout master &&
146         test_tick &&
147         git fetch . left &&
148
149         git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
150
151         test_cmp expected actual1 &&
152         test_cmp expected actual2
153 '
154
155 test_expect_success 'setup FETCH_HEAD' '
156         git checkout master &&
157         test_tick &&
158         git fetch . left
159 '
160
161 test_expect_success 'merge.log=3 limits shortlog length' '
162         cat >expected <<-EOF &&
163         Merge branch ${apos}left${apos}
164
165         # By Another Author (3) and A U Thor (2)
166         # Via Another Committer
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
178 test_expect_success 'merge.log=5 shows all 5 commits' '
179         cat >expected <<-EOF &&
180         Merge branch ${apos}left${apos}
181
182         # By Another Author (3) and A U Thor (2)
183         # Via Another Committer
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
196 test_expect_success '--log=5 with custom comment character' '
197         cat >expected <<-EOF &&
198         Merge branch ${apos}left${apos}
199
200         x By Another Author (3) and A U Thor (2)
201         x Via Another Committer
202         * left:
203           Left #5
204           Left #4
205           Left #3
206           Common #2
207           Common #1
208         EOF
209
210         git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
211         test_cmp expected actual
212 '
213
214 test_expect_success 'merge.log=0 disables shortlog' '
215         echo "Merge branch ${apos}left${apos}" >expected &&
216         git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
217         test_cmp expected actual
218 '
219
220 test_expect_success '--log=3 limits shortlog length' '
221         cat >expected <<-EOF &&
222         Merge branch ${apos}left${apos}
223
224         # By Another Author (3) and A U Thor (2)
225         # Via Another Committer
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
237 test_expect_success '--log=5 shows all 5 commits' '
238         cat >expected <<-EOF &&
239         Merge branch ${apos}left${apos}
240
241         # By Another Author (3) and A U Thor (2)
242         # Via Another Committer
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
255 test_expect_success '--no-log disables shortlog' '
256         echo "Merge branch ${apos}left${apos}" >expected &&
257         git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
258         test_cmp expected actual
259 '
260
261 test_expect_success '--log=0 disables shortlog' '
262         echo "Merge branch ${apos}left${apos}" >expected &&
263         git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
264         test_cmp expected actual
265 '
266
267 test_expect_success 'fmt-merge-msg -m' '
268         echo "Sync with left" >expected &&
269         cat >expected.log <<-EOF &&
270         Sync with left
271
272         # By Another Author (3) and A U Thor (2)
273         # Via Another Committer
274         * ${apos}left${apos} of $(pwd):
275           Left #5
276           Left #4
277           Left #3
278           Common #2
279           Common #1
280         EOF
281
282         test_unconfig merge.log &&
283         test_unconfig merge.summary &&
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 &&
289         test_config merge.log true &&
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
301 test_expect_success 'setup: expected shortlog for two branches' '
302         cat >expected <<-EOF
303         Merge branches ${apos}left${apos} and ${apos}right${apos}
304
305         # By Another Author (3) and A U Thor (2)
306         # Via Another Committer
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 '
322
323 test_expect_success 'shortlog for two branches' '
324         test_config merge.log true &&
325         test_unconfig merge.summary &&
326         git checkout master &&
327         test_tick &&
328         git fetch . left right &&
329         git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
330
331         test_unconfig merge.log &&
332         test_config merge.summary true &&
333         git checkout master &&
334         test_tick &&
335         git fetch . left right &&
336         git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
337
338         test_config merge.log yes &&
339         test_unconfig merge.summary &&
340         git checkout master &&
341         test_tick &&
342         git fetch . left right &&
343         git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
344
345         test_unconfig merge.log &&
346         test_config merge.summary yes &&
347         git checkout master &&
348         test_tick &&
349         git fetch . left right &&
350         git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
351
352         test_cmp expected actual1 &&
353         test_cmp expected actual2 &&
354         test_cmp expected actual3 &&
355         test_cmp expected actual4
356 '
357
358 test_expect_success 'merge-msg -F' '
359         test_unconfig merge.log &&
360         test_config merge.summary yes &&
361         git checkout master &&
362         test_tick &&
363         git fetch . left right &&
364         git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
365         test_cmp expected actual
366 '
367
368 test_expect_success 'merge-msg -F in subdirectory' '
369         test_unconfig merge.log &&
370         test_config merge.summary yes &&
371         git checkout master &&
372         test_tick &&
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
383 test_expect_success 'merge-msg with nothing to merge' '
384         test_unconfig merge.log &&
385         test_config merge.summary yes &&
386
387         (
388                 cd remote &&
389                 git checkout -b unrelated &&
390                 test_tick &&
391                 git fetch origin &&
392                 git fmt-merge-msg <.git/FETCH_HEAD >../actual
393         ) &&
394
395         test_must_be_empty actual
396 '
397
398 test_expect_success 'merge-msg tag' '
399         cat >expected <<-EOF &&
400         Merge tag ${apos}tag-r3${apos}
401
402         * tag ${apos}tag-r3${apos}:
403           Right #3
404           Common #2
405           Common #1
406         EOF
407
408         test_unconfig merge.log &&
409         test_config merge.summary yes &&
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
419 test_expect_success 'merge-msg two tags' '
420         cat >expected <<-EOF &&
421         Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
422
423         * tag ${apos}tag-r3${apos}:
424           Right #3
425           Common #2
426           Common #1
427
428         # By Another Author (3) and A U Thor (2)
429         # Via Another Committer
430         * tag ${apos}tag-l5${apos}:
431           Left #5
432           Left #4
433           Left #3
434           Common #2
435           Common #1
436         EOF
437
438         test_unconfig merge.log &&
439         test_config merge.summary yes &&
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
449 test_expect_success 'merge-msg tag and branch' '
450         cat >expected <<-EOF &&
451         Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
452
453         * tag ${apos}tag-r3${apos}:
454           Right #3
455           Common #2
456           Common #1
457
458         # By Another Author (3) and A U Thor (2)
459         # Via Another Committer
460         * left:
461           Left #5
462           Left #4
463           Left #3
464           Common #2
465           Common #1
466         EOF
467
468         test_unconfig merge.log &&
469         test_config merge.summary yes &&
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
479 test_expect_success 'merge-msg lots of commits' '
480         {
481                 cat <<-EOF &&
482                 Merge branch ${apos}long${apos}
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 &&
495
496         test_config merge.summary yes &&
497
498         git checkout master &&
499         test_tick &&
500         git fetch . long &&
501
502         git fmt-merge-msg <.git/FETCH_HEAD >actual &&
503         test_cmp expected actual
504 '
505
506 test_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
519                 Merge tag '\''annote'\''
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) &&
531         git merge --no-commit --no-ff $annote &&
532         {
533                 cat <<-EOF
534                 Merge tag '\''$annote'\''
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
545 test_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?*[rn]" 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
565 test_done