]>
Commit | Line | Data |
---|---|---|
c8596009 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Two way merge with read-tree -m -u $H $M | |
7 | ||
8 | This is identical to t1001, but uses -u to update the work tree as well. | |
9 | ||
10 | ' | |
11 | . ./test-lib.sh | |
12 | ||
c8596009 JH |
13 | compare_change () { |
14 | sed >current \ | |
26e08a01 BC |
15 | -e '1{/^diff --git /d;}' \ |
16 | -e '2{/^index /d;}' \ | |
c8596009 JH |
17 | -e '/^--- /d; /^+++ /d; /^@@ /d;' \ |
18 | -e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /' "$1" | |
3af82863 | 19 | test_cmp expected current |
c8596009 JH |
20 | } |
21 | ||
22 | check_cache_at () { | |
5be60078 | 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 | ||
36 | test_expect_success \ | |
37 | setup \ | |
38 | 'echo frotz >frotz && | |
39 | echo nitfol >nitfol && | |
40 | echo bozbar >bozbar && | |
41 | echo rezrov >rezrov && | |
5be60078 JH |
42 | git update-index --add nitfol bozbar rezrov && |
43 | treeH=`git write-tree` && | |
c8596009 | 44 | echo treeH $treeH && |
5be60078 | 45 | git ls-tree $treeH && |
c8596009 JH |
46 | |
47 | echo gnusto >bozbar && | |
5be60078 JH |
48 | git update-index --add frotz bozbar --force-remove rezrov && |
49 | git ls-files --stage >M.out && | |
50 | treeM=`git write-tree` && | |
c8596009 | 51 | echo treeM $treeM && |
5be60078 | 52 | git ls-tree $treeM && |
cebe403b | 53 | sum bozbar frotz nitfol >M.sum && |
5be60078 | 54 | git diff-tree $treeH $treeM' |
c8596009 JH |
55 | |
56 | test_expect_success \ | |
57 | '1, 2, 3 - no carry forward' \ | |
fcc387db | 58 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 JH |
59 | git read-tree --reset -u $treeH && |
60 | git read-tree -m -u $treeH $treeM && | |
61 | git ls-files --stage >1-3.out && | |
c8596009 | 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 |
69 | test_expect_success \ |
70 | '4 - carry forward local addition.' \ | |
fcc387db | 71 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 72 | git read-tree --reset -u $treeH && |
fcc387db JH |
73 | echo "+100644 X 0 yomin" >expected && |
74 | echo yomin >yomin && | |
5be60078 JH |
75 | git update-index --add yomin && |
76 | git read-tree -m -u $treeH $treeM && | |
77 | git ls-files --stage >4.out || return 1 | |
26e08a01 | 78 | git diff -U0 --no-index 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 | ||
87 | test_expect_success \ | |
88 | '5 - carry forward local addition.' \ | |
fcc387db | 89 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 JH |
90 | git read-tree --reset -u $treeH && |
91 | git read-tree -m -u $treeH && | |
c8596009 | 92 | echo yomin >yomin && |
5be60078 | 93 | git update-index --add yomin && |
c8596009 | 94 | echo yomin yomin >yomin && |
5be60078 JH |
95 | git read-tree -m -u $treeH $treeM && |
96 | git ls-files --stage >5.out || return 1 | |
26e08a01 | 97 | git diff -U0 --no-index 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 | ||
107 | test_expect_success \ | |
108 | '6 - local addition already has the same.' \ | |
fcc387db | 109 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 110 | git read-tree --reset -u $treeH && |
fcc387db | 111 | echo frotz >frotz && |
5be60078 JH |
112 | git update-index --add frotz && |
113 | git read-tree -m -u $treeH $treeM && | |
114 | git ls-files --stage >6.out && | |
2b14d072 | 115 | test_cmp 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 | ||
123 | test_expect_success \ | |
124 | '7 - local addition already has the same.' \ | |
fcc387db | 125 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 126 | git read-tree --reset -u $treeH && |
c8596009 | 127 | echo frotz >frotz && |
5be60078 | 128 | git update-index --add frotz && |
c8596009 | 129 | echo frotz frotz >frotz && |
5be60078 JH |
130 | git read-tree -m -u $treeH $treeM && |
131 | git ls-files --stage >7.out && | |
2b14d072 | 132 | test_cmp 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 | ||
141 | test_expect_success \ | |
142 | '8 - conflicting addition.' \ | |
fcc387db | 143 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 144 | git read-tree --reset -u $treeH && |
c8596009 | 145 | echo frotz frotz >frotz && |
5be60078 JH |
146 | git update-index --add frotz && |
147 | if git read-tree -m -u $treeH $treeM; then false; else :; fi' | |
c8596009 JH |
148 | |
149 | test_expect_success \ | |
150 | '9 - conflicting addition.' \ | |
fcc387db | 151 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 152 | git read-tree --reset -u $treeH && |
c8596009 | 153 | echo frotz frotz >frotz && |
5be60078 | 154 | git update-index --add frotz && |
c8596009 | 155 | echo frotz >frotz && |
5be60078 | 156 | if git read-tree -m -u $treeH $treeM; then false; else :; fi' |
c8596009 JH |
157 | |
158 | test_expect_success \ | |
159 | '10 - path removed.' \ | |
fcc387db | 160 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 161 | git read-tree --reset -u $treeH && |
c8596009 | 162 | echo rezrov >rezrov && |
5be60078 JH |
163 | git update-index --add rezrov && |
164 | git read-tree -m -u $treeH $treeM && | |
165 | git ls-files --stage >10.out && | |
c8596009 | 166 | cmp M.out 10.out && |
cebe403b MA |
167 | sum bozbar frotz nitfol >actual10.sum && |
168 | cmp M.sum actual10.sum' | |
c8596009 JH |
169 | |
170 | test_expect_success \ | |
171 | '11 - dirty path removed.' \ | |
fcc387db | 172 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 173 | git read-tree --reset -u $treeH && |
c8596009 | 174 | echo rezrov >rezrov && |
5be60078 | 175 | git update-index --add rezrov && |
c8596009 | 176 | echo rezrov rezrov >rezrov && |
5be60078 | 177 | if git read-tree -m -u $treeH $treeM; then false; else :; fi' |
c8596009 JH |
178 | |
179 | test_expect_success \ | |
180 | '12 - unmatching local changes being removed.' \ | |
fcc387db | 181 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 182 | git read-tree --reset -u $treeH && |
c8596009 | 183 | echo rezrov rezrov >rezrov && |
5be60078 JH |
184 | git update-index --add rezrov && |
185 | if git read-tree -m -u $treeH $treeM; then false; else :; fi' | |
c8596009 JH |
186 | |
187 | test_expect_success \ | |
188 | '13 - unmatching local changes being removed.' \ | |
fcc387db | 189 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 190 | git read-tree --reset -u $treeH && |
c8596009 | 191 | echo rezrov rezrov >rezrov && |
5be60078 | 192 | git update-index --add rezrov && |
c8596009 | 193 | echo rezrov >rezrov && |
5be60078 | 194 | if git read-tree -m -u $treeH $treeM; then false; else :; fi' |
c8596009 JH |
195 | |
196 | cat >expected <<EOF | |
197 | -100644 X 0 nitfol | |
198 | +100644 X 0 nitfol | |
199 | EOF | |
200 | ||
201 | test_expect_success \ | |
202 | '14 - unchanged in two heads.' \ | |
fcc387db | 203 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 204 | git read-tree --reset -u $treeH && |
c8596009 | 205 | echo nitfol nitfol >nitfol && |
5be60078 JH |
206 | git update-index --add nitfol && |
207 | git read-tree -m -u $treeH $treeM && | |
315e7654 EN |
208 | git ls-files --stage >14.out && |
209 | test_must_fail git diff -U0 --no-index 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 | ||
221 | test_expect_success \ | |
222 | '15 - unchanged in two heads.' \ | |
fcc387db | 223 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 224 | git read-tree --reset -u $treeH && |
c8596009 | 225 | echo nitfol nitfol >nitfol && |
5be60078 | 226 | git update-index --add nitfol && |
c8596009 | 227 | echo nitfol nitfol nitfol >nitfol && |
5be60078 | 228 | git read-tree -m -u $treeH $treeM && |
315e7654 EN |
229 | git ls-files --stage >15.out && |
230 | test_must_fail git diff -U0 --no-index 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 | ||
242 | test_expect_success \ | |
243 | '16 - conflicting local change.' \ | |
fcc387db | 244 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 245 | git read-tree --reset -u $treeH && |
c8596009 | 246 | echo bozbar bozbar >bozbar && |
5be60078 JH |
247 | git update-index --add bozbar && |
248 | if git read-tree -m -u $treeH $treeM; then false; else :; fi' | |
c8596009 JH |
249 | |
250 | test_expect_success \ | |
251 | '17 - conflicting local change.' \ | |
fcc387db | 252 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 253 | git read-tree --reset -u $treeH && |
c8596009 | 254 | echo bozbar bozbar >bozbar && |
5be60078 | 255 | git update-index --add bozbar && |
c8596009 | 256 | echo bozbar bozbar bozbar >bozbar && |
5be60078 | 257 | if git read-tree -m -u $treeH $treeM; then false; else :; fi' |
c8596009 JH |
258 | |
259 | test_expect_success \ | |
260 | '18 - local change already having a good result.' \ | |
fcc387db | 261 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 262 | git read-tree --reset -u $treeH && |
c8596009 | 263 | echo gnusto >bozbar && |
5be60078 JH |
264 | git update-index --add bozbar && |
265 | git read-tree -m -u $treeH $treeM && | |
266 | git ls-files --stage >18.out && | |
2b14d072 | 267 | test_cmp 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 | |
272 | test_expect_success \ | |
273 | '19 - local change already having a good result, further modified.' \ | |
fcc387db | 274 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 275 | git read-tree --reset -u $treeH && |
c8596009 | 276 | echo gnusto >bozbar && |
5be60078 | 277 | git update-index --add bozbar && |
c8596009 | 278 | echo gnusto gnusto >bozbar && |
5be60078 JH |
279 | git read-tree -m -u $treeH $treeM && |
280 | git ls-files --stage >19.out && | |
2b14d072 | 281 | test_cmp 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 | ||
292 | test_expect_success \ | |
293 | '20 - no local change, use new tree.' \ | |
fcc387db | 294 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 295 | git read-tree --reset -u $treeH && |
c8596009 | 296 | echo bozbar >bozbar && |
5be60078 JH |
297 | git update-index --add bozbar && |
298 | git read-tree -m -u $treeH $treeM && | |
299 | git ls-files --stage >20.out && | |
2b14d072 | 300 | test_cmp 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 | |
305 | test_expect_success \ | |
306 | '21 - no local change, dirty cache.' \ | |
fcc387db | 307 | 'rm -f .git/index nitfol bozbar rezrov frotz && |
5be60078 | 308 | git read-tree --reset -u $treeH && |
c8596009 | 309 | echo bozbar >bozbar && |
5be60078 | 310 | git update-index --add bozbar && |
c8596009 | 311 | echo gnusto gnusto >bozbar && |
5be60078 | 312 | if git read-tree -m -u $treeH $treeM; then false; else :; fi' |
c8596009 JH |
313 | |
314 | # Also make sure we did not break DF vs DF/DF case. | |
315 | test_expect_success \ | |
316 | 'DF vs DF/DF case setup.' \ | |
315e7654 | 317 | 'rm -f .git/index && |
c8596009 | 318 | echo DF >DF && |
5be60078 JH |
319 | git update-index --add DF && |
320 | treeDF=`git write-tree` && | |
c8596009 | 321 | echo treeDF $treeDF && |
5be60078 | 322 | git ls-tree $treeDF && |
c8596009 JH |
323 | |
324 | rm -f DF && | |
325 | mkdir DF && | |
326 | echo DF/DF >DF/DF && | |
5be60078 JH |
327 | git update-index --add --remove DF DF/DF && |
328 | treeDFDF=`git write-tree` && | |
c8596009 | 329 | echo treeDFDF $treeDFDF && |
5be60078 JH |
330 | git ls-tree $treeDFDF && |
331 | git ls-files --stage >DFDF.out' | |
c8596009 JH |
332 | |
333 | test_expect_success \ | |
334 | 'DF vs DF/DF case test.' \ | |
335 | 'rm -f .git/index && | |
336 | rm -fr DF && | |
337 | echo DF >DF && | |
5be60078 JH |
338 | git update-index --add DF && |
339 | git read-tree -m -u $treeDF $treeDFDF && | |
340 | git ls-files --stage >DFDFcheck.out && | |
2b14d072 | 341 | test_cmp DFDF.out DFDFcheck.out && |
c8596009 JH |
342 | check_cache_at DF/DF clean' |
343 | ||
344 | test_done |