]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1002-read-tree-m-u-2way.sh
Missing statics.
[thirdparty/git.git] / t / t1002-read-tree-m-u-2way.sh
CommitLineData
c8596009
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Two way merge with read-tree -m -u $H $M
7
8This is identical to t1001, but uses -u to update the work tree as well.
9
10'
11. ./test-lib.sh
12
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"
15compare_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"
5bd74506 19 git diff expected current
c8596009
JH
20}
21
22check_cache_at () {
6973dcae 23 clean_if_empty=`git-diff-files -- "$1"`
c8596009
JH
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
34}
35
36test_expect_success \
37 setup \
38 'echo frotz >frotz &&
39 echo nitfol >nitfol &&
40 echo bozbar >bozbar &&
41 echo rezrov >rezrov &&
215a7ad1 42 git-update-index --add nitfol bozbar rezrov &&
c8596009
JH
43 treeH=`git-write-tree` &&
44 echo treeH $treeH &&
45 git-ls-tree $treeH &&
46
47 echo gnusto >bozbar &&
215a7ad1 48 git-update-index --add frotz bozbar --force-remove rezrov &&
c8596009
JH
49 git-ls-files --stage >M.out &&
50 treeM=`git-write-tree` &&
51 echo treeM $treeM &&
52 git-ls-tree $treeM &&
cebe403b 53 sum bozbar frotz nitfol >M.sum &&
c8596009
JH
54 git-diff-tree $treeH $treeM'
55
56test_expect_success \
57 '1, 2, 3 - no carry forward' \
fcc387db
JH
58 'rm -f .git/index nitfol bozbar rezrov frotz &&
59 git-read-tree --reset -u $treeH &&
c8596009
JH
60 git-read-tree -m -u $treeH $treeM &&
61 git-ls-files --stage >1-3.out &&
62 cmp M.out 1-3.out &&
cebe403b
MA
63 sum bozbar frotz nitfol >actual3.sum &&
64 cmp M.sum actual3.sum &&
c8596009
JH
65 check_cache_at bozbar clean &&
66 check_cache_at frotz clean &&
67 check_cache_at nitfol clean'
68
c8596009
JH
69test_expect_success \
70 '4 - carry forward local addition.' \
fcc387db
JH
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 &&
215a7ad1 75 git-update-index --add yomin &&
c8596009 76 git-read-tree -m -u $treeH $treeM &&
4d9d62fa 77 git-ls-files --stage >4.out || return 1
c928c67d 78 diff -U0 M.out 4.out >4diff.out
c8596009
JH
79 compare_change 4diff.out expected &&
80 check_cache_at yomin clean &&
cebe403b
MA
81 sum bozbar frotz nitfol >actual4.sum &&
82 cmp M.sum actual4.sum &&
c8596009
JH
83 echo yomin >yomin1 &&
84 diff yomin yomin1 &&
85 rm -f yomin1'
86
87test_expect_success \
88 '5 - carry forward local addition.' \
fcc387db
JH
89 'rm -f .git/index nitfol bozbar rezrov frotz &&
90 git-read-tree --reset -u $treeH &&
91 git-read-tree -m -u $treeH &&
c8596009 92 echo yomin >yomin &&
215a7ad1 93 git-update-index --add yomin &&
c8596009
JH
94 echo yomin yomin >yomin &&
95 git-read-tree -m -u $treeH $treeM &&
4d9d62fa 96 git-ls-files --stage >5.out || return 1
c928c67d 97 diff -U0 M.out 5.out >5diff.out
c8596009
JH
98 compare_change 5diff.out expected &&
99 check_cache_at yomin dirty &&
cebe403b
MA
100 sum bozbar frotz nitfol >actual5.sum &&
101 cmp M.sum actual5.sum &&
7d95ee93 102 : dirty index should have prevented -u from checking it out. &&
c8596009
JH
103 echo yomin yomin >yomin1 &&
104 diff yomin yomin1 &&
105 rm -f yomin1'
106
107test_expect_success \
108 '6 - local addition already has the same.' \
fcc387db
JH
109 'rm -f .git/index nitfol bozbar rezrov frotz &&
110 git-read-tree --reset -u $treeH &&
111 echo frotz >frotz &&
215a7ad1 112 git-update-index --add frotz &&
c8596009
JH
113 git-read-tree -m -u $treeH $treeM &&
114 git-ls-files --stage >6.out &&
c928c67d 115 diff -U0 M.out 6.out &&
c8596009 116 check_cache_at frotz clean &&
cebe403b
MA
117 sum bozbar frotz nitfol >actual3.sum &&
118 cmp M.sum actual3.sum &&
c8596009
JH
119 echo frotz >frotz1 &&
120 diff frotz frotz1 &&
121 rm -f frotz1'
122
123test_expect_success \
124 '7 - local addition already has the same.' \
fcc387db
JH
125 'rm -f .git/index nitfol bozbar rezrov frotz &&
126 git-read-tree --reset -u $treeH &&
c8596009 127 echo frotz >frotz &&
215a7ad1 128 git-update-index --add frotz &&
c8596009
JH
129 echo frotz frotz >frotz &&
130 git-read-tree -m -u $treeH $treeM &&
131 git-ls-files --stage >7.out &&
c928c67d 132 diff -U0 M.out 7.out &&
c8596009 133 check_cache_at frotz dirty &&
cebe403b
MA
134 sum bozbar frotz nitfol >actual7.sum &&
135 if cmp M.sum actual7.sum; then false; else :; fi &&
7d95ee93 136 : dirty index should have prevented -u from checking it out. &&
c8596009
JH
137 echo frotz frotz >frotz1 &&
138 diff frotz frotz1 &&
139 rm -f frotz1'
140
141test_expect_success \
142 '8 - conflicting addition.' \
fcc387db
JH
143 'rm -f .git/index nitfol bozbar rezrov frotz &&
144 git-read-tree --reset -u $treeH &&
c8596009 145 echo frotz frotz >frotz &&
215a7ad1 146 git-update-index --add frotz &&
c8596009
JH
147 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
148
149test_expect_success \
150 '9 - conflicting addition.' \
fcc387db
JH
151 'rm -f .git/index nitfol bozbar rezrov frotz &&
152 git-read-tree --reset -u $treeH &&
c8596009 153 echo frotz frotz >frotz &&
215a7ad1 154 git-update-index --add frotz &&
c8596009
JH
155 echo frotz >frotz &&
156 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
157
158test_expect_success \
159 '10 - path removed.' \
fcc387db
JH
160 'rm -f .git/index nitfol bozbar rezrov frotz &&
161 git-read-tree --reset -u $treeH &&
c8596009 162 echo rezrov >rezrov &&
215a7ad1 163 git-update-index --add rezrov &&
c8596009
JH
164 git-read-tree -m -u $treeH $treeM &&
165 git-ls-files --stage >10.out &&
166 cmp M.out 10.out &&
cebe403b
MA
167 sum bozbar frotz nitfol >actual10.sum &&
168 cmp M.sum actual10.sum'
c8596009
JH
169
170test_expect_success \
171 '11 - dirty path removed.' \
fcc387db
JH
172 'rm -f .git/index nitfol bozbar rezrov frotz &&
173 git-read-tree --reset -u $treeH &&
c8596009 174 echo rezrov >rezrov &&
215a7ad1 175 git-update-index --add rezrov &&
c8596009
JH
176 echo rezrov rezrov >rezrov &&
177 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
178
179test_expect_success \
180 '12 - unmatching local changes being removed.' \
fcc387db
JH
181 'rm -f .git/index nitfol bozbar rezrov frotz &&
182 git-read-tree --reset -u $treeH &&
c8596009 183 echo rezrov rezrov >rezrov &&
215a7ad1 184 git-update-index --add rezrov &&
c8596009
JH
185 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
186
187test_expect_success \
188 '13 - unmatching local changes being removed.' \
fcc387db
JH
189 'rm -f .git/index nitfol bozbar rezrov frotz &&
190 git-read-tree --reset -u $treeH &&
c8596009 191 echo rezrov rezrov >rezrov &&
215a7ad1 192 git-update-index --add rezrov &&
c8596009
JH
193 echo rezrov >rezrov &&
194 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
195
196cat >expected <<EOF
197-100644 X 0 nitfol
198+100644 X 0 nitfol
199EOF
200
201test_expect_success \
202 '14 - unchanged in two heads.' \
fcc387db
JH
203 'rm -f .git/index nitfol bozbar rezrov frotz &&
204 git-read-tree --reset -u $treeH &&
c8596009 205 echo nitfol nitfol >nitfol &&
215a7ad1 206 git-update-index --add nitfol &&
c8596009 207 git-read-tree -m -u $treeH $treeM &&
4d9d62fa 208 git-ls-files --stage >14.out || return 1
c928c67d 209 diff -U0 M.out 14.out >14diff.out
c8596009 210 compare_change 14diff.out expected &&
cebe403b
MA
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 &&
c8596009 216 check_cache_at nitfol clean &&
c8596009
JH
217 echo nitfol nitfol >nitfol1 &&
218 diff nitfol nitfol1 &&
219 rm -f nitfol1'
220
221test_expect_success \
222 '15 - unchanged in two heads.' \
fcc387db
JH
223 'rm -f .git/index nitfol bozbar rezrov frotz &&
224 git-read-tree --reset -u $treeH &&
c8596009 225 echo nitfol nitfol >nitfol &&
215a7ad1 226 git-update-index --add nitfol &&
c8596009
JH
227 echo nitfol nitfol nitfol >nitfol &&
228 git-read-tree -m -u $treeH $treeM &&
4d9d62fa 229 git-ls-files --stage >15.out || return 1
c928c67d 230 diff -U0 M.out 15.out >15diff.out
c8596009
JH
231 compare_change 15diff.out expected &&
232 check_cache_at nitfol dirty &&
cebe403b
MA
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 &&
c8596009
JH
238 echo nitfol nitfol nitfol >nitfol1 &&
239 diff nitfol nitfol1 &&
240 rm -f nitfol1'
241
242test_expect_success \
243 '16 - conflicting local change.' \
fcc387db
JH
244 'rm -f .git/index nitfol bozbar rezrov frotz &&
245 git-read-tree --reset -u $treeH &&
c8596009 246 echo bozbar bozbar >bozbar &&
215a7ad1 247 git-update-index --add bozbar &&
c8596009
JH
248 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
249
250test_expect_success \
251 '17 - conflicting local change.' \
fcc387db
JH
252 'rm -f .git/index nitfol bozbar rezrov frotz &&
253 git-read-tree --reset -u $treeH &&
c8596009 254 echo bozbar bozbar >bozbar &&
215a7ad1 255 git-update-index --add bozbar &&
c8596009
JH
256 echo bozbar bozbar bozbar >bozbar &&
257 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
258
259test_expect_success \
260 '18 - local change already having a good result.' \
fcc387db
JH
261 'rm -f .git/index nitfol bozbar rezrov frotz &&
262 git-read-tree --reset -u $treeH &&
c8596009 263 echo gnusto >bozbar &&
215a7ad1 264 git-update-index --add bozbar &&
c8596009
JH
265 git-read-tree -m -u $treeH $treeM &&
266 git-ls-files --stage >18.out &&
c928c67d 267 diff -U0 M.out 18.out &&
c8596009 268 check_cache_at bozbar clean &&
cebe403b
MA
269 sum bozbar frotz nitfol >actual18.sum &&
270 cmp M.sum actual18.sum'
c8596009
JH
271
272test_expect_success \
273 '19 - local change already having a good result, further modified.' \
fcc387db
JH
274 'rm -f .git/index nitfol bozbar rezrov frotz &&
275 git-read-tree --reset -u $treeH &&
c8596009 276 echo gnusto >bozbar &&
215a7ad1 277 git-update-index --add bozbar &&
c8596009
JH
278 echo gnusto gnusto >bozbar &&
279 git-read-tree -m -u $treeH $treeM &&
280 git-ls-files --stage >19.out &&
c928c67d 281 diff -U0 M.out 19.out &&
c8596009 282 check_cache_at bozbar dirty &&
cebe403b
MA
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 &&
c8596009
JH
288 echo gnusto gnusto >bozbar1 &&
289 diff bozbar bozbar1 &&
290 rm -f bozbar1'
291
292test_expect_success \
293 '20 - no local change, use new tree.' \
fcc387db
JH
294 'rm -f .git/index nitfol bozbar rezrov frotz &&
295 git-read-tree --reset -u $treeH &&
c8596009 296 echo bozbar >bozbar &&
215a7ad1 297 git-update-index --add bozbar &&
c8596009
JH
298 git-read-tree -m -u $treeH $treeM &&
299 git-ls-files --stage >20.out &&
c928c67d 300 diff -U0 M.out 20.out &&
c8596009 301 check_cache_at bozbar clean &&
cebe403b
MA
302 sum bozbar frotz nitfol >actual20.sum &&
303 cmp M.sum actual20.sum'
c8596009
JH
304
305test_expect_success \
306 '21 - no local change, dirty cache.' \
fcc387db
JH
307 'rm -f .git/index nitfol bozbar rezrov frotz &&
308 git-read-tree --reset -u $treeH &&
c8596009 309 echo bozbar >bozbar &&
215a7ad1 310 git-update-index --add bozbar &&
c8596009
JH
311 echo gnusto gnusto >bozbar &&
312 if git-read-tree -m -u $treeH $treeM; then false; else :; fi'
313
314# Also make sure we did not break DF vs DF/DF case.
315test_expect_success \
316 'DF vs DF/DF case setup.' \
fcc387db 317 'rm -f .git/index
c8596009 318 echo DF >DF &&
215a7ad1 319 git-update-index --add DF &&
c8596009
JH
320 treeDF=`git-write-tree` &&
321 echo treeDF $treeDF &&
322 git-ls-tree $treeDF &&
323
324 rm -f DF &&
325 mkdir DF &&
326 echo DF/DF >DF/DF &&
215a7ad1 327 git-update-index --add --remove DF DF/DF &&
c8596009
JH
328 treeDFDF=`git-write-tree` &&
329 echo treeDFDF $treeDFDF &&
330 git-ls-tree $treeDFDF &&
331 git-ls-files --stage >DFDF.out'
332
333test_expect_success \
334 'DF vs DF/DF case test.' \
335 'rm -f .git/index &&
336 rm -fr DF &&
337 echo DF >DF &&
215a7ad1 338 git-update-index --add DF &&
c8596009
JH
339 git-read-tree -m -u $treeDF $treeDFDF &&
340 git-ls-files --stage >DFDFcheck.out &&
c928c67d 341 diff -U0 DFDF.out DFDFcheck.out &&
c8596009
JH
342 check_cache_at DF/DF clean'
343
344test_done