list-objects-filter: handle null default filter spec
[alt-git.git] / t / t6424-merge-unrelated-index-changes.sh
blobb6e424a427b5566b2edf48b3d0a29ad6a927f67e
1 #!/bin/sh
3 test_description="merges with unrelated index changes"
5 . ./test-lib.sh
7 # Testcase for some simple merges
8 # A
9 # o-------o B
10 # \
11 # \-----o C
12 # \
13 # \---o D
14 # \
15 # \-o E
16 # \
17 # o F
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' '
26 test_seq 1 10 >a &&
27 git add a &&
28 test_tick && git commit -m A &&
30 git branch A &&
31 git branch B &&
32 git branch C &&
33 git branch D &&
34 git branch E &&
35 git branch F &&
37 git checkout B &&
38 echo b >b &&
39 echo 11 >>a &&
40 git add a b &&
41 test_tick && git commit -m B &&
43 git checkout C &&
44 echo c >c &&
45 git add c &&
46 test_tick && git commit -m C &&
48 git checkout D &&
49 test_seq 2 10 >a &&
50 echo d >d &&
51 git add a d &&
52 test_tick && git commit -m D &&
54 git checkout E &&
55 mkdir subdir &&
56 git mv a subdir/a &&
57 echo e >subdir/e &&
58 git add subdir &&
59 test_tick && git commit -m E &&
61 git checkout F &&
62 test_tick && git commit --allow-empty -m F
65 test_expect_success 'ff update' '
66 git reset --hard &&
67 git checkout A^0 &&
69 touch random_file && git add random_file &&
71 git merge E^0 &&
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' '
80 git reset --hard &&
81 git checkout A^0 &&
83 mkdir subdir &&
84 touch subdir/e &&
85 git add subdir/e &&
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' '
94 git reset --hard &&
95 git checkout B^0 &&
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' '
106 git reset --hard &&
107 git checkout B^0 &&
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 'recursive' '
118 git reset --hard &&
119 git checkout B^0 &&
121 touch random_file && git add random_file &&
123 test_must_fail git merge -s recursive C^0 &&
124 test_path_is_file random_file &&
125 git rev-parse --verify :random_file &&
126 test_path_is_missing .git/MERGE_HEAD
129 test_expect_success 'recursive, when merge branch matches merge base' '
130 git reset --hard &&
131 git checkout B^0 &&
133 touch random_file && git add random_file &&
135 test_must_fail git merge -s recursive F^0 &&
136 test_path_is_missing .git/MERGE_HEAD
139 test_expect_success 'merge-recursive, when index==head but head!=HEAD' '
140 git reset --hard &&
141 git checkout C^0 &&
143 # Make index match B
144 git diff C B -- | git apply --cached &&
145 test_when_finished "git clean -fd" && # Do not leave untracked around
146 # Merge B & F, with B as "head"
147 git merge-recursive A -- B F > out &&
148 test_i18ngrep "Already up to date" out
151 test_expect_success 'recursive, when file has staged changes not matching HEAD nor what a merge would give' '
152 git reset --hard &&
153 git checkout B^0 &&
155 mkdir subdir &&
156 test_seq 1 10 >subdir/a &&
157 git add subdir/a &&
158 git rev-parse --verify :subdir/a >expect &&
160 # We have staged changes; merge should error out
161 test_must_fail git merge -s recursive E^0 2>err &&
162 git rev-parse --verify :subdir/a >actual &&
163 test_cmp expect actual &&
164 test_i18ngrep "changes to the following files would be overwritten" err
167 test_expect_success 'recursive, when file has staged changes matching what a merge would give' '
168 git reset --hard &&
169 git checkout B^0 &&
171 mkdir subdir &&
172 test_seq 1 11 >subdir/a &&
173 git add subdir/a &&
174 git rev-parse --verify :subdir/a >expect &&
176 # We have staged changes; merge should error out
177 test_must_fail git merge -s recursive E^0 2>err &&
178 git rev-parse --verify :subdir/a >actual &&
179 test_cmp expect actual &&
180 test_i18ngrep "changes to the following files would be overwritten" err
183 test_expect_success 'octopus, unrelated file touched' '
184 git reset --hard &&
185 git checkout B^0 &&
187 touch random_file && git add random_file &&
189 test_must_fail git merge C^0 D^0 &&
190 test_path_is_missing .git/MERGE_HEAD &&
191 git rev-parse --verify :random_file &&
192 test_path_exists random_file
195 test_expect_success 'octopus, related file removed' '
196 git reset --hard &&
197 git checkout B^0 &&
199 git rm b &&
201 test_must_fail git merge C^0 D^0 &&
202 test_path_is_missing b &&
203 test_must_fail git rev-parse --verify :b &&
204 test_path_is_missing .git/MERGE_HEAD
207 test_expect_success 'octopus, related file modified' '
208 git reset --hard &&
209 git checkout B^0 &&
211 echo 12 >>a && git add a &&
212 git rev-parse --verify :a >expect &&
214 test_must_fail git merge C^0 D^0 &&
215 test_path_is_file a &&
216 git rev-parse --verify :a >actual &&
217 test_cmp expect actual &&
218 test_path_is_missing .git/MERGE_HEAD
221 test_expect_success 'ours' '
222 git reset --hard &&
223 git checkout B^0 &&
225 touch random_file && git add random_file &&
227 test_must_fail git merge -s ours C^0 &&
228 test_path_is_file random_file &&
229 git rev-parse --verify :random_file &&
230 test_path_is_missing .git/MERGE_HEAD
233 test_expect_success 'subtree' '
234 git reset --hard &&
235 git checkout B^0 &&
237 touch random_file && git add random_file &&
239 test_must_fail git merge -s subtree E^0 &&
240 test_path_is_file random_file &&
241 git rev-parse --verify :random_file &&
242 test_path_is_missing .git/MERGE_HEAD
245 test_done