3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='Two way merge with read-tree -m -u $H $M
8 This is identical to t1001, but uses -u to update the work tree as well.
13 .
"$TEST_DIRECTORY"/lib-read-tree.sh
17 -e '1{/^diff --git /d;}' \
19 -e '/^--- /d; /^+++ /d; /^@@ /d;' \
20 -e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$OID_REGEX"' /\1 X /' "$1"
21 test_cmp expected current
25 git diff-files
-- "$1" >out
&&
26 clean_if_empty
=$
(cat out
) &&
27 case "$clean_if_empty" in
28 '') echo "$1: clean" ;;
29 ?
*) echo "$1: dirty" ;;
31 case "$2,$clean_if_empty" in
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) &&
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) &&
59 git diff-tree $treeH $treeM'
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 &&
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'
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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'
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 &&
165 if read_tree_u_must_succeed -m -u $treeH $treeM; then false; else :; fi'
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 &&
176 test_cmp bozbar.M bozbar &&
177 test_cmp frotz.M frotz &&
178 test_cmp nitfol.M nitfol
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'
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'
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'
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 &&
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 &&
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'
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'
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
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 &&
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
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'
320 # Also make sure we did not break DF vs DF/DF case.
321 test_expect_success \
322 'DF vs DF/DF case setup.' \
325 git update-index --add DF &&
326 treeDF=$(git write-tree) &&
327 echo treeDF $treeDF &&
328 git ls-tree $treeDF &&
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'
339 test_expect_success \
340 'DF vs DF/DF case test.' \
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'