t: avoid alternation (not POSIX) in grep's BRE
[git/debian.git] / t / t6200-fmt-merge-msg.sh
blobe4c2a6eca43564eea71a0a633b5494dd4626544f
1 #!/bin/sh
3 # Copyright (c) 2006, Junio C Hamano
6 test_description='fmt-merge-msg test'
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY/lib-gpg.sh"
11 test_expect_success setup '
12 echo one >one &&
13 git add one &&
14 test_tick &&
15 git commit -m "Initial" &&
17 git clone . remote &&
19 echo uno >one &&
20 echo dos >two &&
21 git add two &&
22 test_tick &&
23 git commit -a -m "Second" &&
25 git checkout -b left &&
27 echo "c1" >one &&
28 test_tick &&
29 git commit -a -m "Common #1" &&
31 echo "c2" >one &&
32 test_tick &&
33 git commit -a -m "Common #2" &&
35 git branch right &&
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" &&
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" &&
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 &&
53 git checkout right &&
55 echo "r3" >three &&
56 git add three &&
57 test_tick &&
58 git commit -a -m "Right #3" &&
59 git tag tag-r3 &&
61 echo "r4" >three &&
62 test_tick &&
63 git commit -a -m "Right #4" &&
65 echo "r5" >three &&
66 test_tick &&
67 git commit -a -m "Right #5" &&
69 git checkout -b long &&
70 test_commit_bulk --start=0 --message=%s --filename=one 30 &&
72 git show-branch &&
74 apos="'\''"
77 test_expect_success GPG 'set up a signed tag' '
78 git tag -s -m signed-tag-msg signed-good-tag left
81 test_expect_success 'message for merging local branch' '
82 echo "Merge branch ${apos}left${apos}" >expected &&
84 git checkout master &&
85 git fetch . left &&
87 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
88 test_cmp expected actual
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
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
109 test_expect_success 'message for merging external branch' '
110 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
112 git checkout master &&
113 git fetch "$(pwd)" left &&
115 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
116 test_cmp expected actual
119 test_expect_success '[merge] summary/log configuration' '
120 cat >expected <<-EOF &&
121 Merge branch ${apos}left${apos}
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
133 test_config merge.log true &&
134 test_unconfig merge.summary &&
136 git checkout master &&
137 test_tick &&
138 git fetch . left &&
140 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
142 test_unconfig merge.log &&
143 test_config merge.summary true &&
145 git checkout master &&
146 test_tick &&
147 git fetch . left &&
149 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
151 test_cmp expected actual1 &&
152 test_cmp expected actual2
155 test_expect_success 'setup FETCH_HEAD' '
156 git checkout master &&
157 test_tick &&
158 git fetch . left
161 test_expect_success 'merge.log=3 limits shortlog length' '
162 cat >expected <<-EOF &&
163 Merge branch ${apos}left${apos}
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
174 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
175 test_cmp expected actual
178 test_expect_success 'merge.log=5 shows all 5 commits' '
179 cat >expected <<-EOF &&
180 Merge branch ${apos}left${apos}
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
192 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
193 test_cmp expected actual
196 test_expect_success '--log=5 with custom comment character' '
197 cat >expected <<-EOF &&
198 Merge branch ${apos}left${apos}
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
210 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
211 test_cmp expected actual
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
220 test_expect_success '--log=3 limits shortlog length' '
221 cat >expected <<-EOF &&
222 Merge branch ${apos}left${apos}
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
233 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
234 test_cmp expected actual
237 test_expect_success '--log=5 shows all 5 commits' '
238 cat >expected <<-EOF &&
239 Merge branch ${apos}left${apos}
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
251 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
252 test_cmp expected actual
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
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
267 test_expect_success 'fmt-merge-msg -m' '
268 echo "Sync with left" >expected &&
269 cat >expected.log <<-EOF &&
270 Sync with left
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
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 &&
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
301 test_expect_success 'setup: expected shortlog for two branches' '
302 cat >expected <<-EOF
303 Merge branches ${apos}left${apos} and ${apos}right${apos}
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
314 * right:
315 Right #5
316 Right #4
317 Right #3
318 Common #2
319 Common #1
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 &&
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 &&
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 &&
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 &&
352 test_cmp expected actual1 &&
353 test_cmp expected actual2 &&
354 test_cmp expected actual3 &&
355 test_cmp expected actual4
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
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 &&
377 cd sub &&
378 git fmt-merge-msg -F FETCH_HEAD >../actual
379 ) &&
380 test_cmp expected actual
383 test_expect_success 'merge-msg with nothing to merge' '
384 test_unconfig merge.log &&
385 test_config merge.summary yes &&
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 ) &&
395 test_must_be_empty actual
398 test_expect_success 'merge-msg tag' '
399 cat >expected <<-EOF &&
400 Merge tag ${apos}tag-r3${apos}
402 * tag ${apos}tag-r3${apos}:
403 Right #3
404 Common #2
405 Common #1
408 test_unconfig merge.log &&
409 test_config merge.summary yes &&
411 git checkout master &&
412 test_tick &&
413 git fetch . tag tag-r3 &&
415 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
416 test_cmp expected actual
419 test_expect_success 'merge-msg two tags' '
420 cat >expected <<-EOF &&
421 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
423 * tag ${apos}tag-r3${apos}:
424 Right #3
425 Common #2
426 Common #1
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
438 test_unconfig merge.log &&
439 test_config merge.summary yes &&
441 git checkout master &&
442 test_tick &&
443 git fetch . tag tag-r3 tag tag-l5 &&
445 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
446 test_cmp expected actual
449 test_expect_success 'merge-msg tag and branch' '
450 cat >expected <<-EOF &&
451 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
453 * tag ${apos}tag-r3${apos}:
454 Right #3
455 Common #2
456 Common #1
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
468 test_unconfig merge.log &&
469 test_config merge.summary yes &&
471 git checkout master &&
472 test_tick &&
473 git fetch . tag tag-r3 left &&
475 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
476 test_cmp expected actual
479 test_expect_success 'merge-msg lots of commits' '
481 cat <<-EOF &&
482 Merge branch ${apos}long${apos}
484 * long: (35 commits)
487 i=29 &&
488 while test $i -gt 9
490 echo " $i" &&
491 i=$(($i-1))
492 done &&
493 echo " ..."
494 } >expected &&
496 test_config merge.summary yes &&
498 git checkout master &&
499 test_tick &&
500 git fetch . long &&
502 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
503 test_cmp expected actual
506 test_expect_success 'merge-msg with "merging" an annotated tag' '
507 test_config merge.log true &&
509 git checkout master^0 &&
510 git commit --allow-empty -m "One step ahead" &&
511 git tag -a -m "An annotated one" annote HEAD &&
513 git checkout master &&
514 git fetch . annote &&
516 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
518 cat <<-\EOF
519 Merge tag '\''annote'\''
521 An annotated one
523 * tag '\''annote'\'':
524 One step ahead
526 } >expected &&
527 test_cmp expected actual &&
529 test_when_finished "git reset --hard" &&
530 annote=$(git rev-parse annote) &&
531 git merge --no-commit --no-ff $annote &&
533 cat <<-EOF
534 Merge tag '\''$annote'\''
536 An annotated one
538 * tag '\''$annote'\'':
539 One step ahead
541 } >expected &&
542 test_cmp expected .git/MERGE_MSG
545 test_done