Merge branch 'ss/cherry-pick-x-doc' into maint
[git/mjg.git] / t / t1002-read-tree-m-u-2way.sh
bloba4a17e001739a45fc7d53e76bd8bbb14426492f9
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 compare_change () {
14 sed >current \
15 -e '1{/^diff --git /d;}' \
16 -e '2{/^index /d;}' \
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 test_cmp 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 git diff -U0 --no-index M.out 4.out >4diff.out
79 compare_change 4diff.out expected &&
80 check_cache_at yomin clean &&
81 sum bozbar frotz nitfol >actual4.sum &&
82 cmp M.sum actual4.sum &&
83 echo yomin >yomin1 &&
84 diff yomin yomin1 &&
85 rm -f yomin1'
87 test_expect_success \
88 '5 - carry forward local addition.' \
89 'rm -f .git/index nitfol bozbar rezrov frotz &&
90 git read-tree --reset -u $treeH &&
91 git read-tree -m -u $treeH &&
92 echo yomin >yomin &&
93 git update-index --add yomin &&
94 echo yomin yomin >yomin &&
95 git read-tree -m -u $treeH $treeM &&
96 git ls-files --stage >5.out || return 1
97 git diff -U0 --no-index M.out 5.out >5diff.out
98 compare_change 5diff.out expected &&
99 check_cache_at yomin dirty &&
100 sum bozbar frotz nitfol >actual5.sum &&
101 cmp M.sum actual5.sum &&
102 : dirty index should have prevented -u from checking it out. &&
103 echo yomin yomin >yomin1 &&
104 diff yomin yomin1 &&
105 rm -f yomin1'
107 test_expect_success \
108 '6 - local addition already has the same.' \
109 'rm -f .git/index nitfol bozbar rezrov frotz &&
110 git read-tree --reset -u $treeH &&
111 echo frotz >frotz &&
112 git update-index --add frotz &&
113 git read-tree -m -u $treeH $treeM &&
114 git ls-files --stage >6.out &&
115 test_cmp M.out 6.out &&
116 check_cache_at frotz clean &&
117 sum bozbar frotz nitfol >actual3.sum &&
118 cmp M.sum actual3.sum &&
119 echo frotz >frotz1 &&
120 diff frotz frotz1 &&
121 rm -f frotz1'
123 test_expect_success \
124 '7 - local addition already has the same.' \
125 'rm -f .git/index nitfol bozbar rezrov frotz &&
126 git read-tree --reset -u $treeH &&
127 echo frotz >frotz &&
128 git update-index --add frotz &&
129 echo frotz frotz >frotz &&
130 git read-tree -m -u $treeH $treeM &&
131 git ls-files --stage >7.out &&
132 test_cmp M.out 7.out &&
133 check_cache_at frotz dirty &&
134 sum bozbar frotz nitfol >actual7.sum &&
135 if cmp M.sum actual7.sum; then false; else :; fi &&
136 : dirty index should have prevented -u from checking it out. &&
137 echo frotz frotz >frotz1 &&
138 diff frotz frotz1 &&
139 rm -f frotz1'
141 test_expect_success \
142 '8 - conflicting addition.' \
143 'rm -f .git/index nitfol bozbar rezrov frotz &&
144 git read-tree --reset -u $treeH &&
145 echo frotz frotz >frotz &&
146 git update-index --add frotz &&
147 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
149 test_expect_success \
150 '9 - conflicting addition.' \
151 'rm -f .git/index nitfol bozbar rezrov frotz &&
152 git read-tree --reset -u $treeH &&
153 echo frotz frotz >frotz &&
154 git update-index --add frotz &&
155 echo frotz >frotz &&
156 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
158 test_expect_success \
159 '10 - path removed.' \
160 'rm -f .git/index nitfol bozbar rezrov frotz &&
161 git read-tree --reset -u $treeH &&
162 echo rezrov >rezrov &&
163 git update-index --add rezrov &&
164 git read-tree -m -u $treeH $treeM &&
165 git ls-files --stage >10.out &&
166 cmp M.out 10.out &&
167 sum bozbar frotz nitfol >actual10.sum &&
168 cmp M.sum actual10.sum'
170 test_expect_success \
171 '11 - dirty path removed.' \
172 'rm -f .git/index nitfol bozbar rezrov frotz &&
173 git read-tree --reset -u $treeH &&
174 echo rezrov >rezrov &&
175 git update-index --add rezrov &&
176 echo rezrov rezrov >rezrov &&
177 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
179 test_expect_success \
180 '12 - unmatching local changes being removed.' \
181 'rm -f .git/index nitfol bozbar rezrov frotz &&
182 git read-tree --reset -u $treeH &&
183 echo rezrov rezrov >rezrov &&
184 git update-index --add rezrov &&
185 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
187 test_expect_success \
188 '13 - unmatching local changes being removed.' \
189 'rm -f .git/index nitfol bozbar rezrov frotz &&
190 git read-tree --reset -u $treeH &&
191 echo rezrov rezrov >rezrov &&
192 git update-index --add rezrov &&
193 echo rezrov >rezrov &&
194 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
196 cat >expected <<EOF
197 -100644 X 0 nitfol
198 +100644 X 0 nitfol
201 test_expect_success \
202 '14 - unchanged in two heads.' \
203 'rm -f .git/index nitfol bozbar rezrov frotz &&
204 git read-tree --reset -u $treeH &&
205 echo nitfol nitfol >nitfol &&
206 git update-index --add nitfol &&
207 git read-tree -m -u $treeH $treeM &&
208 git ls-files --stage >14.out &&
209 test_must_fail git diff -U0 --no-index M.out 14.out >14diff.out &&
210 compare_change 14diff.out expected &&
211 sum bozbar frotz >actual14.sum &&
212 grep -v nitfol M.sum > expected14.sum &&
213 cmp expected14.sum actual14.sum &&
214 sum bozbar frotz nitfol >actual14a.sum &&
215 if cmp M.sum actual14a.sum; then false; else :; fi &&
216 check_cache_at nitfol clean &&
217 echo nitfol nitfol >nitfol1 &&
218 diff nitfol nitfol1 &&
219 rm -f nitfol1'
221 test_expect_success \
222 '15 - unchanged in two heads.' \
223 'rm -f .git/index nitfol bozbar rezrov frotz &&
224 git read-tree --reset -u $treeH &&
225 echo nitfol nitfol >nitfol &&
226 git update-index --add nitfol &&
227 echo nitfol nitfol nitfol >nitfol &&
228 git read-tree -m -u $treeH $treeM &&
229 git ls-files --stage >15.out &&
230 test_must_fail git diff -U0 --no-index M.out 15.out >15diff.out &&
231 compare_change 15diff.out expected &&
232 check_cache_at nitfol dirty &&
233 sum bozbar frotz >actual15.sum &&
234 grep -v nitfol M.sum > expected15.sum &&
235 cmp expected15.sum actual15.sum &&
236 sum bozbar frotz nitfol >actual15a.sum &&
237 if cmp M.sum actual15a.sum; then false; else :; fi &&
238 echo nitfol nitfol nitfol >nitfol1 &&
239 diff nitfol nitfol1 &&
240 rm -f nitfol1'
242 test_expect_success \
243 '16 - conflicting local change.' \
244 'rm -f .git/index nitfol bozbar rezrov frotz &&
245 git read-tree --reset -u $treeH &&
246 echo bozbar bozbar >bozbar &&
247 git update-index --add bozbar &&
248 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
250 test_expect_success \
251 '17 - conflicting local change.' \
252 'rm -f .git/index nitfol bozbar rezrov frotz &&
253 git read-tree --reset -u $treeH &&
254 echo bozbar bozbar >bozbar &&
255 git update-index --add bozbar &&
256 echo bozbar bozbar bozbar >bozbar &&
257 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
259 test_expect_success \
260 '18 - local change already having a good result.' \
261 'rm -f .git/index nitfol bozbar rezrov frotz &&
262 git read-tree --reset -u $treeH &&
263 echo gnusto >bozbar &&
264 git update-index --add bozbar &&
265 git read-tree -m -u $treeH $treeM &&
266 git ls-files --stage >18.out &&
267 test_cmp M.out 18.out &&
268 check_cache_at bozbar clean &&
269 sum bozbar frotz nitfol >actual18.sum &&
270 cmp M.sum actual18.sum'
272 test_expect_success \
273 '19 - local change already having a good result, further modified.' \
274 'rm -f .git/index nitfol bozbar rezrov frotz &&
275 git read-tree --reset -u $treeH &&
276 echo gnusto >bozbar &&
277 git update-index --add bozbar &&
278 echo gnusto gnusto >bozbar &&
279 git read-tree -m -u $treeH $treeM &&
280 git ls-files --stage >19.out &&
281 test_cmp M.out 19.out &&
282 check_cache_at bozbar dirty &&
283 sum frotz nitfol >actual19.sum &&
284 grep -v bozbar M.sum > expected19.sum &&
285 cmp expected19.sum actual19.sum &&
286 sum bozbar frotz nitfol >actual19a.sum &&
287 if cmp M.sum actual19a.sum; then false; else :; fi &&
288 echo gnusto gnusto >bozbar1 &&
289 diff bozbar bozbar1 &&
290 rm -f bozbar1'
292 test_expect_success \
293 '20 - no local change, use new tree.' \
294 'rm -f .git/index nitfol bozbar rezrov frotz &&
295 git read-tree --reset -u $treeH &&
296 echo bozbar >bozbar &&
297 git update-index --add bozbar &&
298 git read-tree -m -u $treeH $treeM &&
299 git ls-files --stage >20.out &&
300 test_cmp M.out 20.out &&
301 check_cache_at bozbar clean &&
302 sum bozbar frotz nitfol >actual20.sum &&
303 cmp M.sum actual20.sum'
305 test_expect_success \
306 '21 - no local change, dirty cache.' \
307 'rm -f .git/index nitfol bozbar rezrov frotz &&
308 git read-tree --reset -u $treeH &&
309 echo bozbar >bozbar &&
310 git update-index --add bozbar &&
311 echo gnusto gnusto >bozbar &&
312 if git read-tree -m -u $treeH $treeM; then false; else :; fi'
314 # Also make sure we did not break DF vs DF/DF case.
315 test_expect_success \
316 'DF vs DF/DF case setup.' \
317 'rm -f .git/index &&
318 echo DF >DF &&
319 git update-index --add DF &&
320 treeDF=`git write-tree` &&
321 echo treeDF $treeDF &&
322 git ls-tree $treeDF &&
324 rm -f DF &&
325 mkdir DF &&
326 echo DF/DF >DF/DF &&
327 git update-index --add --remove DF DF/DF &&
328 treeDFDF=`git write-tree` &&
329 echo treeDFDF $treeDFDF &&
330 git ls-tree $treeDFDF &&
331 git ls-files --stage >DFDF.out'
333 test_expect_success \
334 'DF vs DF/DF case test.' \
335 'rm -f .git/index &&
336 rm -fr DF &&
337 echo DF >DF &&
338 git update-index --add DF &&
339 git read-tree -m -u $treeDF $treeDFDF &&
340 git ls-files --stage >DFDFcheck.out &&
341 test_cmp DFDF.out DFDFcheck.out &&
342 check_cache_at DF/DF clean'
344 test_done