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