blob: 992c2a04674d474a8875da955935512ec99f335a [file] [log] [blame]
Junio C Hamano30a95f32006-07-03 18:09:54 -07001#!/bin/sh
2#
3# Copyright (c) 2006, Junio C Hamano
4#
5
6test_description='fmt-merge-msg test'
7
8. ./test-lib.sh
9
Junio C Hamano30a95f32006-07-03 18:09:54 -070010test_expect_success setup '
11 echo one >one &&
12 git add one &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -070013 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070014 git commit -m "Initial" &&
15
Stephen Boyd419fe5b2010-03-24 00:15:58 -070016 git clone . remote &&
17
Junio C Hamano30a95f32006-07-03 18:09:54 -070018 echo uno >one &&
19 echo dos >two &&
20 git add two &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -070021 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070022 git commit -a -m "Second" &&
23
24 git checkout -b left &&
25
Stephen Boyd6183a6a2010-03-24 00:15:59 -070026 echo "c1" >one &&
27 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070028 git commit -a -m "Common #1" &&
29
Stephen Boyd6183a6a2010-03-24 00:15:59 -070030 echo "c2" >one &&
31 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070032 git commit -a -m "Common #2" &&
33
34 git branch right &&
35
Stephen Boyd6183a6a2010-03-24 00:15:59 -070036 echo "l3" >two &&
37 test_tick &&
Junio C Hamano418a1432012-03-13 10:00:00 -070038 GIT_COMMITTER_NAME="Another Committer" \
39 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070040
Stephen Boyd6183a6a2010-03-24 00:15:59 -070041 echo "l4" >two &&
42 test_tick &&
Junio C Hamano418a1432012-03-13 10:00:00 -070043 GIT_COMMITTER_NAME="Another Committer" \
44 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070045
Stephen Boyd6183a6a2010-03-24 00:15:59 -070046 echo "l5" >two &&
47 test_tick &&
Junio C Hamano418a1432012-03-13 10:00:00 -070048 GIT_COMMITTER_NAME="Another Committer" \
49 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -070050 git tag tag-l5 &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070051
52 git checkout right &&
53
Stephen Boyd6183a6a2010-03-24 00:15:59 -070054 echo "r3" >three &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070055 git add three &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -070056 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070057 git commit -a -m "Right #3" &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -070058 git tag tag-r3 &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070059
Stephen Boyd6183a6a2010-03-24 00:15:59 -070060 echo "r4" >three &&
61 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070062 git commit -a -m "Right #4" &&
63
Stephen Boyd6183a6a2010-03-24 00:15:59 -070064 echo "r5" >three &&
65 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070066 git commit -a -m "Right #5" &&
67
Stephen Boyd6d6f6e62010-03-24 00:16:00 -070068 git checkout -b long &&
69 i=0 &&
70 while test $i -lt 30
71 do
72 test_commit $i one &&
73 i=$(($i+1))
74 done &&
75
Jonathan Niederd834c962010-08-17 01:57:40 -050076 git show-branch &&
77
78 apos="'\''"
Junio C Hamano30a95f32006-07-03 18:09:54 -070079'
80
Jonathan Niederd834c962010-08-17 01:57:40 -050081test_expect_success 'message for merging local branch' '
82 echo "Merge branch ${apos}left${apos}" >expected &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070083
84 git checkout master &&
85 git fetch . left &&
86
87 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070088 test_cmp expected actual
Junio C Hamano30a95f32006-07-03 18:09:54 -070089'
90
Jonathan Niederd834c962010-08-17 01:57:40 -050091test_expect_success 'message for merging external branch' '
92 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070093
94 git checkout master &&
Johannes Sixt41141562009-03-13 23:35:24 +010095 git fetch "$(pwd)" left &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070096
97 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070098 test_cmp expected actual
Junio C Hamano30a95f32006-07-03 18:09:54 -070099'
100
Jonathan Niederd834c962010-08-17 01:57:40 -0500101test_expect_success '[merge] summary/log configuration' '
102 cat >expected <<-EOF &&
103 Merge branch ${apos}left${apos}
Junio C Hamano30a95f32006-07-03 18:09:54 -0700104
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700105 # By Another Author (3) and A U Thor (2)
106 # Via Another Committer
Jonathan Niederd834c962010-08-17 01:57:40 -0500107 * left:
108 Left #5
109 Left #4
110 Left #3
111 Common #2
112 Common #1
113 EOF
Junio C Hamano30a95f32006-07-03 18:09:54 -0700114
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200115 git config merge.log true &&
Jonathan Niederd834c962010-08-17 01:57:40 -0500116 test_might_fail git config --unset-all merge.summary &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200117
118 git checkout master &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700119 test_tick &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200120 git fetch . left &&
121
Jonathan Niederd834c962010-08-17 01:57:40 -0500122 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200123
Jonathan Niederd834c962010-08-17 01:57:40 -0500124 test_might_fail git config --unset-all merge.log &&
Tom Princee0d10e12007-01-28 16:16:53 -0800125 git config merge.summary true &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700126
127 git checkout master &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700128 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700129 git fetch . left &&
130
Jonathan Niederd834c962010-08-17 01:57:40 -0500131 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
132
133 test_cmp expected actual1 &&
134 test_cmp expected actual2
Junio C Hamano30a95f32006-07-03 18:09:54 -0700135'
136
Ramkumar Ramachandrab928cbf2010-09-08 23:29:56 +0530137test_expect_success 'setup: clear [merge] configuration' '
138 test_might_fail git config --unset-all merge.log &&
139 test_might_fail git config --unset-all merge.summary
140'
141
142test_expect_success 'setup FETCH_HEAD' '
143 git checkout master &&
144 test_tick &&
145 git fetch . left
146'
147
148test_expect_success 'merge.log=3 limits shortlog length' '
149 cat >expected <<-EOF &&
150 Merge branch ${apos}left${apos}
151
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700152 # By Another Author (3) and A U Thor (2)
153 # Via Another Committer
Ramkumar Ramachandrab928cbf2010-09-08 23:29:56 +0530154 * left: (5 commits)
155 Left #5
156 Left #4
157 Left #3
158 ...
159 EOF
160
161 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
162 test_cmp expected actual
163'
164
165test_expect_success 'merge.log=5 shows all 5 commits' '
166 cat >expected <<-EOF &&
167 Merge branch ${apos}left${apos}
168
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700169 # By Another Author (3) and A U Thor (2)
170 # Via Another Committer
Ramkumar Ramachandrab928cbf2010-09-08 23:29:56 +0530171 * left:
172 Left #5
173 Left #4
174 Left #3
175 Common #2
176 Common #1
177 EOF
178
179 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
180 test_cmp expected actual
181'
182
183test_expect_success 'merge.log=0 disables shortlog' '
184 echo "Merge branch ${apos}left${apos}" >expected
185 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
186 test_cmp expected actual
187'
188
Ramkumar Ramachandrabd2549c2010-09-08 23:29:57 +0530189test_expect_success '--log=3 limits shortlog length' '
190 cat >expected <<-EOF &&
191 Merge branch ${apos}left${apos}
192
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700193 # By Another Author (3) and A U Thor (2)
194 # Via Another Committer
Ramkumar Ramachandrabd2549c2010-09-08 23:29:57 +0530195 * left: (5 commits)
196 Left #5
197 Left #4
198 Left #3
199 ...
200 EOF
201
202 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
203 test_cmp expected actual
204'
205
206test_expect_success '--log=5 shows all 5 commits' '
207 cat >expected <<-EOF &&
208 Merge branch ${apos}left${apos}
209
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700210 # By Another Author (3) and A U Thor (2)
211 # Via Another Committer
Ramkumar Ramachandrabd2549c2010-09-08 23:29:57 +0530212 * left:
213 Left #5
214 Left #4
215 Left #3
216 Common #2
217 Common #1
218 EOF
219
220 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
221 test_cmp expected actual
222'
223
224test_expect_success '--no-log disables shortlog' '
225 echo "Merge branch ${apos}left${apos}" >expected &&
226 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
227 test_cmp expected actual
228'
229
230test_expect_success '--log=0 disables shortlog' '
231 echo "Merge branch ${apos}left${apos}" >expected &&
232 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
233 test_cmp expected actual
234'
235
Jonathan Nieder21024402010-08-17 18:00:34 -0500236test_expect_success 'fmt-merge-msg -m' '
237 echo "Sync with left" >expected &&
238 cat >expected.log <<-EOF &&
239 Sync with left
240
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700241 # By Another Author (3) and A U Thor (2)
242 # Via Another Committer
Jonathan Nieder21024402010-08-17 18:00:34 -0500243 * ${apos}left${apos} of $(pwd):
244 Left #5
245 Left #4
246 Left #3
247 Common #2
248 Common #1
249 EOF
250
251 test_might_fail git config --unset merge.log &&
252 test_might_fail git config --unset merge.summary &&
253 git checkout master &&
254 git fetch "$(pwd)" left &&
255 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
256 git fmt-merge-msg --log -m "Sync with left" \
257 <.git/FETCH_HEAD >actual.log &&
258 git config merge.log true &&
259 git fmt-merge-msg -m "Sync with left" \
260 <.git/FETCH_HEAD >actual.log-config &&
261 git fmt-merge-msg --no-log -m "Sync with left" \
262 <.git/FETCH_HEAD >actual.nolog &&
263
264 test_cmp expected actual &&
265 test_cmp expected.log actual.log &&
266 test_cmp expected.log actual.log-config &&
267 test_cmp expected actual.nolog
268'
269
Jonathan Niederd834c962010-08-17 01:57:40 -0500270test_expect_success 'setup: expected shortlog for two branches' '
271 cat >expected <<-EOF
272 Merge branches ${apos}left${apos} and ${apos}right${apos}
Junio C Hamano30a95f32006-07-03 18:09:54 -0700273
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700274 # By Another Author (3) and A U Thor (2)
275 # Via Another Committer
Jonathan Niederd834c962010-08-17 01:57:40 -0500276 * left:
277 Left #5
278 Left #4
279 Left #3
280 Common #2
281 Common #1
Junio C Hamano30a95f32006-07-03 18:09:54 -0700282
Jonathan Niederd834c962010-08-17 01:57:40 -0500283 * right:
284 Right #5
285 Right #4
286 Right #3
287 Common #2
288 Common #1
289 EOF
290'
Junio C Hamano30a95f32006-07-03 18:09:54 -0700291
Jonathan Niederd834c962010-08-17 01:57:40 -0500292test_expect_success 'shortlog for two branches' '
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200293 git config merge.log true &&
Jonathan Niederd834c962010-08-17 01:57:40 -0500294 test_might_fail git config --unset-all merge.summary &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200295 git checkout master &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700296 test_tick &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200297 git fetch . left right &&
Jonathan Niederd834c962010-08-17 01:57:40 -0500298 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200299
Jonathan Niederd834c962010-08-17 01:57:40 -0500300 test_might_fail git config --unset-all merge.log &&
Tom Princee0d10e12007-01-28 16:16:53 -0800301 git config merge.summary true &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700302 git checkout master &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700303 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700304 git fetch . left right &&
Jonathan Niederd834c962010-08-17 01:57:40 -0500305 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700306
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200307 git config merge.log yes &&
Jonathan Niederd834c962010-08-17 01:57:40 -0500308 test_might_fail git config --unset-all merge.summary &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200309 git checkout master &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700310 test_tick &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200311 git fetch . left right &&
Jonathan Niederd834c962010-08-17 01:57:40 -0500312 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200313
Jonathan Niederd834c962010-08-17 01:57:40 -0500314 test_might_fail git config --unset-all merge.log &&
Tom Princee0d10e12007-01-28 16:16:53 -0800315 git config merge.summary yes &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700316 git checkout master &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700317 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700318 git fetch . left right &&
Jonathan Niederd834c962010-08-17 01:57:40 -0500319 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700320
Jonathan Niederd834c962010-08-17 01:57:40 -0500321 test_cmp expected actual1 &&
322 test_cmp expected actual2 &&
323 test_cmp expected actual3 &&
324 test_cmp expected actual4
Junio C Hamano30a95f32006-07-03 18:09:54 -0700325'
326
Stephen Boyd4c8d4c12009-05-23 11:53:11 -0700327test_expect_success 'merge-msg -F' '
Jonathan Niederd834c962010-08-17 01:57:40 -0500328 test_might_fail git config --unset-all merge.log &&
Stephen Boyd4c8d4c12009-05-23 11:53:11 -0700329 git config merge.summary yes &&
Stephen Boyd4c8d4c12009-05-23 11:53:11 -0700330 git checkout master &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700331 test_tick &&
Stephen Boyd4c8d4c12009-05-23 11:53:11 -0700332 git fetch . left right &&
Stephen Boyd4c8d4c12009-05-23 11:53:11 -0700333 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
334 test_cmp expected actual
335'
336
337test_expect_success 'merge-msg -F in subdirectory' '
Jonathan Niederd834c962010-08-17 01:57:40 -0500338 test_might_fail git config --unset-all merge.log &&
Stephen Boyd4c8d4c12009-05-23 11:53:11 -0700339 git config merge.summary yes &&
Stephen Boyd4c8d4c12009-05-23 11:53:11 -0700340 git checkout master &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700341 test_tick &&
Stephen Boyd4c8d4c12009-05-23 11:53:11 -0700342 git fetch . left right &&
343 mkdir sub &&
344 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
345 (
346 cd sub &&
347 git fmt-merge-msg -F FETCH_HEAD >../actual
348 ) &&
349 test_cmp expected actual
350'
351
Stephen Boyd419fe5b2010-03-24 00:15:58 -0700352test_expect_success 'merge-msg with nothing to merge' '
Jonathan Niederd834c962010-08-17 01:57:40 -0500353 test_might_fail git config --unset-all merge.log &&
Stephen Boyd419fe5b2010-03-24 00:15:58 -0700354 git config merge.summary yes &&
355
Jonathan Niederd834c962010-08-17 01:57:40 -0500356 >empty &&
357
Stephen Boyd419fe5b2010-03-24 00:15:58 -0700358 (
359 cd remote &&
360 git checkout -b unrelated &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700361 test_tick &&
Stephen Boyd419fe5b2010-03-24 00:15:58 -0700362 git fetch origin &&
363 git fmt-merge-msg <.git/FETCH_HEAD >../actual
364 ) &&
365
Jonathan Niederd834c962010-08-17 01:57:40 -0500366 test_cmp empty actual
Stephen Boyd419fe5b2010-03-24 00:15:58 -0700367'
368
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700369test_expect_success 'merge-msg tag' '
Jonathan Niederd834c962010-08-17 01:57:40 -0500370 cat >expected <<-EOF &&
371 Merge tag ${apos}tag-r3${apos}
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700372
Jonathan Niederd834c962010-08-17 01:57:40 -0500373 * tag ${apos}tag-r3${apos}:
374 Right #3
375 Common #2
376 Common #1
377 EOF
378
379 test_might_fail git config --unset-all merge.log &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700380 git config merge.summary yes &&
381
382 git checkout master &&
383 test_tick &&
384 git fetch . tag tag-r3 &&
385
386 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
387 test_cmp expected actual
388'
389
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700390test_expect_success 'merge-msg two tags' '
Jonathan Niederd834c962010-08-17 01:57:40 -0500391 cat >expected <<-EOF &&
392 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700393
Jonathan Niederd834c962010-08-17 01:57:40 -0500394 * tag ${apos}tag-r3${apos}:
395 Right #3
396 Common #2
397 Common #1
398
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700399 # By Another Author (3) and A U Thor (2)
400 # Via Another Committer
Jonathan Niederd834c962010-08-17 01:57:40 -0500401 * tag ${apos}tag-l5${apos}:
402 Left #5
403 Left #4
404 Left #3
405 Common #2
406 Common #1
407 EOF
408
409 test_might_fail git config --unset-all merge.log &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700410 git config merge.summary yes &&
411
412 git checkout master &&
413 test_tick &&
414 git fetch . tag tag-r3 tag tag-l5 &&
415
416 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
417 test_cmp expected actual
418'
419
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700420test_expect_success 'merge-msg tag and branch' '
Jonathan Niederd834c962010-08-17 01:57:40 -0500421 cat >expected <<-EOF &&
422 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700423
Jonathan Niederd834c962010-08-17 01:57:40 -0500424 * tag ${apos}tag-r3${apos}:
425 Right #3
426 Common #2
427 Common #1
428
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700429 # By Another Author (3) and A U Thor (2)
430 # Via Another Committer
Jonathan Niederd834c962010-08-17 01:57:40 -0500431 * left:
432 Left #5
433 Left #4
434 Left #3
435 Common #2
436 Common #1
437 EOF
438
439 test_might_fail git config --unset-all merge.log &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700440 git config merge.summary yes &&
441
442 git checkout master &&
443 test_tick &&
444 git fetch . tag tag-r3 left &&
445
446 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
447 test_cmp expected actual
448'
449
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700450test_expect_success 'merge-msg lots of commits' '
Jonathan Niederd834c962010-08-17 01:57:40 -0500451 {
452 cat <<-EOF &&
453 Merge branch ${apos}long${apos}
454
455 * long: (35 commits)
456 EOF
457
458 i=29 &&
459 while test $i -gt 9
460 do
461 echo " $i" &&
462 i=$(($i-1))
463 done &&
464 echo " ..."
465 } >expected &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700466
467 git checkout master &&
468 test_tick &&
469 git fetch . long &&
470
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700471 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
472 test_cmp expected actual
473'
474
Junio C Hamano30a95f32006-07-03 18:09:54 -0700475test_done