3 test_description
="merges with unrelated index changes"
7 # Testcase for some simple merges
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
23 # Commit F: empty commit
25 test_expect_success
'setup trivial merges' '
28 test_tick && git commit -m A &&
41 test_tick && git commit -m B &&
46 test_tick && git commit -m C &&
52 test_tick && git commit -m D &&
59 test_tick && git commit -m E &&
62 test_tick && git commit --allow-empty -m F
65 test_expect_success
'ff update' '
69 touch random_file && git add random_file &&
73 test_must_fail git rev-parse HEAD:random_file &&
74 test "$(git diff --name-only --cached E)" = "random_file" &&
75 test_path_is_file random_file &&
76 git rev-parse --verify :random_file
79 test_expect_success
'ff update, important file modified' '
87 test_must_fail git merge E^0 &&
88 test_path_is_file subdir/e &&
89 git rev-parse --verify :subdir/e &&
90 test_path_is_missing .git/MERGE_HEAD
93 test_expect_success
'resolve, trivial' '
97 touch random_file && git add random_file &&
99 test_must_fail git merge -s resolve C^0 &&
100 test_path_is_file random_file &&
101 git rev-parse --verify :random_file &&
102 test_path_is_missing .git/MERGE_HEAD
105 test_expect_success
'resolve, non-trivial' '
109 touch random_file && git add random_file &&
111 test_must_fail git merge -s resolve D^0 &&
112 test_path_is_file random_file &&
113 git rev-parse --verify :random_file &&
114 test_path_is_missing .git/MERGE_HEAD
117 test_expect_success
'resolve, trivial, related file removed' '
122 test_path_is_missing a &&
124 test_must_fail git merge -s resolve C^0 &&
126 test_path_is_missing a &&
127 test_path_is_missing .git/MERGE_HEAD
130 test_expect_success
'resolve, non-trivial, related file removed' '
135 test_path_is_missing a &&
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 &&
146 test_path_is_missing a &&
147 test_path_is_missing .git/MERGE_HEAD
150 test_expect_success
'recursive' '
154 touch random_file && git add random_file &&
156 test_must_fail git merge -s recursive C^0 &&
157 test_path_is_file random_file &&
158 git rev-parse --verify :random_file &&
159 test_path_is_missing .git/MERGE_HEAD
162 test_expect_success
'recursive, when merge branch matches merge base' '
166 touch random_file && git add random_file &&
168 test_must_fail git merge -s recursive F^0 &&
169 test_path_is_missing .git/MERGE_HEAD
172 test_expect_success
'merge-recursive, when index==head but head!=HEAD' '
177 git diff C B -- | git apply --cached &&
178 test_when_finished "git clean -fd" && # Do not leave untracked around
179 # Merge B & F, with B as "head"
180 git merge-recursive A -- B F > out &&
181 test_grep "Already up to date" out
184 test_expect_success
'recursive, when file has staged changes not matching HEAD nor what a merge would give' '
189 test_seq 1 10 >subdir/a &&
191 git rev-parse --verify :subdir/a >expect &&
193 # We have staged changes; merge should error out
194 test_must_fail git merge -s recursive E^0 2>err &&
195 git rev-parse --verify :subdir/a >actual &&
196 test_cmp expect actual &&
197 test_grep "changes to the following files would be overwritten" err
200 test_expect_success
'recursive, when file has staged changes matching what a merge would give' '
205 test_seq 1 11 >subdir/a &&
207 git rev-parse --verify :subdir/a >expect &&
209 # We have staged changes; merge should error out
210 test_must_fail git merge -s recursive E^0 2>err &&
211 git rev-parse --verify :subdir/a >actual &&
212 test_cmp expect actual &&
213 test_grep "changes to the following files would be overwritten" err
216 test_expect_success
'octopus, unrelated file touched' '
220 touch random_file && git add random_file &&
222 test_must_fail git merge C^0 D^0 &&
223 test_path_is_missing .git/MERGE_HEAD &&
224 git rev-parse --verify :random_file &&
225 test_path_exists random_file
228 test_expect_success
'octopus, related file removed' '
234 test_must_fail git merge C^0 D^0 &&
235 test_path_is_missing b &&
236 test_must_fail git rev-parse --verify :b &&
237 test_path_is_missing .git/MERGE_HEAD
240 test_expect_success
'octopus, related file modified' '
244 echo 12 >>a && git add a &&
245 git rev-parse --verify :a >expect &&
247 test_must_fail git merge C^0 D^0 &&
248 test_path_is_file a &&
249 git rev-parse --verify :a >actual &&
250 test_cmp expect actual &&
251 test_path_is_missing .git/MERGE_HEAD
254 test_expect_success
'ours' '
258 touch random_file && git add random_file &&
260 test_must_fail git merge -s ours C^0 &&
261 test_path_is_file random_file &&
262 git rev-parse --verify :random_file &&
263 test_path_is_missing .git/MERGE_HEAD
266 test_expect_success
'subtree' '
270 touch random_file && git add random_file &&
272 test_must_fail git merge -s subtree E^0 &&
273 test_path_is_file random_file &&
274 git rev-parse --verify :random_file &&
275 test_path_is_missing .git/MERGE_HEAD
278 test_expect_success
'avoid failure due to stat-dirty files' '
282 # Make "a" be stat-dirty
283 test-tool chmtime =+1 a &&
285 # stat-dirty file should not prevent stash creation in builtin/merge.c
286 git merge -s resolve -s recursive D^0
289 test_expect_success
'with multiple strategies, recursive or ort failure do not early abort' '
295 git rev-parse :a >expect &&
297 sane_unset GIT_TEST_MERGE_ALGORITHM &&
298 test_must_fail git merge -s recursive -s ort -s octopus C^0 >output 2>&1 &&
300 grep "Trying merge strategy recursive..." output &&
301 grep "Trying merge strategy ort..." output &&
302 grep "Trying merge strategy octopus..." output &&
303 grep "No merge strategy handled the merge." output &&
305 # Changes to "a" should remain staged
306 git rev-parse :a >actual &&
307 test_cmp expect actual