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