Merge branch 'russian-l10n' of github.com:DJm00n/git-po-ru
[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 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 . ./test-lib.sh
12 . "$TEST_DIRECTORY/lib-gpg.sh"
13
14 test_expect_success setup '
15         echo one >one &&
16         git add one &&
17         test_tick &&
18         git commit -m "Initial" &&
19
20         git clone . remote &&
21
22         echo uno >one &&
23         echo dos >two &&
24         git add two &&
25         test_tick &&
26         git commit -a -m "Second" &&
27
28         git checkout -b left &&
29
30         echo "c1" >one &&
31         test_tick &&
32         git commit -a -m "Common #1" &&
33
34         echo "c2" >one &&
35         test_tick &&
36         git commit -a -m "Common #2" &&
37
38         git branch right &&
39
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" &&
44
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" &&
49
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 &&
55
56         git checkout right &&
57
58         echo "r3" >three &&
59         git add three &&
60         test_tick &&
61         git commit -a -m "Right #3" &&
62         git tag tag-r3 &&
63
64         echo "r4" >three &&
65         test_tick &&
66         git commit -a -m "Right #4" &&
67
68         echo "r5" >three &&
69         test_tick &&
70         git commit -a -m "Right #5" &&
71
72         git checkout -b long &&
73         test_commit_bulk --start=0 --message=%s --filename=one 30 &&
74
75         git show-branch &&
76
77         apos="'\''"
78 '
79
80 test_expect_success GPG 'set up a signed tag' '
81         git tag -s -m signed-tag-msg signed-good-tag left
82 '
83
84 test_expect_success 'message for merging local branch' '
85         echo "Merge branch ${apos}left${apos}" >expected &&
86
87         git checkout main &&
88         git fetch . left &&
89
90         git fmt-merge-msg <.git/FETCH_HEAD >actual &&
91         test_cmp expected actual
92 '
93
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
101 '
102
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
110 '
111
112 test_expect_success 'message for merging external branch' '
113         echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
114
115         git checkout main &&
116         git fetch "$(pwd)" left &&
117
118         git fmt-merge-msg <.git/FETCH_HEAD >actual &&
119         test_cmp expected actual
120 '
121
122 test_expect_success '[merge] summary/log configuration' '
123         cat >expected <<-EOF &&
124         Merge branch ${apos}left${apos}
125
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
134         EOF
135
136         test_config merge.log true &&
137         test_unconfig merge.summary &&
138
139         git checkout main &&
140         test_tick &&
141         git fetch . left &&
142
143         git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
144
145         test_unconfig merge.log &&
146         test_config merge.summary true &&
147
148         git checkout main &&
149         test_tick &&
150         git fetch . left &&
151
152         git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
153
154         test_cmp expected actual1 &&
155         test_cmp expected actual2
156 '
157
158 test_expect_success 'setup FETCH_HEAD' '
159         git checkout main &&
160         test_tick &&
161         git fetch . left
162 '
163
164 test_expect_success 'merge.log=3 limits shortlog length' '
165         cat >expected <<-EOF &&
166         Merge branch ${apos}left${apos}
167
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
174           ...
175         EOF
176
177         git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
178         test_cmp expected actual
179 '
180
181 test_expect_success 'merge.log=5 shows all 5 commits' '
182         cat >expected <<-EOF &&
183         Merge branch ${apos}left${apos}
184
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
193         EOF
194
195         git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
196         test_cmp expected actual
197 '
198
199 test_expect_success '--log=5 with custom comment character' '
200         cat >expected <<-EOF &&
201         Merge branch ${apos}left${apos}
202
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
211         EOF
212
213         git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
214         test_cmp expected actual
215 '
216
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
221 '
222
223 test_expect_success '--log=3 limits shortlog length' '
224         cat >expected <<-EOF &&
225         Merge branch ${apos}left${apos}
226
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
233           ...
234         EOF
235
236         git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
237         test_cmp expected actual
238 '
239
240 test_expect_success '--log=5 shows all 5 commits' '
241         cat >expected <<-EOF &&
242         Merge branch ${apos}left${apos}
243
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
252         EOF
253
254         git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
255         test_cmp expected actual
256 '
257
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
262 '
263
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
268 '
269
270 test_expect_success 'fmt-merge-msg -m' '
271         echo "Sync with left" >expected &&
272         cat >expected.log <<-EOF &&
273         Sync with left
274
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
283         EOF
284
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 &&
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
304 test_expect_success 'setup: expected shortlog for two branches' '
305         cat >expected <<-EOF
306         Merge branches ${apos}left${apos} and ${apos}right${apos}
307
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
316
317         * right:
318           Right #5
319           Right #4
320           Right #3
321           Common #2
322           Common #1
323         EOF
324 '
325
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 &&
333
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 &&
340
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 &&
347
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 &&
354
355         test_cmp expected actual1 &&
356         test_cmp expected actual2 &&
357         test_cmp expected actual3 &&
358         test_cmp expected actual4
359 '
360
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
369 '
370
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 &&
379         (
380                 cd sub &&
381                 git fmt-merge-msg -F FETCH_HEAD >../actual
382         ) &&
383         test_cmp expected actual
384 '
385
386 test_expect_success 'merge-msg with nothing to merge' '
387         test_unconfig merge.log &&
388         test_config merge.summary yes &&
389
390         (
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         ) &&
397
398         test_must_be_empty actual
399 '
400
401 test_expect_success 'merge-msg tag' '
402         cat >expected <<-EOF &&
403         Merge tag ${apos}tag-r3${apos}
404
405         * tag ${apos}tag-r3${apos}:
406           Right #3
407           Common #2
408           Common #1
409         EOF
410
411         test_unconfig merge.log &&
412         test_config merge.summary yes &&
413
414         git checkout main &&
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
422 test_expect_success 'merge-msg two tags' '
423         cat >expected <<-EOF &&
424         Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
425
426         * tag ${apos}tag-r3${apos}:
427           Right #3
428           Common #2
429           Common #1
430
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
439         EOF
440
441         test_unconfig merge.log &&
442         test_config merge.summary yes &&
443
444         git checkout main &&
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
452 test_expect_success 'merge-msg tag and branch' '
453         cat >expected <<-EOF &&
454         Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
455
456         * tag ${apos}tag-r3${apos}:
457           Right #3
458           Common #2
459           Common #1
460
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
469         EOF
470
471         test_unconfig merge.log &&
472         test_config merge.summary yes &&
473
474         git checkout main &&
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
482 test_expect_success 'merge-msg lots of commits' '
483         {
484                 cat <<-EOF &&
485                 Merge branch ${apos}long${apos}
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 &&
498
499         test_config merge.summary yes &&
500
501         git checkout main &&
502         test_tick &&
503         git fetch . long &&
504
505         git fmt-merge-msg <.git/FETCH_HEAD >actual &&
506         test_cmp expected actual
507 '
508
509 test_expect_success 'merge-msg with "merging" an annotated tag' '
510         test_config merge.log true &&
511
512         git checkout main^0 &&
513         git commit --allow-empty -m "One step ahead" &&
514         git tag -a -m "An annotated one" annote HEAD &&
515
516         git checkout main &&
517         git fetch . annote &&
518
519         git fmt-merge-msg <.git/FETCH_HEAD >actual &&
520         {
521                 cat <<-\EOF
522                 Merge tag '\''annote'\''
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) &&
534         git merge --no-commit --no-ff $annote &&
535         {
536                 cat <<-EOF
537                 Merge tag '\''$annote'\''
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
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 &&
553
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 &&
557
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 &&
561
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
566 '
567
568 test_done