1#!/bin/sh
2#
3# Copyright (c) 2006, Junio C Hamano
4#
5
6test_description='fmt-merge-msg test'
7
8. ./test-lib.sh
9
10test_expect_success setup '
11 echo one >one &&
12 git add one &&
13 test_tick &&
14 git commit -m "Initial" &&
15
16 git clone . remote &&
17
18 echo uno >one &&
19 echo dos >two &&
20 git add two &&
21 test_tick &&
22 git commit -a -m "Second" &&
23
24 git checkout -b left &&
25
26 echo "c1" >one &&
27 test_tick &&
28 git commit -a -m "Common #1" &&
29
30 echo "c2" >one &&
31 test_tick &&
32 git commit -a -m "Common #2" &&
33
34 git branch right &&
35
36 echo "l3" >two &&
37 test_tick &&
38 git commit -a -m "Left #3" &&
39
40 echo "l4" >two &&
41 test_tick &&
42 git commit -a -m "Left #4" &&
43
44 echo "l5" >two &&
45 test_tick &&
46 git commit -a -m "Left #5" &&
47 git tag tag-l5 &&
48
49 git checkout right &&
50
51 echo "r3" >three &&
52 git add three &&
53 test_tick &&
54 git commit -a -m "Right #3" &&
55 git tag tag-r3 &&
56
57 echo "r4" >three &&
58 test_tick &&
59 git commit -a -m "Right #4" &&
60
61 echo "r5" >three &&
62 test_tick &&
63 git commit -a -m "Right #5" &&
64
65 git checkout -b long &&
66 i=0 &&
67 while test $i -lt 30
68 do
69 test_commit $i one &&
70 i=$(($i+1))
71 done &&
72
73 git show-branch &&
74
75 apos="'\''"
76'
77
78test_expect_success 'message for merging local branch' '
79 echo "Merge branch ${apos}left${apos}" >expected &&
80
81 git checkout master &&
82 git fetch . left &&
83
84 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
85 test_cmp expected actual
86'
87
88test_expect_success 'message for merging external branch' '
89 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
90
91 git checkout master &&
92 git fetch "$(pwd)" left &&
93
94 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
95 test_cmp expected actual
96'
97
98test_expect_success '[merge] summary/log configuration' '
99 cat >expected <<-EOF &&
100 Merge branch ${apos}left${apos}
101
102 * left:
103 Left #5
104 Left #4
105 Left #3
106 Common #2
107 Common #1
108 EOF
109
110 git config merge.log true &&
111 test_might_fail git config --unset-all merge.summary &&
112
113 git checkout master &&
114 test_tick &&
115 git fetch . left &&
116
117 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
118
119 test_might_fail git config --unset-all merge.log &&
120 git config merge.summary true &&
121
122 git checkout master &&
123 test_tick &&
124 git fetch . left &&
125
126 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
127
128 test_cmp expected actual1 &&
129 test_cmp expected actual2
130'
131
132test_expect_success 'setup: expected shortlog for two branches' '
133 cat >expected <<-EOF
134 Merge branches ${apos}left${apos} and ${apos}right${apos}
135
136 * left:
137 Left #5
138 Left #4
139 Left #3
140 Common #2
141 Common #1
142
143 * right:
144 Right #5
145 Right #4
146 Right #3
147 Common #2
148 Common #1
149 EOF
150'
151
152test_expect_success 'shortlog for two branches' '
153 git config merge.log true &&
154 test_might_fail git config --unset-all merge.summary &&
155 git checkout master &&
156 test_tick &&
157 git fetch . left right &&
158 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
159
160 test_might_fail git config --unset-all merge.log &&
161 git config merge.summary true &&
162 git checkout master &&
163 test_tick &&
164 git fetch . left right &&
165 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
166
167 git config merge.log yes &&
168 test_might_fail git config --unset-all merge.summary &&
169 git checkout master &&
170 test_tick &&
171 git fetch . left right &&
172 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
173
174 test_might_fail git config --unset-all merge.log &&
175 git config merge.summary yes &&
176 git checkout master &&
177 test_tick &&
178 git fetch . left right &&
179 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
180
181 test_cmp expected actual1 &&
182 test_cmp expected actual2 &&
183 test_cmp expected actual3 &&
184 test_cmp expected actual4
185'
186
187test_expect_success 'merge-msg -F' '
188 test_might_fail git config --unset-all merge.log &&
189 git config merge.summary yes &&
190 git checkout master &&
191 test_tick &&
192 git fetch . left right &&
193 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
194 test_cmp expected actual
195'
196
197test_expect_success 'merge-msg -F in subdirectory' '
198 test_might_fail git config --unset-all merge.log &&
199 git config merge.summary yes &&
200 git checkout master &&
201 test_tick &&
202 git fetch . left right &&
203 mkdir sub &&
204 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
205 (
206 cd sub &&
207 git fmt-merge-msg -F FETCH_HEAD >../actual
208 ) &&
209 test_cmp expected actual
210'
211
212test_expect_success 'merge-msg with nothing to merge' '
213 test_might_fail git config --unset-all merge.log &&
214 git config merge.summary yes &&
215
216 >empty &&
217
218 (
219 cd remote &&
220 git checkout -b unrelated &&
221 test_tick &&
222 git fetch origin &&
223 git fmt-merge-msg <.git/FETCH_HEAD >../actual
224 ) &&
225
226 test_cmp empty actual
227'
228
229test_expect_success 'merge-msg tag' '
230 cat >expected <<-EOF &&
231 Merge tag ${apos}tag-r3${apos}
232
233 * tag ${apos}tag-r3${apos}:
234 Right #3
235 Common #2
236 Common #1
237 EOF
238
239 test_might_fail git config --unset-all merge.log &&
240 git config merge.summary yes &&
241
242 git checkout master &&
243 test_tick &&
244 git fetch . tag tag-r3 &&
245
246 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
247 test_cmp expected actual
248'
249
250test_expect_success 'merge-msg two tags' '
251 cat >expected <<-EOF &&
252 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
253
254 * tag ${apos}tag-r3${apos}:
255 Right #3
256 Common #2
257 Common #1
258
259 * tag ${apos}tag-l5${apos}:
260 Left #5
261 Left #4
262 Left #3
263 Common #2
264 Common #1
265 EOF
266
267 test_might_fail git config --unset-all merge.log &&
268 git config merge.summary yes &&
269
270 git checkout master &&
271 test_tick &&
272 git fetch . tag tag-r3 tag tag-l5 &&
273
274 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
275 test_cmp expected actual
276'
277
278test_expect_success 'merge-msg tag and branch' '
279 cat >expected <<-EOF &&
280 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
281
282 * tag ${apos}tag-r3${apos}:
283 Right #3
284 Common #2
285 Common #1
286
287 * left:
288 Left #5
289 Left #4
290 Left #3
291 Common #2
292 Common #1
293 EOF
294
295 test_might_fail git config --unset-all merge.log &&
296 git config merge.summary yes &&
297
298 git checkout master &&
299 test_tick &&
300 git fetch . tag tag-r3 left &&
301
302 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
303 test_cmp expected actual
304'
305
306test_expect_success 'merge-msg lots of commits' '
307 {
308 cat <<-EOF &&
309 Merge branch ${apos}long${apos}
310
311 * long: (35 commits)
312 EOF
313
314 i=29 &&
315 while test $i -gt 9
316 do
317 echo " $i" &&
318 i=$(($i-1))
319 done &&
320 echo " ..."
321 } >expected &&
322
323 git checkout master &&
324 test_tick &&
325 git fetch . long &&
326
327 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
328 test_cmp expected actual
329'
330
331test_done