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 _x40
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
14 _x40
="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
17 -e '/^--- /d; /^+++ /d; /^@@ /d;' \
18 -e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /' "$1"
19 git
diff expected current
23 clean_if_empty
=`git diff-files -- "$1"`
24 case "$clean_if_empty" in
25 '') echo "$1: clean" ;;
26 ?
*) echo "$1: dirty" ;;
28 case "$2,$clean_if_empty" in
39 echo nitfol >nitfol &&
40 echo bozbar >bozbar &&
41 echo rezrov >rezrov &&
42 git update-index --add nitfol bozbar rezrov &&
43 treeH=`git write-tree` &&
47 echo gnusto >bozbar &&
48 git update-index --add frotz bozbar --force-remove rezrov &&
49 git ls-files --stage >M.out &&
50 treeM=`git write-tree` &&
53 sum bozbar frotz nitfol >M.sum &&
54 git diff-tree $treeH $treeM'
57 '1, 2, 3 - no carry forward' \
58 'rm -f .git/index nitfol bozbar rezrov frotz &&
59 git read-tree --reset -u $treeH &&
60 git read-tree -m -u $treeH $treeM &&
61 git ls-files --stage >1-3.out &&
63 sum bozbar frotz nitfol >actual3.sum &&
64 cmp M.sum actual3.sum &&
65 check_cache_at bozbar clean &&
66 check_cache_at frotz clean &&
67 check_cache_at nitfol clean'
70 '4 - carry forward local addition.' \
71 'rm -f .git/index nitfol bozbar rezrov frotz &&
72 git read-tree --reset -u $treeH &&
73 echo "+100644 X 0 yomin" >expected &&
75 git update-index --add yomin &&
76 git read-tree -m -u $treeH $treeM &&
77 git ls-files --stage >4.out || return 1
78 diff M.out 4.out >4diff.out
79 check_cache_at yomin clean &&
80 sum bozbar frotz nitfol >actual4.sum &&
81 cmp M.sum actual4.sum &&
87 '5 - carry forward local addition.' \
88 'rm -f .git/index nitfol bozbar rezrov frotz &&
89 git read-tree --reset -u $treeH &&
90 git read-tree -m -u $treeH &&
92 git update-index --add yomin &&
93 echo yomin yomin >yomin &&
94 git read-tree -m -u $treeH $treeM &&
95 git ls-files --stage >5.out || return 1
96 diff M.out 5.out >5diff.out
97 check_cache_at yomin dirty &&
98 sum bozbar frotz nitfol >actual5.sum &&
99 cmp M.sum actual5.sum &&
100 : dirty index should have prevented -u from checking it out. &&
101 echo yomin yomin >yomin1 &&
105 test_expect_success \
106 '6 - local addition already has the same.' \
107 'rm -f .git/index nitfol bozbar rezrov frotz &&
108 git read-tree --reset -u $treeH &&
110 git update-index --add frotz &&
111 git read-tree -m -u $treeH $treeM &&
112 git ls-files --stage >6.out &&
114 check_cache_at frotz clean &&
115 sum bozbar frotz nitfol >actual3.sum &&
116 cmp M.sum actual3.sum &&
117 echo frotz >frotz1 &&
121 test_expect_success \
122 '7 - local addition already has the same.' \
123 'rm -f .git/index nitfol bozbar rezrov frotz &&
124 git read-tree --reset -u $treeH &&
126 git update-index --add frotz &&
127 echo frotz frotz >frotz &&
128 git read-tree -m -u $treeH $treeM &&
129 git ls-files --stage >7.out &&
131 check_cache_at frotz dirty &&
132 sum bozbar frotz nitfol >actual7.sum &&
133 if cmp M.sum actual7.sum; then false; else :; fi &&
134 : dirty index should have prevented -u from checking it out. &&
135 echo frotz frotz >frotz1 &&
139 test_expect_success \
140 '8 - conflicting addition.' \
141 'rm -f .git/index nitfol bozbar rezrov frotz &&
142 git read-tree --reset -u $treeH &&
143 echo frotz frotz >frotz &&
144 git update-index --add frotz &&
145 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
147 test_expect_success \
148 '9 - 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 &&
154 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
156 test_expect_success \
157 '10 - path removed.' \
158 'rm -f .git/index nitfol bozbar rezrov frotz &&
159 git read-tree --reset -u $treeH &&
160 echo rezrov >rezrov &&
161 git update-index --add rezrov &&
162 git read-tree -m -u $treeH $treeM &&
163 git ls-files --stage >10.out &&
165 sum bozbar frotz nitfol >actual10.sum &&
166 cmp M.sum actual10.sum'
168 test_expect_success \
169 '11 - dirty path removed.' \
170 'rm -f .git/index nitfol bozbar rezrov frotz &&
171 git read-tree --reset -u $treeH &&
172 echo rezrov >rezrov &&
173 git update-index --add rezrov &&
174 echo rezrov rezrov >rezrov &&
175 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
177 test_expect_success \
178 '12 - unmatching local changes being removed.' \
179 'rm -f .git/index nitfol bozbar rezrov frotz &&
180 git read-tree --reset -u $treeH &&
181 echo rezrov rezrov >rezrov &&
182 git update-index --add rezrov &&
183 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
185 test_expect_success \
186 '13 - 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 echo rezrov >rezrov &&
192 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
199 test_expect_success \
200 '14 - unchanged in two heads.' \
201 'rm -f .git/index nitfol bozbar rezrov frotz &&
202 git read-tree --reset -u $treeH &&
203 echo nitfol nitfol >nitfol &&
204 git update-index --add nitfol &&
205 git read-tree -m -u $treeH $treeM &&
206 git ls-files --stage >14.out || return 1
207 diff M.out 14.out >14diff.out
208 sum bozbar frotz >actual14.sum &&
209 grep -v nitfol M.sum > expected14.sum &&
210 cmp expected14.sum actual14.sum &&
211 sum bozbar frotz nitfol >actual14a.sum &&
212 if cmp M.sum actual14a.sum; then false; else :; fi &&
213 check_cache_at nitfol clean &&
214 echo nitfol nitfol >nitfol1 &&
215 diff nitfol nitfol1 &&
218 test_expect_success \
219 '15 - unchanged in two heads.' \
220 'rm -f .git/index nitfol bozbar rezrov frotz &&
221 git read-tree --reset -u $treeH &&
222 echo nitfol nitfol >nitfol &&
223 git update-index --add nitfol &&
224 echo nitfol nitfol nitfol >nitfol &&
225 git read-tree -m -u $treeH $treeM &&
226 git ls-files --stage >15.out || return 1
227 diff M.out 15.out >15diff.out
228 check_cache_at nitfol dirty &&
229 sum bozbar frotz >actual15.sum &&
230 grep -v nitfol M.sum > expected15.sum &&
231 cmp expected15.sum actual15.sum &&
232 sum bozbar frotz nitfol >actual15a.sum &&
233 if cmp M.sum actual15a.sum; then false; else :; fi &&
234 echo nitfol nitfol nitfol >nitfol1 &&
235 diff nitfol nitfol1 &&
238 test_expect_success \
239 '16 - conflicting local change.' \
240 'rm -f .git/index nitfol bozbar rezrov frotz &&
241 git read-tree --reset -u $treeH &&
242 echo bozbar bozbar >bozbar &&
243 git update-index --add bozbar &&
244 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
246 test_expect_success \
247 '17 - conflicting local change.' \
248 'rm -f .git/index nitfol bozbar rezrov frotz &&
249 git read-tree --reset -u $treeH &&
250 echo bozbar bozbar >bozbar &&
251 git update-index --add bozbar &&
252 echo bozbar bozbar bozbar >bozbar &&
253 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
255 test_expect_success \
256 '18 - local change already having a good result.' \
257 'rm -f .git/index nitfol bozbar rezrov frotz &&
258 git read-tree --reset -u $treeH &&
259 echo gnusto >bozbar &&
260 git update-index --add bozbar &&
261 git read-tree -m -u $treeH $treeM &&
262 git ls-files --stage >18.out &&
264 check_cache_at bozbar clean &&
265 sum bozbar frotz nitfol >actual18.sum &&
266 cmp M.sum actual18.sum'
268 test_expect_success \
269 '19 - local change already having a good result, further modified.' \
270 'rm -f .git/index nitfol bozbar rezrov frotz &&
271 git read-tree --reset -u $treeH &&
272 echo gnusto >bozbar &&
273 git update-index --add bozbar &&
274 echo gnusto gnusto >bozbar &&
275 git read-tree -m -u $treeH $treeM &&
276 git ls-files --stage >19.out &&
278 check_cache_at bozbar dirty &&
279 sum frotz nitfol >actual19.sum &&
280 grep -v bozbar M.sum > expected19.sum &&
281 cmp expected19.sum actual19.sum &&
282 sum bozbar frotz nitfol >actual19a.sum &&
283 if cmp M.sum actual19a.sum; then false; else :; fi &&
284 echo gnusto gnusto >bozbar1 &&
285 diff bozbar bozbar1 &&
288 test_expect_success \
289 '20 - no local change, use new tree.' \
290 'rm -f .git/index nitfol bozbar rezrov frotz &&
291 git read-tree --reset -u $treeH &&
292 echo bozbar >bozbar &&
293 git update-index --add bozbar &&
294 git read-tree -m -u $treeH $treeM &&
295 git ls-files --stage >20.out &&
297 check_cache_at bozbar clean &&
298 sum bozbar frotz nitfol >actual20.sum &&
299 cmp M.sum actual20.sum'
301 test_expect_success \
302 '21 - no local change, dirty cache.' \
303 'rm -f .git/index nitfol bozbar rezrov frotz &&
304 git read-tree --reset -u $treeH &&
305 echo bozbar >bozbar &&
306 git update-index --add bozbar &&
307 echo gnusto gnusto >bozbar &&
308 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
310 # Also make sure we did not break DF vs DF/DF case.
311 test_expect_success \
312 'DF vs DF/DF case setup.' \
315 git update-index --add DF &&
316 treeDF=`git write-tree` &&
317 echo treeDF $treeDF &&
318 git ls-tree $treeDF &&
323 git update-index --add --remove DF DF/DF &&
324 treeDFDF=`git write-tree` &&
325 echo treeDFDF $treeDFDF &&
326 git ls-tree $treeDFDF &&
327 git ls-files --stage >DFDF.out'
329 test_expect_success \
330 'DF vs DF/DF case test.' \
334 git update-index --add DF &&
335 git read-tree -m -u $treeDF $treeDFDF &&
336 git ls-files --stage >DFDFcheck.out &&
337 diff DFDF.out DFDFcheck.out &&
338 check_cache_at DF/DF clean'