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