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