summaryrefslogtreecommitdiff
path: root/t/t6200-fmt-merge-msg.sh
blob: 9a168069217ef8d82173e563a04eaefe58d99f2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#!/bin/sh
#
# Copyright (c) 2006, Junio C Hamano
#
 
test_description='fmt-merge-msg test'
 
. ./test-lib.sh
 
test_expect_success setup '
	echo one >one &&
	git add one &&
	test_tick &&
	git commit -m "Initial" &&
 
	git clone . remote &&
 
	echo uno >one &&
	echo dos >two &&
	git add two &&
	test_tick &&
	git commit -a -m "Second" &&
 
	git checkout -b left &&
 
	echo "c1" >one &&
	test_tick &&
	git commit -a -m "Common #1" &&
 
	echo "c2" >one &&
	test_tick &&
	git commit -a -m "Common #2" &&
 
	git branch right &&
 
	echo "l3" >two &&
	test_tick &&
	git commit -a -m "Left #3" &&
 
	echo "l4" >two &&
	test_tick &&
	git commit -a -m "Left #4" &&
 
	echo "l5" >two &&
	test_tick &&
	git commit -a -m "Left #5" &&
	git tag tag-l5 &&
 
	git checkout right &&
 
	echo "r3" >three &&
	git add three &&
	test_tick &&
	git commit -a -m "Right #3" &&
	git tag tag-r3 &&
 
	echo "r4" >three &&
	test_tick &&
	git commit -a -m "Right #4" &&
 
	echo "r5" >three &&
	test_tick &&
	git commit -a -m "Right #5" &&
 
	git checkout -b long &&
	i=0 &&
	while test $i -lt 30
	do
		test_commit $i one &&
		i=$(($i+1))
	done &&
 
	git show-branch &&
 
	apos="'\''"
'
 
test_expect_success 'message for merging local branch' '
	echo "Merge branch ${apos}left${apos}" >expected &&
 
	git checkout master &&
	git fetch . left &&
 
	git fmt-merge-msg <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success 'message for merging external branch' '
	echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
 
	git checkout master &&
	git fetch "$(pwd)" left &&
 
	git fmt-merge-msg <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success '[merge] summary/log configuration' '
	cat >expected <<-EOF &&
	Merge branch ${apos}left${apos}
 
	* left:
	  Left #5
	  Left #4
	  Left #3
	  Common #2
	  Common #1
	EOF
 
	git config merge.log true &&
	test_might_fail git config --unset-all merge.summary &&
 
	git checkout master &&
	test_tick &&
	git fetch . left &&
 
	git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
 
	test_might_fail git config --unset-all merge.log &&
	git config merge.summary true &&
 
	git checkout master &&
	test_tick &&
	git fetch . left &&
 
	git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
 
	test_cmp expected actual1 &&
	test_cmp expected actual2
'
 
test_expect_success 'setup: clear [merge] configuration' '
	test_might_fail git config --unset-all merge.log &&
	test_might_fail git config --unset-all merge.summary
'
 
test_expect_success 'setup FETCH_HEAD' '
	git checkout master &&
	test_tick &&
	git fetch . left
'
 
test_expect_success 'merge.log=3 limits shortlog length' '
	cat >expected <<-EOF &&
	Merge branch ${apos}left${apos}
 
	* left: (5 commits)
	  Left #5
	  Left #4
	  Left #3
	  ...
	EOF
 
	git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success 'merge.log=5 shows all 5 commits' '
	cat >expected <<-EOF &&
	Merge branch ${apos}left${apos}
 
	* left:
	  Left #5
	  Left #4
	  Left #3
	  Common #2
	  Common #1
	EOF
 
	git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success 'merge.log=0 disables shortlog' '
	echo "Merge branch ${apos}left${apos}" >expected
	git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success '--log=3 limits shortlog length' '
	cat >expected <<-EOF &&
	Merge branch ${apos}left${apos}
 
	* left: (5 commits)
	  Left #5
	  Left #4
	  Left #3
	  ...
	EOF
 
	git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success '--log=5 shows all 5 commits' '
	cat >expected <<-EOF &&
	Merge branch ${apos}left${apos}
 
	* left:
	  Left #5
	  Left #4
	  Left #3
	  Common #2
	  Common #1
	EOF
 
	git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success '--no-log disables shortlog' '
	echo "Merge branch ${apos}left${apos}" >expected &&
	git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success '--log=0 disables shortlog' '
	echo "Merge branch ${apos}left${apos}" >expected &&
	git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success 'fmt-merge-msg -m' '
	echo "Sync with left" >expected &&
	cat >expected.log <<-EOF &&
	Sync with left
 
	* ${apos}left${apos} of $(pwd):
	  Left #5
	  Left #4
	  Left #3
	  Common #2
	  Common #1
	EOF
 
	test_might_fail git config --unset merge.log &&
	test_might_fail git config --unset merge.summary &&
	git checkout master &&
	git fetch "$(pwd)" left &&
	git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
	git fmt-merge-msg --log -m "Sync with left" \
					<.git/FETCH_HEAD >actual.log &&
	git config merge.log true &&
	git fmt-merge-msg -m "Sync with left" \
					<.git/FETCH_HEAD >actual.log-config &&
	git fmt-merge-msg --no-log -m "Sync with left" \
					<.git/FETCH_HEAD >actual.nolog &&
 
	test_cmp expected actual &&
	test_cmp expected.log actual.log &&
	test_cmp expected.log actual.log-config &&
	test_cmp expected actual.nolog
'
 
test_expect_success 'setup: expected shortlog for two branches' '
	cat >expected <<-EOF
	Merge branches ${apos}left${apos} and ${apos}right${apos}
 
	* left:
	  Left #5
	  Left #4
	  Left #3
	  Common #2
	  Common #1
 
	* right:
	  Right #5
	  Right #4
	  Right #3
	  Common #2
	  Common #1
	EOF
'
 
test_expect_success 'shortlog for two branches' '
	git config merge.log true &&
	test_might_fail git config --unset-all merge.summary &&
	git checkout master &&
	test_tick &&
	git fetch . left right &&
	git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
 
	test_might_fail git config --unset-all merge.log &&
	git config merge.summary true &&
	git checkout master &&
	test_tick &&
	git fetch . left right &&
	git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
 
	git config merge.log yes &&
	test_might_fail git config --unset-all merge.summary &&
	git checkout master &&
	test_tick &&
	git fetch . left right &&
	git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
 
	test_might_fail git config --unset-all merge.log &&
	git config merge.summary yes &&
	git checkout master &&
	test_tick &&
	git fetch . left right &&
	git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
 
	test_cmp expected actual1 &&
	test_cmp expected actual2 &&
	test_cmp expected actual3 &&
	test_cmp expected actual4
'
 
test_expect_success 'merge-msg -F' '
	test_might_fail git config --unset-all merge.log &&
	git config merge.summary yes &&
	git checkout master &&
	test_tick &&
	git fetch . left right &&
	git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success 'merge-msg -F in subdirectory' '
	test_might_fail git config --unset-all merge.log &&
	git config merge.summary yes &&
	git checkout master &&
	test_tick &&
	git fetch . left right &&
	mkdir sub &&
	cp .git/FETCH_HEAD sub/FETCH_HEAD &&
	(
		cd sub &&
		git fmt-merge-msg -F FETCH_HEAD >../actual
	) &&
	test_cmp expected actual
'
 
test_expect_success 'merge-msg with nothing to merge' '
	test_might_fail git config --unset-all merge.log &&
	git config merge.summary yes &&
 
	>empty &&
 
	(
		cd remote &&
		git checkout -b unrelated &&
		test_tick &&
		git fetch origin &&
		git fmt-merge-msg <.git/FETCH_HEAD >../actual
	) &&
 
	test_cmp empty actual
'
 
test_expect_success 'merge-msg tag' '
	cat >expected <<-EOF &&
	Merge tag ${apos}tag-r3${apos}
 
	* tag ${apos}tag-r3${apos}:
	  Right #3
	  Common #2
	  Common #1
	EOF
 
	test_might_fail git config --unset-all merge.log &&
	git config merge.summary yes &&
 
	git checkout master &&
	test_tick &&
	git fetch . tag tag-r3 &&
 
	git fmt-merge-msg <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success 'merge-msg two tags' '
	cat >expected <<-EOF &&
	Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
 
	* tag ${apos}tag-r3${apos}:
	  Right #3
	  Common #2
	  Common #1
 
	* tag ${apos}tag-l5${apos}:
	  Left #5
	  Left #4
	  Left #3
	  Common #2
	  Common #1
	EOF
 
	test_might_fail git config --unset-all merge.log &&
	git config merge.summary yes &&
 
	git checkout master &&
	test_tick &&
	git fetch . tag tag-r3 tag tag-l5 &&
 
	git fmt-merge-msg <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success 'merge-msg tag and branch' '
	cat >expected <<-EOF &&
	Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
 
	* tag ${apos}tag-r3${apos}:
	  Right #3
	  Common #2
	  Common #1
 
	* left:
	  Left #5
	  Left #4
	  Left #3
	  Common #2
	  Common #1
	EOF
 
	test_might_fail git config --unset-all merge.log &&
	git config merge.summary yes &&
 
	git checkout master &&
	test_tick &&
	git fetch . tag tag-r3 left &&
 
	git fmt-merge-msg <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_expect_success 'merge-msg lots of commits' '
	{
		cat <<-EOF &&
		Merge branch ${apos}long${apos}
 
		* long: (35 commits)
		EOF
 
		i=29 &&
		while test $i -gt 9
		do
			echo "  $i" &&
			i=$(($i-1))
		done &&
		echo "  ..."
	} >expected &&
 
	git checkout master &&
	test_tick &&
	git fetch . long &&
 
	git fmt-merge-msg <.git/FETCH_HEAD >actual &&
	test_cmp expected actual
'
 
test_done