t7503: add tests for pre-merge-hook
[git/mjg.git] / t / t6200-fmt-merge-msg.sh
blob8a72b4c43a4ff5ba2e2aeb99121ba8ba054dc396
1 #!/bin/sh
3 # Copyright (c) 2006, Junio C Hamano
6 test_description='fmt-merge-msg test'
8 . ./test-lib.sh
10 test_expect_success setup '
11 echo one >one &&
12 git add one &&
13 test_tick &&
14 git commit -m "Initial" &&
16 git clone . remote &&
18 echo uno >one &&
19 echo dos >two &&
20 git add two &&
21 test_tick &&
22 git commit -a -m "Second" &&
24 git checkout -b left &&
26 echo "c1" >one &&
27 test_tick &&
28 git commit -a -m "Common #1" &&
30 echo "c2" >one &&
31 test_tick &&
32 git commit -a -m "Common #2" &&
34 git branch right &&
36 echo "l3" >two &&
37 test_tick &&
38 GIT_COMMITTER_NAME="Another Committer" \
39 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
41 echo "l4" >two &&
42 test_tick &&
43 GIT_COMMITTER_NAME="Another Committer" \
44 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
46 echo "l5" >two &&
47 test_tick &&
48 GIT_COMMITTER_NAME="Another Committer" \
49 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
50 git tag tag-l5 &&
52 git checkout right &&
54 echo "r3" >three &&
55 git add three &&
56 test_tick &&
57 git commit -a -m "Right #3" &&
58 git tag tag-r3 &&
60 echo "r4" >three &&
61 test_tick &&
62 git commit -a -m "Right #4" &&
64 echo "r5" >three &&
65 test_tick &&
66 git commit -a -m "Right #5" &&
68 git checkout -b long &&
69 test_commit_bulk --start=0 --message=%s --filename=one 30 &&
71 git show-branch &&
73 apos="'\''"
76 test_expect_success 'message for merging local branch' '
77 echo "Merge branch ${apos}left${apos}" >expected &&
79 git checkout master &&
80 git fetch . left &&
82 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
83 test_cmp expected actual
86 test_expect_success 'message for merging external branch' '
87 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
89 git checkout master &&
90 git fetch "$(pwd)" left &&
92 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
93 test_cmp expected actual
96 test_expect_success '[merge] summary/log configuration' '
97 cat >expected <<-EOF &&
98 Merge branch ${apos}left${apos}
100 # By Another Author (3) and A U Thor (2)
101 # Via Another Committer
102 * left:
103 Left #5
104 Left #4
105 Left #3
106 Common #2
107 Common #1
110 test_config merge.log true &&
111 test_unconfig merge.summary &&
113 git checkout master &&
114 test_tick &&
115 git fetch . left &&
117 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
119 test_unconfig merge.log &&
120 test_config merge.summary true &&
122 git checkout master &&
123 test_tick &&
124 git fetch . left &&
126 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
128 test_cmp expected actual1 &&
129 test_cmp expected actual2
132 test_expect_success 'setup FETCH_HEAD' '
133 git checkout master &&
134 test_tick &&
135 git fetch . left
138 test_expect_success 'merge.log=3 limits shortlog length' '
139 cat >expected <<-EOF &&
140 Merge branch ${apos}left${apos}
142 # By Another Author (3) and A U Thor (2)
143 # Via Another Committer
144 * left: (5 commits)
145 Left #5
146 Left #4
147 Left #3
151 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
152 test_cmp expected actual
155 test_expect_success 'merge.log=5 shows all 5 commits' '
156 cat >expected <<-EOF &&
157 Merge branch ${apos}left${apos}
159 # By Another Author (3) and A U Thor (2)
160 # Via Another Committer
161 * left:
162 Left #5
163 Left #4
164 Left #3
165 Common #2
166 Common #1
169 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
170 test_cmp expected actual
173 test_expect_success '--log=5 with custom comment character' '
174 cat >expected <<-EOF &&
175 Merge branch ${apos}left${apos}
177 x By Another Author (3) and A U Thor (2)
178 x Via Another Committer
179 * left:
180 Left #5
181 Left #4
182 Left #3
183 Common #2
184 Common #1
187 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
188 test_cmp expected actual
191 test_expect_success 'merge.log=0 disables shortlog' '
192 echo "Merge branch ${apos}left${apos}" >expected &&
193 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
194 test_cmp expected actual
197 test_expect_success '--log=3 limits shortlog length' '
198 cat >expected <<-EOF &&
199 Merge branch ${apos}left${apos}
201 # By Another Author (3) and A U Thor (2)
202 # Via Another Committer
203 * left: (5 commits)
204 Left #5
205 Left #4
206 Left #3
210 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
211 test_cmp expected actual
214 test_expect_success '--log=5 shows all 5 commits' '
215 cat >expected <<-EOF &&
216 Merge branch ${apos}left${apos}
218 # By Another Author (3) and A U Thor (2)
219 # Via Another Committer
220 * left:
221 Left #5
222 Left #4
223 Left #3
224 Common #2
225 Common #1
228 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
229 test_cmp expected actual
232 test_expect_success '--no-log disables shortlog' '
233 echo "Merge branch ${apos}left${apos}" >expected &&
234 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
235 test_cmp expected actual
238 test_expect_success '--log=0 disables shortlog' '
239 echo "Merge branch ${apos}left${apos}" >expected &&
240 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
241 test_cmp expected actual
244 test_expect_success 'fmt-merge-msg -m' '
245 echo "Sync with left" >expected &&
246 cat >expected.log <<-EOF &&
247 Sync with left
249 # By Another Author (3) and A U Thor (2)
250 # Via Another Committer
251 * ${apos}left${apos} of $(pwd):
252 Left #5
253 Left #4
254 Left #3
255 Common #2
256 Common #1
259 test_unconfig merge.log &&
260 test_unconfig merge.summary &&
261 git checkout master &&
262 git fetch "$(pwd)" left &&
263 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
264 git fmt-merge-msg --log -m "Sync with left" \
265 <.git/FETCH_HEAD >actual.log &&
266 test_config merge.log true &&
267 git fmt-merge-msg -m "Sync with left" \
268 <.git/FETCH_HEAD >actual.log-config &&
269 git fmt-merge-msg --no-log -m "Sync with left" \
270 <.git/FETCH_HEAD >actual.nolog &&
272 test_cmp expected actual &&
273 test_cmp expected.log actual.log &&
274 test_cmp expected.log actual.log-config &&
275 test_cmp expected actual.nolog
278 test_expect_success 'setup: expected shortlog for two branches' '
279 cat >expected <<-EOF
280 Merge branches ${apos}left${apos} and ${apos}right${apos}
282 # By Another Author (3) and A U Thor (2)
283 # Via Another Committer
284 * left:
285 Left #5
286 Left #4
287 Left #3
288 Common #2
289 Common #1
291 * right:
292 Right #5
293 Right #4
294 Right #3
295 Common #2
296 Common #1
300 test_expect_success 'shortlog for two branches' '
301 test_config merge.log true &&
302 test_unconfig merge.summary &&
303 git checkout master &&
304 test_tick &&
305 git fetch . left right &&
306 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
308 test_unconfig merge.log &&
309 test_config merge.summary true &&
310 git checkout master &&
311 test_tick &&
312 git fetch . left right &&
313 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
315 test_config merge.log yes &&
316 test_unconfig merge.summary &&
317 git checkout master &&
318 test_tick &&
319 git fetch . left right &&
320 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
322 test_unconfig merge.log &&
323 test_config merge.summary yes &&
324 git checkout master &&
325 test_tick &&
326 git fetch . left right &&
327 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
329 test_cmp expected actual1 &&
330 test_cmp expected actual2 &&
331 test_cmp expected actual3 &&
332 test_cmp expected actual4
335 test_expect_success 'merge-msg -F' '
336 test_unconfig merge.log &&
337 test_config merge.summary yes &&
338 git checkout master &&
339 test_tick &&
340 git fetch . left right &&
341 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
342 test_cmp expected actual
345 test_expect_success 'merge-msg -F in subdirectory' '
346 test_unconfig merge.log &&
347 test_config merge.summary yes &&
348 git checkout master &&
349 test_tick &&
350 git fetch . left right &&
351 mkdir sub &&
352 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
354 cd sub &&
355 git fmt-merge-msg -F FETCH_HEAD >../actual
356 ) &&
357 test_cmp expected actual
360 test_expect_success 'merge-msg with nothing to merge' '
361 test_unconfig merge.log &&
362 test_config merge.summary yes &&
365 cd remote &&
366 git checkout -b unrelated &&
367 test_tick &&
368 git fetch origin &&
369 git fmt-merge-msg <.git/FETCH_HEAD >../actual
370 ) &&
372 test_must_be_empty actual
375 test_expect_success 'merge-msg tag' '
376 cat >expected <<-EOF &&
377 Merge tag ${apos}tag-r3${apos}
379 * tag ${apos}tag-r3${apos}:
380 Right #3
381 Common #2
382 Common #1
385 test_unconfig merge.log &&
386 test_config merge.summary yes &&
388 git checkout master &&
389 test_tick &&
390 git fetch . tag tag-r3 &&
392 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
393 test_cmp expected actual
396 test_expect_success 'merge-msg two tags' '
397 cat >expected <<-EOF &&
398 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
400 * tag ${apos}tag-r3${apos}:
401 Right #3
402 Common #2
403 Common #1
405 # By Another Author (3) and A U Thor (2)
406 # Via Another Committer
407 * tag ${apos}tag-l5${apos}:
408 Left #5
409 Left #4
410 Left #3
411 Common #2
412 Common #1
415 test_unconfig merge.log &&
416 test_config merge.summary yes &&
418 git checkout master &&
419 test_tick &&
420 git fetch . tag tag-r3 tag tag-l5 &&
422 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
423 test_cmp expected actual
426 test_expect_success 'merge-msg tag and branch' '
427 cat >expected <<-EOF &&
428 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
430 * tag ${apos}tag-r3${apos}:
431 Right #3
432 Common #2
433 Common #1
435 # By Another Author (3) and A U Thor (2)
436 # Via Another Committer
437 * left:
438 Left #5
439 Left #4
440 Left #3
441 Common #2
442 Common #1
445 test_unconfig merge.log &&
446 test_config merge.summary yes &&
448 git checkout master &&
449 test_tick &&
450 git fetch . tag tag-r3 left &&
452 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
453 test_cmp expected actual
456 test_expect_success 'merge-msg lots of commits' '
458 cat <<-EOF &&
459 Merge branch ${apos}long${apos}
461 * long: (35 commits)
464 i=29 &&
465 while test $i -gt 9
467 echo " $i" &&
468 i=$(($i-1))
469 done &&
470 echo " ..."
471 } >expected &&
473 test_config merge.summary yes &&
475 git checkout master &&
476 test_tick &&
477 git fetch . long &&
479 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
480 test_cmp expected actual
483 test_expect_success 'merge-msg with "merging" an annotated tag' '
484 test_config merge.log true &&
486 git checkout master^0 &&
487 git commit --allow-empty -m "One step ahead" &&
488 git tag -a -m "An annotated one" annote HEAD &&
490 git checkout master &&
491 git fetch . annote &&
493 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
495 cat <<-\EOF
496 Merge tag '\''annote'\''
498 An annotated one
500 * tag '\''annote'\'':
501 One step ahead
503 } >expected &&
504 test_cmp expected actual &&
506 test_when_finished "git reset --hard" &&
507 annote=$(git rev-parse annote) &&
508 git merge --no-commit --no-ff $annote &&
510 cat <<-EOF
511 Merge tag '\''$annote'\''
513 An annotated one
515 * tag '\''$annote'\'':
516 One step ahead
518 } >expected &&
519 test_cmp expected .git/MERGE_MSG
522 test_done