read-cache: delete unused hashing methods
[git] / t / t7601-merge-pull-config.sh
1 #!/bin/sh
2
3 test_description='git merge
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
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
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
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 &&
47         test_i18ngrep ! "Pulling without specifying how to reconcile" err
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
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
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
87 test_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
95 test_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
102 test_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
109 test_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
116 test_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
122 test_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
128 test_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
134 test_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
140 test_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
146 test_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
157 test_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
164 test_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
172 test_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
180 test_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
186 test_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
194 test_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
201 test_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
216 conflict_count()
217 {
218         {
219                 git diff-files --name-only
220                 git ls-files --unmerged
221         } | wc -l
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
234 test_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
257 # recursive is chosen.
258
259 test_expect_success 'merge picks up the best result' '
260         git config --unset-all pull.twohead &&
261         git reset --hard c5 &&
262         test_must_fail git merge -s resolve c6 &&
263         resolve_count=$(conflict_count) &&
264         git reset --hard c5 &&
265         test_must_fail git merge -s recursive c6 &&
266         recursive_count=$(conflict_count) &&
267         git reset --hard c5 &&
268         test_must_fail git merge -s recursive -s resolve c6 &&
269         auto_count=$(conflict_count) &&
270         test $auto_count = $recursive_count &&
271         test $auto_count != $resolve_count
272 '
273
274 test_expect_success 'merge picks up the best result (from config)' '
275         git config pull.twohead "recursive resolve" &&
276         git reset --hard c5 &&
277         test_must_fail git merge -s resolve c6 &&
278         resolve_count=$(conflict_count) &&
279         git reset --hard c5 &&
280         test_must_fail git merge -s recursive c6 &&
281         recursive_count=$(conflict_count) &&
282         git reset --hard c5 &&
283         test_must_fail git merge c6 &&
284         auto_count=$(conflict_count) &&
285         test $auto_count = $recursive_count &&
286         test $auto_count != $resolve_count
287 '
288
289 test_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
295 test_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
301 test_done