merge: test the top-level merge driver

We seem to have tests for specific merge strategy backends (e.g. recursive), but not much test coverage for the "git merge" itself. As I am planning to update the semantics of merging "FETCH_HEAD" in such a way that these two git pull . topic_a topic_b... vs. git fetch . topic_a topic_b... git merge FETCH_HEAD are truly equivalent, let me add a few test cases to cover the tricky ones. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Apr 29, 2015 at 13:14 UTC 9e62316df7f918eabc879f97da76543cc5f0b3fc
1 file changed +136
t/t3033-merge-toplevel.sh new
+136
@@ -0,0 +1,136 @@
1 +#!/bin/sh
2 +
3 +test_description='"git merge" top-level frontend'
4 +
5 +. ./test-lib.sh
6 +
7 +t3033_reset () {
8 + git checkout -B master two &&
9 + git branch -f left three &&
10 + git branch -f right four
11 +}
12 +
13 +test_expect_success setup '
14 + test_commit one &&
15 + git branch left &&
16 + git branch right &&
17 + test_commit two &&
18 + git checkout left &&
19 + test_commit three &&
20 + git checkout right &&
21 + test_commit four &&
22 + git checkout master
23 +'
24 +
25 +# Local branches
26 +
27 +test_expect_success 'merge an octopus into void' '
28 + t3033_reset &&
29 + git checkout --orphan test &&
30 + git rm -fr . &&
31 + test_must_fail git merge left right &&
32 + test_must_fail git rev-parse --verify HEAD &&
33 + git diff --quiet &&
34 + test_must_fail git rev-parse HEAD
35 +'
36 +
37 +test_expect_success 'merge an octopus, fast-forward (ff)' '
38 + t3033_reset &&
39 + git reset --hard one &&
40 + git merge left right &&
41 + # one is ancestor of three (left) and four (right)
42 + test_must_fail git rev-parse --verify HEAD^3 &&
43 + git rev-parse HEAD^1 HEAD^2 | sort >actual &&
44 + git rev-parse three four | sort >expect &&
45 + test_cmp expect actual
46 +'
47 +
48 +test_expect_success 'merge octopus, non-fast-forward (ff)' '
49 + t3033_reset &&
50 + git reset --hard one &&
51 + git merge --no-ff left right &&
52 + # one is ancestor of three (left) and four (right)
53 + test_must_fail git rev-parse --verify HEAD^4 &&
54 + git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
55 + git rev-parse one three four | sort >expect &&
56 + test_cmp expect actual
57 +'
58 +
59 +test_expect_success 'merge octopus, fast-forward (does not ff)' '
60 + t3033_reset &&
61 + git merge left right &&
62 + # two (master) is not an ancestor of three (left) and four (right)
63 + test_must_fail git rev-parse --verify HEAD^4 &&
64 + git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
65 + git rev-parse two three four | sort >expect &&
66 + test_cmp expect actual
67 +'
68 +
69 +test_expect_success 'merge octopus, non-fast-forward' '
70 + t3033_reset &&
71 + git merge --no-ff left right &&
72 + test_must_fail git rev-parse --verify HEAD^4 &&
73 + git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
74 + git rev-parse two three four | sort >expect &&
75 + test_cmp expect actual
76 +'
77 +
78 +# The same set with FETCH_HEAD
79 +
80 +test_expect_failure 'merge FETCH_HEAD octopus into void' '
81 + t3033_reset &&
82 + git checkout --orphan test &&
83 + git rm -fr . &&
84 + git fetch . left right &&
85 + test_must_fail git merge FETCH_HEAD &&
86 + test_must_fail git rev-parse --verify HEAD &&
87 + git diff --quiet &&
88 + test_must_fail git rev-parse HEAD
89 +'
90 +
91 +test_expect_failure 'merge FETCH_HEAD octopus fast-forward (ff)' '
92 + t3033_reset &&
93 + git reset --hard one &&
94 + git fetch . left right &&
95 + git merge FETCH_HEAD &&
96 + # one is ancestor of three (left) and four (right)
97 + test_must_fail git rev-parse --verify HEAD^3 &&
98 + git rev-parse HEAD^1 HEAD^2 | sort >actual &&
99 + git rev-parse three four | sort >expect &&
100 + test_cmp expect actual
101 +'
102 +
103 +test_expect_failure 'merge FETCH_HEAD octopus non-fast-forward (ff)' '
104 + t3033_reset &&
105 + git reset --hard one &&
106 + git fetch . left right &&
107 + git merge --no-ff FETCH_HEAD &&
108 + # one is ancestor of three (left) and four (right)
109 + test_must_fail git rev-parse --verify HEAD^4 &&
110 + git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
111 + git rev-parse one three four | sort >expect &&
112 + test_cmp expect actual
113 +'
114 +
115 +test_expect_failure 'merge FETCH_HEAD octopus fast-forward (does not ff)' '
116 + t3033_reset &&
117 + git fetch . left right &&
118 + git merge FETCH_HEAD &&
119 + # two (master) is not an ancestor of three (left) and four (right)
120 + test_must_fail git rev-parse --verify HEAD^4 &&
121 + git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
122 + git rev-parse two three four | sort >expect &&
123 + test_cmp expect actual
124 +'
125 +
126 +test_expect_failure 'merge FETCH_HEAD octopus non-fast-forward' '
127 + t3033_reset &&
128 + git fetch . left right &&
129 + git merge --no-ff FETCH_HEAD &&
130 + test_must_fail git rev-parse --verify HEAD^4 &&
131 + git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
132 + git rev-parse two three four | sort >expect &&
133 + test_cmp expect actual
134 +'
135 +
136 +test_done