cache-tree: use ce_namelen() instead of strlen()
[git/debian.git] / t / t7601-merge-pull-config.sh
blob6774e9d86fa04c901b3833127e72f63a60028236
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 -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
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
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
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
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
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
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
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
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
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
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)"
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)"
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)"
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
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
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)"
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
160 conflict_count()
163 git diff-files --name-only
164 git ls-files --unmerged
165 } | wc -l
168 # c4 - c5
169 # \ c6
171 # There are two conflicts here:
173 # 1) Because foo.c is renamed to bar.c, recursive will handle this,
174 # resolve won't.
176 # 2) One in conflict.c and that will always fail.
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
200 # First do the merge with resolve and recursive then verify that
201 # recursive is chosen.
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
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
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
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
245 test_done