]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6424-merge-unrelated-index-changes.sh
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / t6424-merge-unrelated-index-changes.sh
CommitLineData
a6ee883b
EN
1#!/bin/sh
2
3test_description="merges with unrelated index changes"
4
5. ./test-lib.sh
6
7# Testcase for some simple merges
8# A
eab3f285 9# o-------o B
a6ee883b 10# \
eab3f285 11# \-----o C
a6ee883b 12# \
eab3f285 13# \---o D
a6ee883b 14# \
eab3f285
EN
15# \-o E
16# \
17# o F
a6ee883b
EN
18# Commit A: some file a
19# Commit B: adds file b, modifies end of a
20# Commit C: adds file c
21# Commit D: adds file d, modifies beginning of a
22# Commit E: renames a->subdir/a, adds subdir/e
eab3f285 23# Commit F: empty commit
a6ee883b
EN
24
25test_expect_success 'setup trivial merges' '
3f215b03 26 test_seq 1 10 >a &&
a6ee883b
EN
27 git add a &&
28 test_tick && git commit -m A &&
29
30 git branch A &&
31 git branch B &&
32 git branch C &&
33 git branch D &&
34 git branch E &&
eab3f285 35 git branch F &&
a6ee883b
EN
36
37 git checkout B &&
38 echo b >b &&
39 echo 11 >>a &&
40 git add a b &&
41 test_tick && git commit -m B &&
42
43 git checkout C &&
44 echo c >c &&
45 git add c &&
46 test_tick && git commit -m C &&
47
48 git checkout D &&
3f215b03 49 test_seq 2 10 >a &&
a6ee883b
EN
50 echo d >d &&
51 git add a d &&
52 test_tick && git commit -m D &&
53
54 git checkout E &&
55 mkdir subdir &&
56 git mv a subdir/a &&
57 echo e >subdir/e &&
58 git add subdir &&
eab3f285
EN
59 test_tick && git commit -m E &&
60
61 git checkout F &&
62 test_tick && git commit --allow-empty -m F
a6ee883b
EN
63'
64
65test_expect_success 'ff update' '
66 git reset --hard &&
67 git checkout A^0 &&
68
69 touch random_file && git add random_file &&
70
71 git merge E^0 &&
72
73 test_must_fail git rev-parse HEAD:random_file &&
4b317450
JH
74 test "$(git diff --name-only --cached E)" = "random_file" &&
75 test_path_is_file random_file &&
76 git rev-parse --verify :random_file
a6ee883b
EN
77'
78
79test_expect_success 'ff update, important file modified' '
80 git reset --hard &&
81 git checkout A^0 &&
82
83 mkdir subdir &&
84 touch subdir/e &&
85 git add subdir/e &&
86
58f4d1b9 87 test_must_fail git merge E^0 &&
4b317450
JH
88 test_path_is_file subdir/e &&
89 git rev-parse --verify :subdir/e &&
58f4d1b9 90 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
91'
92
93test_expect_success 'resolve, trivial' '
94 git reset --hard &&
95 git checkout B^0 &&
96
97 touch random_file && git add random_file &&
98
58f4d1b9 99 test_must_fail git merge -s resolve C^0 &&
4b317450
JH
100 test_path_is_file random_file &&
101 git rev-parse --verify :random_file &&
58f4d1b9 102 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
103'
104
105test_expect_success 'resolve, non-trivial' '
106 git reset --hard &&
107 git checkout B^0 &&
108
109 touch random_file && git add random_file &&
110
58f4d1b9 111 test_must_fail git merge -s resolve D^0 &&
4b317450
JH
112 test_path_is_file random_file &&
113 git rev-parse --verify :random_file &&
58f4d1b9 114 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
115'
116
e4cdfe84
EN
117test_expect_success 'resolve, trivial, related file removed' '
118 git reset --hard &&
119 git checkout B^0 &&
120
121 git rm a &&
122 test_path_is_missing a &&
123
124 test_must_fail git merge -s resolve C^0 &&
125
126 test_path_is_missing a &&
127 test_path_is_missing .git/MERGE_HEAD
128'
129
24ba8b70
EN
130test_expect_success 'resolve, non-trivial, related file removed' '
131 git reset --hard &&
132 git checkout B^0 &&
133
134 git rm a &&
135 test_path_is_missing a &&
136
e4cdfe84
EN
137 # We also ask for recursive in order to turn off the "allow_trivial"
138 # setting in builtin/merge.c, and ensure that resolve really does
139 # correctly fail the merge (I guess this also tests that recursive
140 # correctly fails the merge, but the main thing we are attempting
141 # to test here is resolve and are just using the side effect of
142 # adding recursive to ensure that resolve is actually tested rather
143 # than the trivial merge codepath)
144 test_must_fail git merge -s resolve -s recursive D^0 &&
24ba8b70
EN
145
146 test_path_is_missing a &&
147 test_path_is_missing .git/MERGE_HEAD
148'
149
a6ee883b
EN
150test_expect_success 'recursive' '
151 git reset --hard &&
152 git checkout B^0 &&
153
154 touch random_file && git add random_file &&
155
58f4d1b9 156 test_must_fail git merge -s recursive C^0 &&
4b317450
JH
157 test_path_is_file random_file &&
158 git rev-parse --verify :random_file &&
58f4d1b9 159 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
160'
161
92702392 162test_expect_success 'recursive, when merge branch matches merge base' '
eab3f285
EN
163 git reset --hard &&
164 git checkout B^0 &&
165
166 touch random_file && git add random_file &&
167
58f4d1b9
EN
168 test_must_fail git merge -s recursive F^0 &&
169 test_path_is_missing .git/MERGE_HEAD
eab3f285
EN
170'
171
e1f8694f 172test_expect_success 'merge-recursive, when index==head but head!=HEAD' '
cf69f2af
EN
173 git reset --hard &&
174 git checkout C^0 &&
175
176 # Make index match B
177 git diff C B -- | git apply --cached &&
f222bd34 178 test_when_finished "git clean -fd" && # Do not leave untracked around
cf69f2af
EN
179 # Merge B & F, with B as "head"
180 git merge-recursive A -- B F > out &&
181 test_i18ngrep "Already up to date" out
182'
183
eddd1a41 184test_expect_success 'recursive, when file has staged changes not matching HEAD nor what a merge would give' '
7f5271fa
EN
185 git reset --hard &&
186 git checkout B^0 &&
187
188 mkdir subdir &&
189 test_seq 1 10 >subdir/a &&
190 git add subdir/a &&
4b317450 191 git rev-parse --verify :subdir/a >expect &&
7f5271fa 192
eddd1a41
EN
193 # We have staged changes; merge should error out
194 test_must_fail git merge -s recursive E^0 2>err &&
4b317450
JH
195 git rev-parse --verify :subdir/a >actual &&
196 test_cmp expect actual &&
eddd1a41 197 test_i18ngrep "changes to the following files would be overwritten" err
7f5271fa
EN
198'
199
eddd1a41 200test_expect_success 'recursive, when file has staged changes matching what a merge would give' '
7f5271fa
EN
201 git reset --hard &&
202 git checkout B^0 &&
203
204 mkdir subdir &&
205 test_seq 1 11 >subdir/a &&
206 git add subdir/a &&
4b317450 207 git rev-parse --verify :subdir/a >expect &&
7f5271fa 208
eddd1a41
EN
209 # We have staged changes; merge should error out
210 test_must_fail git merge -s recursive E^0 2>err &&
4b317450
JH
211 git rev-parse --verify :subdir/a >actual &&
212 test_cmp expect actual &&
eddd1a41 213 test_i18ngrep "changes to the following files would be overwritten" err
7f5271fa
EN
214'
215
3ec62ad9 216test_expect_success 'octopus, unrelated file touched' '
a6ee883b
EN
217 git reset --hard &&
218 git checkout B^0 &&
219
220 touch random_file && git add random_file &&
221
58f4d1b9 222 test_must_fail git merge C^0 D^0 &&
4b317450
JH
223 test_path_is_missing .git/MERGE_HEAD &&
224 git rev-parse --verify :random_file &&
225 test_path_exists random_file
a6ee883b
EN
226'
227
3ec62ad9 228test_expect_success 'octopus, related file removed' '
a6ee883b
EN
229 git reset --hard &&
230 git checkout B^0 &&
231
232 git rm b &&
233
58f4d1b9 234 test_must_fail git merge C^0 D^0 &&
4b317450
JH
235 test_path_is_missing b &&
236 test_must_fail git rev-parse --verify :b &&
58f4d1b9 237 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
238'
239
3ec62ad9 240test_expect_success 'octopus, related file modified' '
a6ee883b
EN
241 git reset --hard &&
242 git checkout B^0 &&
243
244 echo 12 >>a && git add a &&
4b317450 245 git rev-parse --verify :a >expect &&
a6ee883b 246
58f4d1b9 247 test_must_fail git merge C^0 D^0 &&
4b317450
JH
248 test_path_is_file a &&
249 git rev-parse --verify :a >actual &&
250 test_cmp expect actual &&
58f4d1b9 251 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
252'
253
254test_expect_success 'ours' '
255 git reset --hard &&
256 git checkout B^0 &&
257
258 touch random_file && git add random_file &&
259
58f4d1b9 260 test_must_fail git merge -s ours C^0 &&
4b317450
JH
261 test_path_is_file random_file &&
262 git rev-parse --verify :random_file &&
58f4d1b9 263 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
264'
265
266test_expect_success 'subtree' '
267 git reset --hard &&
268 git checkout B^0 &&
269
270 touch random_file && git add random_file &&
271
58f4d1b9 272 test_must_fail git merge -s subtree E^0 &&
4b317450
JH
273 test_path_is_file random_file &&
274 git rev-parse --verify :random_file &&
58f4d1b9 275 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
276'
277
1369f147
EN
278test_expect_success 'avoid failure due to stat-dirty files' '
279 git reset --hard &&
280 git checkout B^0 &&
281
282 # Make "a" be stat-dirty
283 test-tool chmtime =+1 a &&
284
285 # stat-dirty file should not prevent stash creation in builtin/merge.c
286 git merge -s resolve -s recursive D^0
287'
288
8f240b8b
EN
289test_expect_success 'with multiple strategies, recursive or ort failure do not early abort' '
290 git reset --hard &&
291 git checkout B^0 &&
292
293 test_seq 0 10 >a &&
294 git add a &&
aa77ce88 295 git rev-parse :a >expect &&
8f240b8b
EN
296
297 sane_unset GIT_TEST_MERGE_ALGORITHM &&
298 test_must_fail git merge -s recursive -s ort -s octopus C^0 >output 2>&1 &&
299
300 grep "Trying merge strategy recursive..." output &&
301 grep "Trying merge strategy ort..." output &&
302 grep "Trying merge strategy octopus..." output &&
aa77ce88
EN
303 grep "No merge strategy handled the merge." output &&
304
305 # Changes to "a" should remain staged
306 git rev-parse :a >actual &&
307 test_cmp expect actual
8f240b8b
EN
308'
309
a6ee883b 310test_done