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