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