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