3 # Copyright (c) 2007 Lars Hjemli
6 test_description='git-merge
8 Testing basic merge operations/option parsing.'
84 cat >result.1-5-9 <<EOF
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 &&
101 git log --no-merges ^HEAD c1 >>squash.1 &&
102 echo "Squashed commit of the following:" >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
111 if ! diff -u "$1" "$2"
119 verify_diff "$2" "$1" "[OOPS] bad merge result" &&
120 if test $(git ls-files -u | wc -l) -gt 0
122 echo "[OOPS] unmerged files"
125 if ! git diff --exit-code
127 echo "[OOPS] working tree != index"
132 git show -s --pretty=format:%s HEAD >msg.act &&
133 verify_diff "$3" msg.act "[OOPS] bad merge message"
138 if test "$1" != "$(git rev-parse HEAD)"
140 echo "[OOPS] HEAD != $1"
149 if test "$1" != "$(git rev-parse HEAD^$i)"
151 echo "[OOPS] HEAD^$i != $1"
159 verify_mergeheads() {
161 if ! test -f .git/MERGE_HEAD
163 echo "[OOPS] MERGE_HEAD is missing"
168 head=$(head -n $i .git/MERGE_HEAD | tail -n 1)
169 if test "$1" != "$head"
171 echo "[OOPS] MERGE_HEAD $i != $1"
179 verify_no_mergehead() {
180 if test -f .git/MERGE_HEAD
182 echo "[OOPS] MERGE_HEAD exists"
188 test_expect_success 'setup' '
191 git commit -m "commit 0" &&
193 c0=$(git rev-parse HEAD) &&
197 git commit -m "commit 1" &&
199 c1=$(git rev-parse HEAD) &&
200 git reset --hard "$c0" &&
204 git commit -m "commit 2" &&
206 c2=$(git rev-parse HEAD) &&
207 git reset --hard "$c0" &&
211 git commit -m "commit 3" &&
213 c3=$(git rev-parse HEAD)
214 git reset --hard "$c0" &&
218 test_debug 'gitk --all'
220 test_expect_success 'test option parsing' '
223 echo "[OOPS] -$ accepted"
226 if git merge --no-such c1
228 echo "[OOPS] --no-such accepted"
231 if git merge -s foobar c1
233 echo "[OOPS] -s foobar accepted"
236 if git merge -s=foobar c1
238 echo "[OOPS] -s=foobar accepted"
243 echo "[OOPS] missing commit msg accepted"
248 echo "[OOPS] missing commit references accepted"
253 test_expect_success 'merge c0 with c1' '
254 git reset --hard c0 &&
256 verify_merge file result.1 &&
260 test_debug 'gitk --all'
262 test_expect_success 'merge c1 with c2' '
263 git reset --hard c1 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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" &&
348 verify_merge file result.1-5 &&
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" &&
359 verify_merge file result.1-5 &&
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" &&
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
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" &&
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
391 echo "[OOPS] diffstat was generated"
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" &&
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" &&
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 &&
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" &&
434 verify_merge file result.1 &&
438 test_debug 'gitk --all'