Prevent case sensitive commit
[git/jr.git] / t / t7600-merge.sh
blob50c51c82facdf30fffa4517763c84ce862aa8c27
1 #!/bin/sh
3 # Copyright (c) 2007 Lars Hjemli
6 test_description='git-merge
8 Testing basic merge operations/option parsing.'
10 . ./test-lib.sh
12 cat >file <<EOF
22 EOF
24 cat >file.1 <<EOF
25 1 X
34 EOF
36 cat >file.5 <<EOF
41 5 X
46 EOF
48 cat >file.9 <<EOF
57 9 X
58 EOF
60 cat >result.1 <<EOF
61 1 X
70 EOF
72 cat >result.1-5 <<EOF
73 1 X
77 5 X
82 EOF
84 cat >result.1-5-9 <<EOF
85 1 X
89 5 X
93 9 X
94 EOF
96 create_merge_msgs() {
97 echo "Merge commit 'c2'" >msg.1-5 &&
98 echo "Merge commit 'c2'; commit 'c3'" >msg.1-5-9 &&
99 echo "Squashed commit of the following:" >squash.1 &&
100 echo >>squash.1 &&
101 git log --no-merges ^HEAD c1 >>squash.1 &&
102 echo "Squashed commit of the following:" >squash.1-5 &&
103 echo >>squash.1-5 &&
104 git log --no-merges ^HEAD c2 >>squash.1-5 &&
105 echo "Squashed commit of the following:" >squash.1-5-9 &&
106 echo >>squash.1-5-9 &&
107 git log --no-merges ^HEAD c2 c3 >>squash.1-5-9
110 verify_diff() {
111 if ! diff -u "$1" "$2"
112 then
113 echo "$3"
114 false
118 verify_merge() {
119 verify_diff "$2" "$1" "[OOPS] bad merge result" &&
120 if test $(git ls-files -u | wc -l) -gt 0
121 then
122 echo "[OOPS] unmerged files"
123 false
124 fi &&
125 if ! git diff --exit-code
126 then
127 echo "[OOPS] working tree != index"
128 false
129 fi &&
130 if test -n "$3"
131 then
132 git show -s --pretty=format:%s HEAD >msg.act &&
133 verify_diff "$3" msg.act "[OOPS] bad merge message"
137 verify_head() {
138 if test "$1" != "$(git rev-parse HEAD)"
139 then
140 echo "[OOPS] HEAD != $1"
141 false
145 verify_parents() {
147 while test $# -gt 0
149 if test "$1" != "$(git rev-parse HEAD^$i)"
150 then
151 echo "[OOPS] HEAD^$i != $1"
152 return 1
154 i=$(expr $i + 1)
155 shift
156 done
159 verify_mergeheads() {
161 if ! test -f .git/MERGE_HEAD
162 then
163 echo "[OOPS] MERGE_HEAD is missing"
164 false
165 fi &&
166 while test $# -gt 0
168 head=$(head -n $i .git/MERGE_HEAD | tail -n 1)
169 if test "$1" != "$head"
170 then
171 echo "[OOPS] MERGE_HEAD $i != $1"
172 return 1
174 i=$(expr $i + 1)
175 shift
176 done
179 verify_no_mergehead() {
180 if test -f .git/MERGE_HEAD
181 then
182 echo "[OOPS] MERGE_HEAD exists"
183 false
188 test_expect_success 'setup' '
189 git add file &&
190 test_tick &&
191 git commit -m "commit 0" &&
192 git tag c0 &&
193 c0=$(git rev-parse HEAD) &&
194 cp file.1 file &&
195 git add file &&
196 test_tick &&
197 git commit -m "commit 1" &&
198 git tag c1 &&
199 c1=$(git rev-parse HEAD) &&
200 git reset --hard "$c0" &&
201 cp file.5 file &&
202 git add file &&
203 test_tick &&
204 git commit -m "commit 2" &&
205 git tag c2 &&
206 c2=$(git rev-parse HEAD) &&
207 git reset --hard "$c0" &&
208 cp file.9 file &&
209 git add file &&
210 test_tick &&
211 git commit -m "commit 3" &&
212 git tag c3 &&
213 c3=$(git rev-parse HEAD)
214 git reset --hard "$c0" &&
215 create_merge_msgs
218 test_debug 'gitk --all'
220 test_expect_success 'test option parsing' '
221 if git merge -$ c1
222 then
223 echo "[OOPS] -$ accepted"
224 false
225 fi &&
226 if git merge --no-such c1
227 then
228 echo "[OOPS] --no-such accepted"
229 false
230 fi &&
231 if git merge -s foobar c1
232 then
233 echo "[OOPS] -s foobar accepted"
234 false
235 fi &&
236 if git merge -s=foobar c1
237 then
238 echo "[OOPS] -s=foobar accepted"
239 false
240 fi &&
241 if git merge -m
242 then
243 echo "[OOPS] missing commit msg accepted"
244 false
245 fi &&
246 if git merge
247 then
248 echo "[OOPS] missing commit references accepted"
249 false
253 test_expect_success 'merge c0 with c1' '
254 git reset --hard c0 &&
255 git merge c1 &&
256 verify_merge file result.1 &&
257 verify_head "$c1"
260 test_debug 'gitk --all'
262 test_expect_success 'merge c1 with c2' '
263 git reset --hard c1 &&
264 test_tick &&
265 git merge c2 &&
266 verify_merge file result.1-5 msg.1-5 &&
267 verify_parents $c1 $c2
270 test_debug 'gitk --all'
272 test_expect_success 'merge c1 with c2 and c3' '
273 git reset --hard c1 &&
274 test_tick &&
275 git merge c2 c3 &&
276 verify_merge file result.1-5-9 msg.1-5-9 &&
277 verify_parents $c1 $c2 $c3
280 test_debug 'gitk --all'
282 test_expect_success 'merge c0 with c1 (no-commit)' '
283 git reset --hard c0 &&
284 git merge --no-commit c1 &&
285 verify_merge file result.1 &&
286 verify_head $c1
289 test_debug 'gitk --all'
291 test_expect_success 'merge c1 with c2 (no-commit)' '
292 git reset --hard c1 &&
293 git merge --no-commit c2 &&
294 verify_merge file result.1-5 &&
295 verify_head $c1 &&
296 verify_mergeheads $c2
299 test_debug 'gitk --all'
301 test_expect_success 'merge c1 with c2 and c3 (no-commit)' '
302 git reset --hard c1 &&
303 git merge --no-commit c2 c3 &&
304 verify_merge file result.1-5-9 &&
305 verify_head $c1 &&
306 verify_mergeheads $c2 $c3
309 test_debug 'gitk --all'
311 test_expect_success 'merge c0 with c1 (squash)' '
312 git reset --hard c0 &&
313 git merge --squash c1 &&
314 verify_merge file result.1 &&
315 verify_head $c0 &&
316 verify_no_mergehead &&
317 verify_diff squash.1 .git/SQUASH_MSG "[OOPS] bad squash message"
320 test_debug 'gitk --all'
322 test_expect_success 'merge c1 with c2 (squash)' '
323 git reset --hard c1 &&
324 git merge --squash c2 &&
325 verify_merge file result.1-5 &&
326 verify_head $c1 &&
327 verify_no_mergehead &&
328 verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
331 test_debug 'gitk --all'
333 test_expect_success 'merge c1 with c2 and c3 (squash)' '
334 git reset --hard c1 &&
335 git merge --squash c2 c3 &&
336 verify_merge file result.1-5-9 &&
337 verify_head $c1 &&
338 verify_no_mergehead &&
339 verify_diff squash.1-5-9 .git/SQUASH_MSG "[OOPS] bad squash message"
342 test_debug 'gitk --all'
344 test_expect_success 'merge c1 with c2 (no-commit in config)' '
345 git reset --hard c1 &&
346 git config branch.master.mergeoptions "--no-commit" &&
347 git merge c2 &&
348 verify_merge file result.1-5 &&
349 verify_head $c1 &&
350 verify_mergeheads $c2
353 test_debug 'gitk --all'
355 test_expect_success 'merge c1 with c2 (squash in config)' '
356 git reset --hard c1 &&
357 git config branch.master.mergeoptions "--squash" &&
358 git merge c2 &&
359 verify_merge file result.1-5 &&
360 verify_head $c1 &&
361 verify_no_mergehead &&
362 verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
365 test_debug 'gitk --all'
367 test_expect_success 'override config option -n' '
368 git reset --hard c1 &&
369 git config branch.master.mergeoptions "-n" &&
370 test_tick &&
371 git merge --summary c2 >diffstat.txt &&
372 verify_merge file result.1-5 msg.1-5 &&
373 verify_parents $c1 $c2 &&
374 if ! grep -e "^ file | *2 +-$" diffstat.txt
375 then
376 echo "[OOPS] diffstat was not generated"
380 test_debug 'gitk --all'
382 test_expect_success 'override config option --summary' '
383 git reset --hard c1 &&
384 git config branch.master.mergeoptions "--summary" &&
385 test_tick &&
386 git merge -n c2 >diffstat.txt &&
387 verify_merge file result.1-5 msg.1-5 &&
388 verify_parents $c1 $c2 &&
389 if grep -e "^ file | *2 +-$" diffstat.txt
390 then
391 echo "[OOPS] diffstat was generated"
392 false
396 test_debug 'gitk --all'
398 test_expect_success 'merge c1 with c2 (override --no-commit)' '
399 git reset --hard c1 &&
400 git config branch.master.mergeoptions "--no-commit" &&
401 test_tick &&
402 git merge --commit c2 &&
403 verify_merge file result.1-5 msg.1-5 &&
404 verify_parents $c1 $c2
407 test_debug 'gitk --all'
409 test_expect_success 'merge c1 with c2 (override --squash)' '
410 git reset --hard c1 &&
411 git config branch.master.mergeoptions "--squash" &&
412 test_tick &&
413 git merge --no-squash c2 &&
414 verify_merge file result.1-5 msg.1-5 &&
415 verify_parents $c1 $c2
418 test_debug 'gitk --all'
420 test_expect_success 'merge c0 with c1 (no-ff)' '
421 git reset --hard c0 &&
422 test_tick &&
423 git merge --no-ff c1 &&
424 verify_merge file result.1 &&
425 verify_parents $c0 $c1
428 test_debug 'gitk --all'
430 test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
431 git reset --hard c0 &&
432 git config branch.master.mergeoptions "--no-ff" &&
433 git merge --ff c1 &&
434 verify_merge file result.1 &&
435 verify_head $c1
438 test_debug 'gitk --all'
440 test_done