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