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