FYI: Reply from HP-UX
[git/dscho.git] / t / t1002-read-tree-m-u-2way.sh
blob531f07303f7904321893918947a92ddd73898d49
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 '/^--- /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
22 check_cache_at () {
23 clean_if_empty=`git diff-files -- "$1"`
24 case "$clean_if_empty" in
25 '') echo "$1: clean" ;;
26 ?*) echo "$1: dirty" ;;
27 esac
28 case "$2,$clean_if_empty" in
29 clean,) : ;;
30 clean,?*) false ;;
31 dirty,) false ;;
32 dirty,?*) : ;;
33 esac
36 test_expect_success \
37 setup \
38 'echo frotz >frotz &&
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` &&
44 echo treeH $treeH &&
45 git ls-tree $treeH &&
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` &&
51 echo treeM $treeM &&
52 git ls-tree $treeM &&
53 sum bozbar frotz nitfol >M.sum &&
54 git diff-tree $treeH $treeM'
56 test_expect_success \
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 &&
62 cmp M.out 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'
69 test_expect_success \
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 &&
74 echo yomin >yomin &&
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 &&
82 echo yomin >yomin1 &&
83 diff yomin yomin1 &&
84 rm -f yomin1'
86 test_expect_success \
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 &&
91 echo yomin >yomin &&
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 &&
102 diff yomin yomin1 &&
103 rm -f 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 &&
109 echo frotz >frotz &&
110 git update-index --add frotz &&
111 git read-tree -m -u $treeH $treeM &&
112 git ls-files --stage >6.out &&
113 diff M.out 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 &&
118 diff frotz frotz1 &&
119 rm -f 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 &&
125 echo frotz >frotz &&
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 &&
130 diff M.out 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 &&
136 diff frotz frotz1 &&
137 rm -f 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 &&
153 echo frotz >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 &&
164 cmp M.out 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'
194 cat >expected <<EOF
195 -100644 X 0 nitfol
196 +100644 X 0 nitfol
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 &&
216 rm -f 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 &&
236 rm -f 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 &&
263 diff M.out 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 &&
277 diff M.out 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 &&
286 rm -f 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 &&
296 diff M.out 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.' \
313 'rm -f .git/index
314 echo DF >DF &&
315 git update-index --add DF &&
316 treeDF=`git write-tree` &&
317 echo treeDF $treeDF &&
318 git ls-tree $treeDF &&
320 rm -f DF &&
321 mkdir DF &&
322 echo DF/DF >DF/DF &&
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.' \
331 'rm -f .git/index &&
332 rm -fr DF &&
333 echo DF >DF &&
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'
340 test_done