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