]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6044-merge-unrelated-index-changes.sh
Merge branch 'wb/fsmonitor-bitmap-fix'
[thirdparty/git.git] / t / t6044-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 &&
74 test "$(git diff --name-only --cached E)" = "random_file"
75'
76
77test_expect_success 'ff update, important file modified' '
78 git reset --hard &&
79 git checkout A^0 &&
80
81 mkdir subdir &&
82 touch subdir/e &&
83 git add subdir/e &&
84
58f4d1b9
EN
85 test_must_fail git merge E^0 &&
86 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
87'
88
89test_expect_success 'resolve, trivial' '
90 git reset --hard &&
91 git checkout B^0 &&
92
93 touch random_file && git add random_file &&
94
58f4d1b9
EN
95 test_must_fail git merge -s resolve C^0 &&
96 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
97'
98
99test_expect_success 'resolve, non-trivial' '
100 git reset --hard &&
101 git checkout B^0 &&
102
103 touch random_file && git add random_file &&
104
58f4d1b9
EN
105 test_must_fail git merge -s resolve D^0 &&
106 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
107'
108
109test_expect_success 'recursive' '
110 git reset --hard &&
111 git checkout B^0 &&
112
113 touch random_file && git add random_file &&
114
58f4d1b9
EN
115 test_must_fail git merge -s recursive C^0 &&
116 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
117'
118
92702392 119test_expect_success 'recursive, when merge branch matches merge base' '
eab3f285
EN
120 git reset --hard &&
121 git checkout B^0 &&
122
123 touch random_file && git add random_file &&
124
58f4d1b9
EN
125 test_must_fail git merge -s recursive F^0 &&
126 test_path_is_missing .git/MERGE_HEAD
eab3f285
EN
127'
128
e1f8694f 129test_expect_success 'merge-recursive, when index==head but head!=HEAD' '
cf69f2af
EN
130 git reset --hard &&
131 git checkout C^0 &&
132
133 # Make index match B
134 git diff C B -- | git apply --cached &&
135 # Merge B & F, with B as "head"
136 git merge-recursive A -- B F > out &&
137 test_i18ngrep "Already up to date" out
138'
139
eddd1a41 140test_expect_success 'recursive, when file has staged changes not matching HEAD nor what a merge would give' '
7f5271fa
EN
141 git reset --hard &&
142 git checkout B^0 &&
143
144 mkdir subdir &&
145 test_seq 1 10 >subdir/a &&
146 git add subdir/a &&
147
eddd1a41
EN
148 # We have staged changes; merge should error out
149 test_must_fail git merge -s recursive E^0 2>err &&
150 test_i18ngrep "changes to the following files would be overwritten" err
7f5271fa
EN
151'
152
eddd1a41 153test_expect_success 'recursive, when file has staged changes matching what a merge would give' '
7f5271fa
EN
154 git reset --hard &&
155 git checkout B^0 &&
156
157 mkdir subdir &&
158 test_seq 1 11 >subdir/a &&
159 git add subdir/a &&
160
eddd1a41
EN
161 # We have staged changes; merge should error out
162 test_must_fail git merge -s recursive E^0 2>err &&
163 test_i18ngrep "changes to the following files would be overwritten" err
7f5271fa
EN
164'
165
3ec62ad9 166test_expect_success 'octopus, unrelated file touched' '
a6ee883b
EN
167 git reset --hard &&
168 git checkout B^0 &&
169
170 touch random_file && git add random_file &&
171
58f4d1b9
EN
172 test_must_fail git merge C^0 D^0 &&
173 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
174'
175
3ec62ad9 176test_expect_success 'octopus, related file removed' '
a6ee883b
EN
177 git reset --hard &&
178 git checkout B^0 &&
179
180 git rm b &&
181
58f4d1b9
EN
182 test_must_fail git merge C^0 D^0 &&
183 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
184'
185
3ec62ad9 186test_expect_success 'octopus, related file modified' '
a6ee883b
EN
187 git reset --hard &&
188 git checkout B^0 &&
189
190 echo 12 >>a && git add a &&
191
58f4d1b9
EN
192 test_must_fail git merge C^0 D^0 &&
193 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
194'
195
196test_expect_success 'ours' '
197 git reset --hard &&
198 git checkout B^0 &&
199
200 touch random_file && git add random_file &&
201
58f4d1b9
EN
202 test_must_fail git merge -s ours C^0 &&
203 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
204'
205
206test_expect_success 'subtree' '
207 git reset --hard &&
208 git checkout B^0 &&
209
210 touch random_file && git add random_file &&
211
58f4d1b9
EN
212 test_must_fail git merge -s subtree E^0 &&
213 test_path_is_missing .git/MERGE_HEAD
a6ee883b
EN
214'
215
216test_done