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 sum .
/test-lib.sh
>/dev
/null
2>&1 ||
{
19 _x40
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
20 _x40
="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
23 -e '/^--- /d; /^+++ /d; /^@@ /d;' \
24 -e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /' "$1"
25 git
diff expected current
29 clean_if_empty
=`git diff-files -- "$1"`
30 case "$clean_if_empty" in
31 '') echo "$1: clean" ;;
32 ?
*) echo "$1: dirty" ;;
34 case "$2,$clean_if_empty" in
45 echo nitfol >nitfol &&
46 echo bozbar >bozbar &&
47 echo rezrov >rezrov &&
48 git update-index --add nitfol bozbar rezrov &&
49 treeH=`git write-tree` &&
53 echo gnusto >bozbar &&
54 git update-index --add frotz bozbar --force-remove rezrov &&
55 git ls-files --stage >M.out &&
56 treeM=`git write-tree` &&
59 sum bozbar frotz nitfol >M.sum &&
60 git diff-tree $treeH $treeM'
63 '1, 2, 3 - no carry forward' \
64 'rm -f .git/index nitfol bozbar rezrov frotz &&
65 git read-tree --reset -u $treeH &&
66 git read-tree -m -u $treeH $treeM &&
67 git ls-files --stage >1-3.out &&
69 sum bozbar frotz nitfol >actual3.sum &&
70 cmp M.sum actual3.sum &&
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 git read-tree --reset -u $treeH &&
79 echo "+100644 X 0 yomin" >expected &&
81 git update-index --add yomin &&
82 git read-tree -m -u $treeH $treeM &&
83 git ls-files --stage >4.out || return 1
84 diff -U0 M.out 4.out >4diff.out
85 compare_change 4diff.out expected &&
86 check_cache_at yomin clean &&
87 sum bozbar frotz nitfol >actual4.sum &&
88 cmp M.sum actual4.sum &&
94 '5 - carry forward local addition.' \
95 'rm -f .git/index nitfol bozbar rezrov frotz &&
96 git read-tree --reset -u $treeH &&
97 git read-tree -m -u $treeH &&
99 git update-index --add yomin &&
100 echo yomin yomin >yomin &&
101 git read-tree -m -u $treeH $treeM &&
102 git ls-files --stage >5.out || return 1
103 diff -U0 M.out 5.out >5diff.out
104 compare_change 5diff.out expected &&
105 check_cache_at yomin dirty &&
106 sum bozbar frotz nitfol >actual5.sum &&
107 cmp M.sum actual5.sum &&
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 git read-tree --reset -u $treeH &&
118 git update-index --add frotz &&
119 git read-tree -m -u $treeH $treeM &&
120 git ls-files --stage >6.out &&
121 diff -U0 M.out 6.out &&
122 check_cache_at frotz clean &&
123 sum bozbar frotz nitfol >actual3.sum &&
124 cmp M.sum actual3.sum &&
125 echo frotz >frotz1 &&
129 test_expect_success \
130 '7 - local addition already has the same.' \
131 'rm -f .git/index nitfol bozbar rezrov frotz &&
132 git read-tree --reset -u $treeH &&
134 git update-index --add frotz &&
135 echo frotz frotz >frotz &&
136 git read-tree -m -u $treeH $treeM &&
137 git ls-files --stage >7.out &&
138 diff -U0 M.out 7.out &&
139 check_cache_at frotz dirty &&
140 sum bozbar frotz nitfol >actual7.sum &&
141 if cmp M.sum actual7.sum; then false; else :; fi &&
142 : dirty index should have prevented -u from checking it out. &&
143 echo frotz frotz >frotz1 &&
147 test_expect_success \
148 '8 - conflicting addition.' \
149 'rm -f .git/index nitfol bozbar rezrov frotz &&
150 git read-tree --reset -u $treeH &&
151 echo frotz frotz >frotz &&
152 git update-index --add frotz &&
153 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
155 test_expect_success \
156 '9 - conflicting addition.' \
157 'rm -f .git/index nitfol bozbar rezrov frotz &&
158 git read-tree --reset -u $treeH &&
159 echo frotz frotz >frotz &&
160 git update-index --add frotz &&
162 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
164 test_expect_success \
165 '10 - path removed.' \
166 'rm -f .git/index nitfol bozbar rezrov frotz &&
167 git read-tree --reset -u $treeH &&
168 echo rezrov >rezrov &&
169 git update-index --add rezrov &&
170 git read-tree -m -u $treeH $treeM &&
171 git ls-files --stage >10.out &&
173 sum bozbar frotz nitfol >actual10.sum &&
174 cmp M.sum actual10.sum'
176 test_expect_success \
177 '11 - dirty path removed.' \
178 'rm -f .git/index nitfol bozbar rezrov frotz &&
179 git read-tree --reset -u $treeH &&
180 echo rezrov >rezrov &&
181 git update-index --add rezrov &&
182 echo rezrov rezrov >rezrov &&
183 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
185 test_expect_success \
186 '12 - unmatching local changes being removed.' \
187 'rm -f .git/index nitfol bozbar rezrov frotz &&
188 git read-tree --reset -u $treeH &&
189 echo rezrov rezrov >rezrov &&
190 git update-index --add rezrov &&
191 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
193 test_expect_success \
194 '13 - unmatching local changes being removed.' \
195 'rm -f .git/index nitfol bozbar rezrov frotz &&
196 git read-tree --reset -u $treeH &&
197 echo rezrov rezrov >rezrov &&
198 git update-index --add rezrov &&
199 echo rezrov >rezrov &&
200 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
207 test_expect_success \
208 '14 - unchanged in two heads.' \
209 'rm -f .git/index nitfol bozbar rezrov frotz &&
210 git read-tree --reset -u $treeH &&
211 echo nitfol nitfol >nitfol &&
212 git update-index --add nitfol &&
213 git read-tree -m -u $treeH $treeM &&
214 git ls-files --stage >14.out || return 1
215 diff -U0 M.out 14.out >14diff.out
216 compare_change 14diff.out expected &&
217 sum bozbar frotz >actual14.sum &&
218 grep -v nitfol M.sum > expected14.sum &&
219 cmp expected14.sum actual14.sum &&
220 sum bozbar frotz nitfol >actual14a.sum &&
221 if cmp M.sum actual14a.sum; then false; else :; fi &&
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 git read-tree --reset -u $treeH &&
231 echo nitfol nitfol >nitfol &&
232 git update-index --add nitfol &&
233 echo nitfol nitfol nitfol >nitfol &&
234 git read-tree -m -u $treeH $treeM &&
235 git ls-files --stage >15.out || return 1
236 diff -U0 M.out 15.out >15diff.out
237 compare_change 15diff.out expected &&
238 check_cache_at nitfol dirty &&
239 sum bozbar frotz >actual15.sum &&
240 grep -v nitfol M.sum > expected15.sum &&
241 cmp expected15.sum actual15.sum &&
242 sum bozbar frotz nitfol >actual15a.sum &&
243 if cmp M.sum actual15a.sum; then false; else :; fi &&
244 echo nitfol nitfol nitfol >nitfol1 &&
245 diff nitfol nitfol1 &&
248 test_expect_success \
249 '16 - conflicting local change.' \
250 'rm -f .git/index nitfol bozbar rezrov frotz &&
251 git read-tree --reset -u $treeH &&
252 echo bozbar bozbar >bozbar &&
253 git update-index --add bozbar &&
254 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
256 test_expect_success \
257 '17 - conflicting local change.' \
258 'rm -f .git/index nitfol bozbar rezrov frotz &&
259 git read-tree --reset -u $treeH &&
260 echo bozbar bozbar >bozbar &&
261 git update-index --add bozbar &&
262 echo bozbar bozbar bozbar >bozbar &&
263 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
265 test_expect_success \
266 '18 - local change already having a good result.' \
267 'rm -f .git/index nitfol bozbar rezrov frotz &&
268 git read-tree --reset -u $treeH &&
269 echo gnusto >bozbar &&
270 git update-index --add bozbar &&
271 git read-tree -m -u $treeH $treeM &&
272 git ls-files --stage >18.out &&
273 diff -U0 M.out 18.out &&
274 check_cache_at bozbar clean &&
275 sum bozbar frotz nitfol >actual18.sum &&
276 cmp M.sum actual18.sum'
278 test_expect_success \
279 '19 - local change already having a good result, further modified.' \
280 'rm -f .git/index nitfol bozbar rezrov frotz &&
281 git read-tree --reset -u $treeH &&
282 echo gnusto >bozbar &&
283 git update-index --add bozbar &&
284 echo gnusto gnusto >bozbar &&
285 git read-tree -m -u $treeH $treeM &&
286 git ls-files --stage >19.out &&
287 diff -U0 M.out 19.out &&
288 check_cache_at bozbar dirty &&
289 sum frotz nitfol >actual19.sum &&
290 grep -v bozbar M.sum > expected19.sum &&
291 cmp expected19.sum actual19.sum &&
292 sum bozbar frotz nitfol >actual19a.sum &&
293 if cmp M.sum actual19a.sum; then false; else :; fi &&
294 echo gnusto gnusto >bozbar1 &&
295 diff bozbar bozbar1 &&
298 test_expect_success \
299 '20 - no local change, use new tree.' \
300 'rm -f .git/index nitfol bozbar rezrov frotz &&
301 git read-tree --reset -u $treeH &&
302 echo bozbar >bozbar &&
303 git update-index --add bozbar &&
304 git read-tree -m -u $treeH $treeM &&
305 git ls-files --stage >20.out &&
306 diff -U0 M.out 20.out &&
307 check_cache_at bozbar clean &&
308 sum bozbar frotz nitfol >actual20.sum &&
309 cmp M.sum actual20.sum'
311 test_expect_success \
312 '21 - no local change, dirty cache.' \
313 'rm -f .git/index nitfol bozbar rezrov frotz &&
314 git read-tree --reset -u $treeH &&
315 echo bozbar >bozbar &&
316 git update-index --add bozbar &&
317 echo gnusto gnusto >bozbar &&
318 if git read-tree -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 git read-tree -m -u $treeDF $treeDFDF &&
346 git ls-files --stage >DFDFcheck.out &&
347 diff -U0 DFDF.out DFDFcheck.out &&
348 check_cache_at DF/DF clean'