]>
Commit | Line | Data |
---|---|---|
b2eabcc2 MV |
1 | #!/bin/sh |
2 | ||
47a528ad | 3 | test_description='git merge |
b2eabcc2 MV |
4 | |
5 | Testing pull.* configuration parsing.' | |
6 | ||
7 | . ./test-lib.sh | |
8 | ||
9 | test_expect_success 'setup' ' | |
10 | echo c0 >c0.c && | |
11 | git add c0.c && | |
12 | git commit -m c0 && | |
13 | git tag c0 && | |
14 | echo c1 >c1.c && | |
15 | git add c1.c && | |
16 | git commit -m c1 && | |
17 | git tag c1 && | |
18 | git reset --hard c0 && | |
19 | echo c2 >c2.c && | |
20 | git add c2.c && | |
21 | git commit -m c2 && | |
22 | git tag c2 && | |
23 | git reset --hard c0 && | |
24 | echo c3 >c3.c && | |
25 | git add c3.c && | |
26 | git commit -m c3 && | |
27 | git tag c3 | |
28 | ' | |
29 | ||
d18c950a AH |
30 | test_expect_success 'pull.rebase not set' ' |
31 | git reset --hard c0 && | |
32 | git pull . c1 2>err && | |
33 | test_i18ngrep "Pulling without specifying how to reconcile" err | |
34 | ' | |
35 | ||
54200cef AH |
36 | test_expect_success 'pull.rebase not set and pull.ff=true' ' |
37 | git reset --hard c0 && | |
38 | test_config pull.ff true && | |
39 | git pull . c1 2>err && | |
40 | test_i18ngrep ! "Pulling without specifying how to reconcile" err | |
41 | ' | |
42 | ||
d18c950a AH |
43 | test_expect_success 'pull.rebase not set and pull.ff=false' ' |
44 | git reset --hard c0 && | |
45 | test_config pull.ff false && | |
46 | git pull . c1 2>err && | |
54200cef | 47 | test_i18ngrep ! "Pulling without specifying how to reconcile" err |
d18c950a AH |
48 | ' |
49 | ||
50 | test_expect_success 'pull.rebase not set and pull.ff=only' ' | |
51 | git reset --hard c0 && | |
52 | test_config pull.ff only && | |
53 | git pull . c1 2>err && | |
54 | test_i18ngrep ! "Pulling without specifying how to reconcile" err | |
55 | ' | |
56 | ||
57 | test_expect_success 'pull.rebase not set and --rebase given' ' | |
58 | git reset --hard c0 && | |
59 | git pull --rebase . c1 2>err && | |
60 | test_i18ngrep ! "Pulling without specifying how to reconcile" err | |
61 | ' | |
62 | ||
63 | test_expect_success 'pull.rebase not set and --no-rebase given' ' | |
64 | git reset --hard c0 && | |
65 | git pull --no-rebase . c1 2>err && | |
66 | test_i18ngrep ! "Pulling without specifying how to reconcile" err | |
67 | ' | |
68 | ||
54200cef AH |
69 | test_expect_success 'pull.rebase not set and --ff given' ' |
70 | git reset --hard c0 && | |
71 | git pull --ff . c1 2>err && | |
72 | test_i18ngrep ! "Pulling without specifying how to reconcile" err | |
73 | ' | |
74 | ||
75 | test_expect_success 'pull.rebase not set and --no-ff given' ' | |
76 | git reset --hard c0 && | |
77 | git pull --no-ff . c1 2>err && | |
78 | test_i18ngrep ! "Pulling without specifying how to reconcile" err | |
79 | ' | |
80 | ||
d18c950a AH |
81 | test_expect_success 'pull.rebase not set and --ff-only given' ' |
82 | git reset --hard c0 && | |
83 | git pull --ff-only . c1 2>err && | |
84 | test_i18ngrep ! "Pulling without specifying how to reconcile" err | |
85 | ' | |
86 | ||
b2eabcc2 MV |
87 | test_expect_success 'merge c1 with c2' ' |
88 | git reset --hard c1 && | |
89 | test -f c0.c && | |
90 | test -f c1.c && | |
91 | test ! -f c2.c && | |
92 | test ! -f c3.c && | |
93 | git merge c2 && | |
94 | test -f c1.c && | |
95 | test -f c2.c | |
96 | ' | |
97 | ||
b814da89 DA |
98 | test_expect_success 'fast-forward pull succeeds with "true" in pull.ff' ' |
99 | git reset --hard c0 && | |
100 | test_config pull.ff true && | |
101 | git pull . c1 && | |
102 | test "$(git rev-parse HEAD)" = "$(git rev-parse c1)" | |
103 | ' | |
104 | ||
eb8dc05c PT |
105 | test_expect_success 'pull.ff=true overrides merge.ff=false' ' |
106 | git reset --hard c0 && | |
107 | test_config merge.ff false && | |
108 | test_config pull.ff true && | |
109 | git pull . c1 && | |
110 | test "$(git rev-parse HEAD)" = "$(git rev-parse c1)" | |
111 | ' | |
112 | ||
b814da89 DA |
113 | test_expect_success 'fast-forward pull creates merge with "false" in pull.ff' ' |
114 | git reset --hard c0 && | |
115 | test_config pull.ff false && | |
116 | git pull . c1 && | |
117 | test "$(git rev-parse HEAD^1)" = "$(git rev-parse c0)" && | |
118 | test "$(git rev-parse HEAD^2)" = "$(git rev-parse c1)" | |
119 | ' | |
120 | ||
121 | test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' ' | |
122 | git reset --hard c1 && | |
123 | test_config pull.ff only && | |
124 | test_must_fail git pull . c3 | |
125 | ' | |
126 | ||
b2eabcc2 MV |
127 | test_expect_success 'merge c1 with c2 (ours in pull.twohead)' ' |
128 | git reset --hard c1 && | |
129 | git config pull.twohead ours && | |
130 | git merge c2 && | |
131 | test -f c1.c && | |
132 | ! test -f c2.c | |
133 | ' | |
134 | ||
135 | test_expect_success 'merge c1 with c2 and c3 (recursive in pull.octopus)' ' | |
136 | git reset --hard c1 && | |
137 | git config pull.octopus "recursive" && | |
138 | test_must_fail git merge c2 c3 && | |
139 | test "$(git rev-parse c1)" = "$(git rev-parse HEAD)" | |
140 | ' | |
141 | ||
142 | test_expect_success 'merge c1 with c2 and c3 (recursive and octopus in pull.octopus)' ' | |
143 | git reset --hard c1 && | |
144 | git config pull.octopus "recursive octopus" && | |
145 | git merge c2 c3 && | |
146 | test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" && | |
147 | test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" && | |
148 | test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" && | |
149 | test "$(git rev-parse c3)" = "$(git rev-parse HEAD^3)" && | |
150 | git diff --exit-code && | |
151 | test -f c0.c && | |
152 | test -f c1.c && | |
153 | test -f c2.c && | |
154 | test -f c3.c | |
155 | ' | |
156 | ||
157 | conflict_count() | |
158 | { | |
1c666935 | 159 | { |
b2eabcc2 MV |
160 | git diff-files --name-only |
161 | git ls-files --unmerged | |
1c666935 | 162 | } | wc -l |
b2eabcc2 MV |
163 | } |
164 | ||
165 | # c4 - c5 | |
166 | # \ c6 | |
167 | # | |
168 | # There are two conflicts here: | |
169 | # | |
170 | # 1) Because foo.c is renamed to bar.c, recursive will handle this, | |
171 | # resolve won't. | |
172 | # | |
173 | # 2) One in conflict.c and that will always fail. | |
174 | ||
175 | test_expect_success 'setup conflicted merge' ' | |
176 | git reset --hard c0 && | |
177 | echo A >conflict.c && | |
178 | git add conflict.c && | |
179 | echo contents >foo.c && | |
180 | git add foo.c && | |
181 | git commit -m c4 && | |
182 | git tag c4 && | |
183 | echo B >conflict.c && | |
184 | git add conflict.c && | |
185 | git mv foo.c bar.c && | |
186 | git commit -m c5 && | |
187 | git tag c5 && | |
188 | git reset --hard c4 && | |
189 | echo C >conflict.c && | |
190 | git add conflict.c && | |
191 | echo secondline >> foo.c && | |
192 | git add foo.c && | |
193 | git commit -m c6 && | |
194 | git tag c6 | |
195 | ' | |
196 | ||
197 | # First do the merge with resolve and recursive then verify that | |
98e023de | 198 | # recursive is chosen. |
b2eabcc2 MV |
199 | |
200 | test_expect_success 'merge picks up the best result' ' | |
4d175ef7 MV |
201 | git config --unset-all pull.twohead && |
202 | git reset --hard c5 && | |
af7b2526 | 203 | test_must_fail git merge -s resolve c6 && |
4d175ef7 MV |
204 | resolve_count=$(conflict_count) && |
205 | git reset --hard c5 && | |
af7b2526 | 206 | test_must_fail git merge -s recursive c6 && |
4d175ef7 MV |
207 | recursive_count=$(conflict_count) && |
208 | git reset --hard c5 && | |
af7b2526 | 209 | test_must_fail git merge -s recursive -s resolve c6 && |
4d175ef7 MV |
210 | auto_count=$(conflict_count) && |
211 | test $auto_count = $recursive_count && | |
212 | test $auto_count != $resolve_count | |
213 | ' | |
214 | ||
215 | test_expect_success 'merge picks up the best result (from config)' ' | |
b2eabcc2 MV |
216 | git config pull.twohead "recursive resolve" && |
217 | git reset --hard c5 && | |
af7b2526 | 218 | test_must_fail git merge -s resolve c6 && |
1c666935 | 219 | resolve_count=$(conflict_count) && |
b2eabcc2 | 220 | git reset --hard c5 && |
af7b2526 | 221 | test_must_fail git merge -s recursive c6 && |
1c666935 | 222 | recursive_count=$(conflict_count) && |
b2eabcc2 | 223 | git reset --hard c5 && |
af7b2526 | 224 | test_must_fail git merge c6 && |
1c666935 MV |
225 | auto_count=$(conflict_count) && |
226 | test $auto_count = $recursive_count && | |
227 | test $auto_count != $resolve_count | |
b2eabcc2 MV |
228 | ' |
229 | ||
1719b5e4 MV |
230 | test_expect_success 'merge errors out on invalid strategy' ' |
231 | git config pull.twohead "foobar" && | |
232 | git reset --hard c5 && | |
233 | test_must_fail git merge c6 | |
234 | ' | |
235 | ||
236 | test_expect_success 'merge errors out on invalid strategy' ' | |
237 | git config --unset-all pull.twohead && | |
238 | git reset --hard c5 && | |
239 | test_must_fail git merge -s "resolve recursive" c6 | |
240 | ' | |
241 | ||
b2eabcc2 | 242 | test_done |