grep: handle deref_tag() returning NULL
[git/debian.git] / t / t7601-merge-pull-config.sh
blobc5c4ea5fc09e335b41e021f04206c4328326c811
1 #!/bin/sh
3 test_description='git merge
5 Testing pull.* configuration parsing.'
7 . ./test-lib.sh
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
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
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
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
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
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
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
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
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
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
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
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)"
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)"
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)"
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
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
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)"
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
157 conflict_count()
160 git diff-files --name-only
161 git ls-files --unmerged
162 } | wc -l
165 # c4 - c5
166 # \ c6
168 # There are two conflicts here:
170 # 1) Because foo.c is renamed to bar.c, recursive will handle this,
171 # resolve won't.
173 # 2) One in conflict.c and that will always fail.
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
197 # First do the merge with resolve and recursive then verify that
198 # recursive is chosen.
200 test_expect_success 'merge picks up the best result' '
201 git config --unset-all pull.twohead &&
202 git reset --hard c5 &&
203 test_must_fail git merge -s resolve c6 &&
204 resolve_count=$(conflict_count) &&
205 git reset --hard c5 &&
206 test_must_fail git merge -s recursive c6 &&
207 recursive_count=$(conflict_count) &&
208 git reset --hard c5 &&
209 test_must_fail git merge -s recursive -s resolve c6 &&
210 auto_count=$(conflict_count) &&
211 test $auto_count = $recursive_count &&
212 test $auto_count != $resolve_count
215 test_expect_success 'merge picks up the best result (from config)' '
216 git config pull.twohead "recursive resolve" &&
217 git reset --hard c5 &&
218 test_must_fail git merge -s resolve c6 &&
219 resolve_count=$(conflict_count) &&
220 git reset --hard c5 &&
221 test_must_fail git merge -s recursive c6 &&
222 recursive_count=$(conflict_count) &&
223 git reset --hard c5 &&
224 test_must_fail git merge c6 &&
225 auto_count=$(conflict_count) &&
226 test $auto_count = $recursive_count &&
227 test $auto_count != $resolve_count
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
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
242 test_done