]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1002-read-tree-m-u-2way.sh
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / t / t1002-read-tree-m-u-2way.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 #
5
6 test_description='Two way merge with read-tree -m -u $H $M
7
8 This is identical to t1001, but uses -u to update the work tree as well.
9
10 '
11
12 TEST_PASSES_SANITIZE_LEAK=true
13 . ./test-lib.sh
14 . "$TEST_DIRECTORY"/lib-read-tree.sh
15
16 compare_change () {
17 sed >current \
18 -e '1{/^diff --git /d;}' \
19 -e '2{/^index /d;}' \
20 -e '/^--- /d; /^+++ /d; /^@@ /d;' \
21 -e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$OID_REGEX"' /\1 X /' "$1"
22 test_cmp expected current
23 }
24
25 check_cache_at () {
26 clean_if_empty=$(git diff-files -- "$1")
27 case "$clean_if_empty" in
28 '') echo "$1: clean" ;;
29 ?*) echo "$1: dirty" ;;
30 esac
31 case "$2,$clean_if_empty" in
32 clean,) : ;;
33 clean,?*) false ;;
34 dirty,) false ;;
35 dirty,?*) : ;;
36 esac
37 }
38
39 test_expect_success \
40 setup \
41 'echo frotz >frotz &&
42 echo nitfol >nitfol &&
43 echo bozbar >bozbar &&
44 echo rezrov >rezrov &&
45 git update-index --add nitfol bozbar rezrov &&
46 treeH=$(git write-tree) &&
47 echo treeH $treeH &&
48 git ls-tree $treeH &&
49
50 echo gnusto >bozbar &&
51 git update-index --add frotz bozbar --force-remove rezrov &&
52 git ls-files --stage >M.out &&
53 treeM=$(git write-tree) &&
54 echo treeM $treeM &&
55 git ls-tree $treeM &&
56 cp bozbar bozbar.M &&
57 cp frotz frotz.M &&
58 cp nitfol nitfol.M &&
59 git diff-tree $treeH $treeM'
60
61 test_expect_success \
62 '1, 2, 3 - no carry forward' \
63 'rm -f .git/index nitfol bozbar rezrov frotz &&
64 read_tree_u_must_succeed --reset -u $treeH &&
65 read_tree_u_must_succeed -m -u $treeH $treeM &&
66 git ls-files --stage >1-3.out &&
67 cmp M.out 1-3.out &&
68 test_cmp bozbar.M bozbar &&
69 test_cmp frotz.M frotz &&
70 test_cmp nitfol.M nitfol &&
71 check_cache_at bozbar clean &&
72 check_cache_at frotz clean &&
73 check_cache_at nitfol clean'
74
75 test_expect_success \
76 '4 - carry forward local addition.' \
77 'rm -f .git/index nitfol bozbar rezrov frotz &&
78 read_tree_u_must_succeed --reset -u $treeH &&
79 echo "+100644 X 0 yomin" >expected &&
80 echo yomin >yomin &&
81 git update-index --add yomin &&
82 read_tree_u_must_succeed -m -u $treeH $treeM &&
83 git ls-files --stage >4.out &&
84 test_might_fail git diff -U0 --no-index M.out 4.out >4diff.out &&
85 compare_change 4diff.out expected &&
86 check_cache_at yomin clean &&
87 test_cmp bozbar.M bozbar &&
88 test_cmp frotz.M frotz &&
89 test_cmp nitfol.M nitfol &&
90 echo yomin >yomin1 &&
91 diff yomin yomin1 &&
92 rm -f yomin1'
93
94 test_expect_success \
95 '5 - carry forward local addition.' \
96 'rm -f .git/index nitfol bozbar rezrov frotz &&
97 read_tree_u_must_succeed --reset -u $treeH &&
98 read_tree_u_must_succeed -m -u $treeH &&
99 echo yomin >yomin &&
100 git update-index --add yomin &&
101 echo yomin yomin >yomin &&
102 read_tree_u_must_succeed -m -u $treeH $treeM &&
103 git ls-files --stage >5.out &&
104 test_might_fail git diff -U0 --no-index M.out 5.out >5diff.out &&
105 compare_change 5diff.out expected &&
106 check_cache_at yomin dirty &&
107 test_cmp bozbar.M bozbar &&
108 test_cmp frotz.M frotz &&
109 test_cmp nitfol.M nitfol &&
110 : dirty index should have prevented -u from checking it out. &&
111 echo yomin yomin >yomin1 &&
112 diff yomin yomin1 &&
113 rm -f yomin1'
114
115 test_expect_success \
116 '6 - local addition already has the same.' \
117 'rm -f .git/index nitfol bozbar rezrov frotz &&
118 read_tree_u_must_succeed --reset -u $treeH &&
119 echo frotz >frotz &&
120 git update-index --add frotz &&
121 read_tree_u_must_succeed -m -u $treeH $treeM &&
122 git ls-files --stage >6.out &&
123 test_cmp M.out 6.out &&
124 check_cache_at frotz clean &&
125 test_cmp bozbar.M bozbar &&
126 test_cmp frotz.M frotz &&
127 test_cmp nitfol.M nitfol &&
128 echo frotz >frotz1 &&
129 diff frotz frotz1 &&
130 rm -f frotz1'
131
132 test_expect_success \
133 '7 - local addition already has the same.' \
134 'rm -f .git/index nitfol bozbar rezrov frotz &&
135 read_tree_u_must_succeed --reset -u $treeH &&
136 echo frotz >frotz &&
137 git update-index --add frotz &&
138 echo frotz frotz >frotz &&
139 read_tree_u_must_succeed -m -u $treeH $treeM &&
140 git ls-files --stage >7.out &&
141 test_cmp M.out 7.out &&
142 check_cache_at frotz dirty &&
143 test_cmp bozbar.M bozbar &&
144 test_cmp nitfol.M nitfol &&
145 : dirty index should have prevented -u from checking it out. &&
146 echo frotz frotz >frotz1 &&
147 diff frotz frotz1 &&
148 rm -f frotz1'
149
150 test_expect_success \
151 '8 - conflicting addition.' \
152 'rm -f .git/index nitfol bozbar rezrov frotz &&
153 read_tree_u_must_succeed --reset -u $treeH &&
154 echo frotz frotz >frotz &&
155 git update-index --add frotz &&
156 if read_tree_u_must_succeed -m -u $treeH $treeM; then false; else :; fi'
157
158 test_expect_success \
159 '9 - conflicting addition.' \
160 'rm -f .git/index nitfol bozbar rezrov frotz &&
161 read_tree_u_must_succeed --reset -u $treeH &&
162 echo frotz frotz >frotz &&
163 git update-index --add frotz &&
164 echo frotz >frotz &&
165 if read_tree_u_must_succeed -m -u $treeH $treeM; then false; else :; fi'
166
167 test_expect_success \
168 '10 - path removed.' \
169 'rm -f .git/index nitfol bozbar rezrov frotz &&
170 read_tree_u_must_succeed --reset -u $treeH &&
171 echo rezrov >rezrov &&
172 git update-index --add rezrov &&
173 read_tree_u_must_succeed -m -u $treeH $treeM &&
174 git ls-files --stage >10.out &&
175 cmp M.out 10.out &&
176 test_cmp bozbar.M bozbar &&
177 test_cmp frotz.M frotz &&
178 test_cmp nitfol.M nitfol
179 '
180
181 test_expect_success \
182 '11 - dirty path removed.' \
183 'rm -f .git/index nitfol bozbar rezrov frotz &&
184 read_tree_u_must_succeed --reset -u $treeH &&
185 echo rezrov >rezrov &&
186 git update-index --add rezrov &&
187 echo rezrov rezrov >rezrov &&
188 if read_tree_u_must_succeed -m -u $treeH $treeM; then false; else :; fi'
189
190 test_expect_success \
191 '12 - unmatching local changes being removed.' \
192 'rm -f .git/index nitfol bozbar rezrov frotz &&
193 read_tree_u_must_succeed --reset -u $treeH &&
194 echo rezrov rezrov >rezrov &&
195 git update-index --add rezrov &&
196 if read_tree_u_must_succeed -m -u $treeH $treeM; then false; else :; fi'
197
198 test_expect_success \
199 '13 - unmatching local changes being removed.' \
200 'rm -f .git/index nitfol bozbar rezrov frotz &&
201 read_tree_u_must_succeed --reset -u $treeH &&
202 echo rezrov rezrov >rezrov &&
203 git update-index --add rezrov &&
204 echo rezrov >rezrov &&
205 if read_tree_u_must_succeed -m -u $treeH $treeM; then false; else :; fi'
206
207 cat >expected <<EOF
208 -100644 X 0 nitfol
209 +100644 X 0 nitfol
210 EOF
211
212 test_expect_success \
213 '14 - unchanged in two heads.' \
214 'rm -f .git/index nitfol bozbar rezrov frotz &&
215 read_tree_u_must_succeed --reset -u $treeH &&
216 echo nitfol nitfol >nitfol &&
217 git update-index --add nitfol &&
218 read_tree_u_must_succeed -m -u $treeH $treeM &&
219 git ls-files --stage >14.out &&
220 test_must_fail git diff -U0 --no-index M.out 14.out >14diff.out &&
221 compare_change 14diff.out expected &&
222 test_cmp bozbar.M bozbar &&
223 test_cmp frotz.M frotz &&
224 check_cache_at nitfol clean &&
225 echo nitfol nitfol >nitfol1 &&
226 diff nitfol nitfol1 &&
227 rm -f nitfol1'
228
229 test_expect_success \
230 '15 - unchanged in two heads.' \
231 'rm -f .git/index nitfol bozbar rezrov frotz &&
232 read_tree_u_must_succeed --reset -u $treeH &&
233 echo nitfol nitfol >nitfol &&
234 git update-index --add nitfol &&
235 echo nitfol nitfol nitfol >nitfol &&
236 read_tree_u_must_succeed -m -u $treeH $treeM &&
237 git ls-files --stage >15.out &&
238 test_must_fail git diff -U0 --no-index M.out 15.out >15diff.out &&
239 compare_change 15diff.out expected &&
240 check_cache_at nitfol dirty &&
241 test_cmp bozbar.M bozbar &&
242 test_cmp frotz.M frotz &&
243 echo nitfol nitfol nitfol >nitfol1 &&
244 diff nitfol nitfol1 &&
245 rm -f nitfol1'
246
247 test_expect_success \
248 '16 - conflicting local change.' \
249 'rm -f .git/index nitfol bozbar rezrov frotz &&
250 read_tree_u_must_succeed --reset -u $treeH &&
251 echo bozbar bozbar >bozbar &&
252 git update-index --add bozbar &&
253 if read_tree_u_must_succeed -m -u $treeH $treeM; then false; else :; fi'
254
255 test_expect_success \
256 '17 - conflicting local change.' \
257 'rm -f .git/index nitfol bozbar rezrov frotz &&
258 read_tree_u_must_succeed --reset -u $treeH &&
259 echo bozbar bozbar >bozbar &&
260 git update-index --add bozbar &&
261 echo bozbar bozbar bozbar >bozbar &&
262 if read_tree_u_must_succeed -m -u $treeH $treeM; then false; else :; fi'
263
264 test_expect_success \
265 '18 - local change already having a good result.' \
266 'rm -f .git/index nitfol bozbar rezrov frotz &&
267 read_tree_u_must_succeed --reset -u $treeH &&
268 echo gnusto >bozbar &&
269 git update-index --add bozbar &&
270 read_tree_u_must_succeed -m -u $treeH $treeM &&
271 git ls-files --stage >18.out &&
272 test_cmp M.out 18.out &&
273 check_cache_at bozbar clean &&
274 test_cmp bozbar.M bozbar &&
275 test_cmp frotz.M frotz &&
276 test_cmp nitfol.M nitfol
277 '
278
279 test_expect_success \
280 '19 - local change already having a good result, further modified.' \
281 'rm -f .git/index nitfol bozbar rezrov frotz &&
282 read_tree_u_must_succeed --reset -u $treeH &&
283 echo gnusto >bozbar &&
284 git update-index --add bozbar &&
285 echo gnusto gnusto >bozbar &&
286 read_tree_u_must_succeed -m -u $treeH $treeM &&
287 git ls-files --stage >19.out &&
288 test_cmp M.out 19.out &&
289 check_cache_at bozbar dirty &&
290 test_cmp frotz.M frotz &&
291 test_cmp nitfol.M nitfol &&
292 echo gnusto gnusto >bozbar1 &&
293 diff bozbar bozbar1 &&
294 rm -f bozbar1'
295
296 test_expect_success \
297 '20 - no local change, use new tree.' \
298 'rm -f .git/index nitfol bozbar rezrov frotz &&
299 read_tree_u_must_succeed --reset -u $treeH &&
300 echo bozbar >bozbar &&
301 git update-index --add bozbar &&
302 read_tree_u_must_succeed -m -u $treeH $treeM &&
303 git ls-files --stage >20.out &&
304 test_cmp M.out 20.out &&
305 check_cache_at bozbar clean &&
306 test_cmp bozbar.M bozbar &&
307 test_cmp frotz.M frotz &&
308 test_cmp nitfol.M nitfol
309 '
310
311 test_expect_success \
312 '21 - no local change, dirty cache.' \
313 'rm -f .git/index nitfol bozbar rezrov frotz &&
314 read_tree_u_must_succeed --reset -u $treeH &&
315 echo bozbar >bozbar &&
316 git update-index --add bozbar &&
317 echo gnusto gnusto >bozbar &&
318 if read_tree_u_must_succeed -m -u $treeH $treeM; then false; else :; fi'
319
320 # Also make sure we did not break DF vs DF/DF case.
321 test_expect_success \
322 'DF vs DF/DF case setup.' \
323 'rm -f .git/index &&
324 echo DF >DF &&
325 git update-index --add DF &&
326 treeDF=$(git write-tree) &&
327 echo treeDF $treeDF &&
328 git ls-tree $treeDF &&
329
330 rm -f DF &&
331 mkdir DF &&
332 echo DF/DF >DF/DF &&
333 git update-index --add --remove DF DF/DF &&
334 treeDFDF=$(git write-tree) &&
335 echo treeDFDF $treeDFDF &&
336 git ls-tree $treeDFDF &&
337 git ls-files --stage >DFDF.out'
338
339 test_expect_success \
340 'DF vs DF/DF case test.' \
341 'rm -f .git/index &&
342 rm -fr DF &&
343 echo DF >DF &&
344 git update-index --add DF &&
345 read_tree_u_must_succeed -m -u $treeDF $treeDFDF &&
346 git ls-files --stage >DFDFcheck.out &&
347 test_cmp DFDF.out DFDFcheck.out &&
348 check_cache_at DF/DF clean'
349
350 test_done