]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7601-merge-pull-config.sh
Merge branch 'ab/detox-gettext-tests'
[thirdparty/git.git] / t / t7601-merge-pull-config.sh
CommitLineData
b2eabcc2
MV
1#!/bin/sh
2
47a528ad 3test_description='git merge
b2eabcc2
MV
4
5Testing pull.* configuration parsing.'
6
7. ./test-lib.sh
8
9test_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
30test_expect_success 'pull.rebase not set' '
31 git reset --hard c0 &&
c525de33
FC
32 git pull . c1 2>err &&
33 test_i18ngrep ! "Pulling without specifying how to reconcile" err
d18c950a
AH
34'
35
54200cef
AH
36test_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
43test_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
50test_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
57test_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
63test_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
69test_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
75test_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
81test_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
c525de33
FC
87test_expect_success 'pull.rebase not set (not-fast-forward)' '
88 git reset --hard c2 &&
89 git -c color.advice=always pull . c1 2>err &&
90 test_decode_color <err >decoded &&
91 test_i18ngrep "<YELLOW>hint: " decoded &&
92 test_i18ngrep "Pulling without specifying how to reconcile" decoded
93'
94
95test_expect_success 'pull.rebase not set and pull.ff=true (not-fast-forward)' '
96 git reset --hard c2 &&
97 test_config pull.ff true &&
98 git pull . c1 2>err &&
99 test_i18ngrep ! "Pulling without specifying how to reconcile" err
100'
101
102test_expect_success 'pull.rebase not set and pull.ff=false (not-fast-forward)' '
103 git reset --hard c2 &&
104 test_config pull.ff false &&
105 git pull . c1 2>err &&
106 test_i18ngrep ! "Pulling without specifying how to reconcile" err
107'
108
109test_expect_success 'pull.rebase not set and pull.ff=only (not-fast-forward)' '
110 git reset --hard c2 &&
111 test_config pull.ff only &&
112 test_must_fail git pull . c1 2>err &&
113 test_i18ngrep ! "Pulling without specifying how to reconcile" err
114'
115
116test_expect_success 'pull.rebase not set and --rebase given (not-fast-forward)' '
117 git reset --hard c2 &&
118 git pull --rebase . c1 2>err &&
119 test_i18ngrep ! "Pulling without specifying how to reconcile" err
120'
121
122test_expect_success 'pull.rebase not set and --no-rebase given (not-fast-forward)' '
123 git reset --hard c2 &&
124 git pull --no-rebase . c1 2>err &&
125 test_i18ngrep ! "Pulling without specifying how to reconcile" err
126'
127
128test_expect_success 'pull.rebase not set and --ff given (not-fast-forward)' '
129 git reset --hard c2 &&
130 git pull --ff . c1 2>err &&
131 test_i18ngrep ! "Pulling without specifying how to reconcile" err
132'
133
134test_expect_success 'pull.rebase not set and --no-ff given (not-fast-forward)' '
135 git reset --hard c2 &&
136 git pull --no-ff . c1 2>err &&
137 test_i18ngrep ! "Pulling without specifying how to reconcile" err
138'
139
140test_expect_success 'pull.rebase not set and --ff-only given (not-fast-forward)' '
141 git reset --hard c2 &&
142 test_must_fail git pull --ff-only . c1 2>err &&
143 test_i18ngrep ! "Pulling without specifying how to reconcile" err
144'
145
b2eabcc2
MV
146test_expect_success 'merge c1 with c2' '
147 git reset --hard c1 &&
148 test -f c0.c &&
149 test -f c1.c &&
150 test ! -f c2.c &&
151 test ! -f c3.c &&
152 git merge c2 &&
153 test -f c1.c &&
154 test -f c2.c
155'
156
b814da89
DA
157test_expect_success 'fast-forward pull succeeds with "true" in pull.ff' '
158 git reset --hard c0 &&
159 test_config pull.ff true &&
160 git pull . c1 &&
161 test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
162'
163
eb8dc05c
PT
164test_expect_success 'pull.ff=true overrides merge.ff=false' '
165 git reset --hard c0 &&
166 test_config merge.ff false &&
167 test_config pull.ff true &&
168 git pull . c1 &&
169 test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
170'
171
b814da89
DA
172test_expect_success 'fast-forward pull creates merge with "false" in pull.ff' '
173 git reset --hard c0 &&
174 test_config pull.ff false &&
175 git pull . c1 &&
176 test "$(git rev-parse HEAD^1)" = "$(git rev-parse c0)" &&
177 test "$(git rev-parse HEAD^2)" = "$(git rev-parse c1)"
178'
179
180test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' '
181 git reset --hard c1 &&
182 test_config pull.ff only &&
183 test_must_fail git pull . c3
184'
185
b2eabcc2
MV
186test_expect_success 'merge c1 with c2 (ours in pull.twohead)' '
187 git reset --hard c1 &&
188 git config pull.twohead ours &&
189 git merge c2 &&
190 test -f c1.c &&
191 ! test -f c2.c
192'
193
194test_expect_success 'merge c1 with c2 and c3 (recursive in pull.octopus)' '
195 git reset --hard c1 &&
196 git config pull.octopus "recursive" &&
197 test_must_fail git merge c2 c3 &&
198 test "$(git rev-parse c1)" = "$(git rev-parse HEAD)"
199'
200
201test_expect_success 'merge c1 with c2 and c3 (recursive and octopus in pull.octopus)' '
202 git reset --hard c1 &&
203 git config pull.octopus "recursive octopus" &&
204 git merge c2 c3 &&
205 test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
206 test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" &&
207 test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" &&
208 test "$(git rev-parse c3)" = "$(git rev-parse HEAD^3)" &&
209 git diff --exit-code &&
210 test -f c0.c &&
211 test -f c1.c &&
212 test -f c2.c &&
213 test -f c3.c
214'
215
216conflict_count()
217{
1c666935 218 {
b2eabcc2
MV
219 git diff-files --name-only
220 git ls-files --unmerged
1c666935 221 } | wc -l
b2eabcc2
MV
222}
223
224# c4 - c5
225# \ c6
226#
227# There are two conflicts here:
228#
229# 1) Because foo.c is renamed to bar.c, recursive will handle this,
230# resolve won't.
231#
232# 2) One in conflict.c and that will always fail.
233
234test_expect_success 'setup conflicted merge' '
235 git reset --hard c0 &&
236 echo A >conflict.c &&
237 git add conflict.c &&
238 echo contents >foo.c &&
239 git add foo.c &&
240 git commit -m c4 &&
241 git tag c4 &&
242 echo B >conflict.c &&
243 git add conflict.c &&
244 git mv foo.c bar.c &&
245 git commit -m c5 &&
246 git tag c5 &&
247 git reset --hard c4 &&
248 echo C >conflict.c &&
249 git add conflict.c &&
250 echo secondline >> foo.c &&
251 git add foo.c &&
252 git commit -m c6 &&
253 git tag c6
254'
255
256# First do the merge with resolve and recursive then verify that
98e023de 257# recursive is chosen.
b2eabcc2
MV
258
259test_expect_success 'merge picks up the best result' '
4d175ef7
MV
260 git config --unset-all pull.twohead &&
261 git reset --hard c5 &&
af7b2526 262 test_must_fail git merge -s resolve c6 &&
4d175ef7
MV
263 resolve_count=$(conflict_count) &&
264 git reset --hard c5 &&
af7b2526 265 test_must_fail git merge -s recursive c6 &&
4d175ef7
MV
266 recursive_count=$(conflict_count) &&
267 git reset --hard c5 &&
af7b2526 268 test_must_fail git merge -s recursive -s resolve c6 &&
4d175ef7
MV
269 auto_count=$(conflict_count) &&
270 test $auto_count = $recursive_count &&
271 test $auto_count != $resolve_count
272'
273
274test_expect_success 'merge picks up the best result (from config)' '
b2eabcc2
MV
275 git config pull.twohead "recursive resolve" &&
276 git reset --hard c5 &&
af7b2526 277 test_must_fail git merge -s resolve c6 &&
1c666935 278 resolve_count=$(conflict_count) &&
b2eabcc2 279 git reset --hard c5 &&
af7b2526 280 test_must_fail git merge -s recursive c6 &&
1c666935 281 recursive_count=$(conflict_count) &&
b2eabcc2 282 git reset --hard c5 &&
af7b2526 283 test_must_fail git merge c6 &&
1c666935
MV
284 auto_count=$(conflict_count) &&
285 test $auto_count = $recursive_count &&
286 test $auto_count != $resolve_count
b2eabcc2
MV
287'
288
1719b5e4
MV
289test_expect_success 'merge errors out on invalid strategy' '
290 git config pull.twohead "foobar" &&
291 git reset --hard c5 &&
292 test_must_fail git merge c6
293'
294
295test_expect_success 'merge errors out on invalid strategy' '
296 git config --unset-all pull.twohead &&
297 git reset --hard c5 &&
298 test_must_fail git merge -s "resolve recursive" c6
299'
300
b2eabcc2 301test_done