rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t6424-merge-unrelated-index-changes.sh
blob89dd544f3880c46b4207220427da86e1580c5789
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"
77 test_expect_success 'ff update, important file modified' '
78 git reset --hard &&
79 git checkout A^0 &&
81 mkdir subdir &&
82 touch subdir/e &&
83 git add subdir/e &&
85 test_must_fail git merge E^0 &&
86 test_path_is_missing .git/MERGE_HEAD
89 test_expect_success 'resolve, trivial' '
90 git reset --hard &&
91 git checkout B^0 &&
93 touch random_file && git add random_file &&
95 test_must_fail git merge -s resolve C^0 &&
96 test_path_is_missing .git/MERGE_HEAD
99 test_expect_success 'resolve, non-trivial' '
100 git reset --hard &&
101 git checkout B^0 &&
103 touch random_file && git add random_file &&
105 test_must_fail git merge -s resolve D^0 &&
106 test_path_is_missing .git/MERGE_HEAD
109 test_expect_success 'recursive' '
110 git reset --hard &&
111 git checkout B^0 &&
113 touch random_file && git add random_file &&
115 test_must_fail git merge -s recursive C^0 &&
116 test_path_is_missing .git/MERGE_HEAD
119 test_expect_success 'recursive, when merge branch matches merge base' '
120 git reset --hard &&
121 git checkout B^0 &&
123 touch random_file && git add random_file &&
125 test_must_fail git merge -s recursive F^0 &&
126 test_path_is_missing .git/MERGE_HEAD
129 test_expect_success 'merge-recursive, when index==head but head!=HEAD' '
130 git reset --hard &&
131 git checkout C^0 &&
133 # Make index match B
134 git diff C B -- | git apply --cached &&
135 test_when_finished "git clean -fd" && # Do not leave untracked around
136 # Merge B & F, with B as "head"
137 git merge-recursive A -- B F > out &&
138 test_i18ngrep "Already up to date" out
141 test_expect_success 'recursive, when file has staged changes not matching HEAD nor what a merge would give' '
142 git reset --hard &&
143 git checkout B^0 &&
145 mkdir subdir &&
146 test_seq 1 10 >subdir/a &&
147 git add subdir/a &&
149 # We have staged changes; merge should error out
150 test_must_fail git merge -s recursive E^0 2>err &&
151 test_i18ngrep "changes to the following files would be overwritten" err
154 test_expect_success 'recursive, when file has staged changes matching what a merge would give' '
155 git reset --hard &&
156 git checkout B^0 &&
158 mkdir subdir &&
159 test_seq 1 11 >subdir/a &&
160 git add subdir/a &&
162 # We have staged changes; merge should error out
163 test_must_fail git merge -s recursive E^0 2>err &&
164 test_i18ngrep "changes to the following files would be overwritten" err
167 test_expect_success 'octopus, unrelated file touched' '
168 git reset --hard &&
169 git checkout B^0 &&
171 touch random_file && git add random_file &&
173 test_must_fail git merge C^0 D^0 &&
174 test_path_is_missing .git/MERGE_HEAD
177 test_expect_success 'octopus, related file removed' '
178 git reset --hard &&
179 git checkout B^0 &&
181 git rm b &&
183 test_must_fail git merge C^0 D^0 &&
184 test_path_is_missing .git/MERGE_HEAD
187 test_expect_success 'octopus, related file modified' '
188 git reset --hard &&
189 git checkout B^0 &&
191 echo 12 >>a && git add a &&
193 test_must_fail git merge C^0 D^0 &&
194 test_path_is_missing .git/MERGE_HEAD
197 test_expect_success 'ours' '
198 git reset --hard &&
199 git checkout B^0 &&
201 touch random_file && git add random_file &&
203 test_must_fail git merge -s ours C^0 &&
204 test_path_is_missing .git/MERGE_HEAD
207 test_expect_success 'subtree' '
208 git reset --hard &&
209 git checkout B^0 &&
211 touch random_file && git add random_file &&
213 test_must_fail git merge -s subtree E^0 &&
214 test_path_is_missing .git/MERGE_HEAD
217 test_done