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.
12 . "$TEST_DIRECTORY"/lib-read-tree.sh
16 -e '1{/^diff --git /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
24 clean_if_empty=$(git diff-files -- "$1")
25 case "$clean_if_empty" in
26 '') echo "$1: clean" ;;
27 ?*) echo "$1: dirty" ;;
29 case "$2,$clean_if_empty" in
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) &&
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) &&
57 git diff-tree $treeH $treeM'
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 &&
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'
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 &&
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 &&
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 &&
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 &&
113 test_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 &&
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 &&
130 test_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 &&
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 &&
148 test_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'
156 test_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 &&
163 if read_tree_u_must_succeed -m -u $treeH $treeM; then false; else :; fi'
165 test_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 &&
174 test_cmp bozbar.M bozbar &&
175 test_cmp frotz.M frotz &&
176 test_cmp nitfol.M nitfol
179 test_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'
188 test_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'
196 test_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'
210 test_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 &&
227 test_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 &&
245 test_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'
253 test_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'
262 test_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
277 test_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 &&
294 test_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
309 test_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'
318 # Also make sure we did not break DF vs DF/DF case.
319 test_expect_success \
320 'DF vs DF/DF case setup.' \
323 git update-index --add DF &&
324 treeDF=$(git write-tree) &&
325 echo treeDF $treeDF &&
326 git ls-tree $treeDF &&
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'
337 test_expect_success \
338 'DF vs DF/DF case test.' \
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'