]>
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 $H $M | |
7 | ||
a75d7b54 | 8 | This test tries two-way merge (aka fast-forward with carry forward). |
c8596009 JH |
9 | |
10 | There is the head (called H) and another commit (called M), which is | |
11 | simply ahead of H. The index and the work tree contains a state that | |
12 | is derived from H, but may also have local changes. This test checks | |
13 | all the combinations described in the two-tree merge "carry forward" | |
5be60078 | 14 | rules, found in <Documentation/git read-tree.txt>. |
c8596009 JH |
15 | |
16 | In the test, these paths are used: | |
17 | bozbar - in H, stays in M, modified from bozbar to gnusto | |
18 | frotz - not in H added in M | |
19 | nitfol - in H, stays in M unmodified | |
20 | rezrov - in H, deleted in M | |
235e8d59 | 21 | yomin - not in H or M |
c8596009 JH |
22 | ' |
23 | . ./test-lib.sh | |
ea5070c9 | 24 | . "$TEST_DIRECTORY"/lib-read-tree.sh |
c8596009 | 25 | |
76bc82ca | 26 | read_tree_twoway () { |
5be60078 | 27 | git read-tree -m "$1" "$2" && git ls-files --stage |
76bc82ca JH |
28 | } |
29 | ||
c8596009 | 30 | compare_change () { |
76bc82ca | 31 | sed -n >current \ |
c8596009 | 32 | -e '/^--- /d; /^+++ /d; /^@@ /d;' \ |
76bc82ca JH |
33 | -e 's/^\([-+][0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /p' \ |
34 | "$1" | |
3af82863 | 35 | test_cmp expected current |
c8596009 JH |
36 | } |
37 | ||
38 | check_cache_at () { | |
5be60078 | 39 | clean_if_empty=`git diff-files -- "$1"` |
c8596009 JH |
40 | case "$clean_if_empty" in |
41 | '') echo "$1: clean" ;; | |
42 | ?*) echo "$1: dirty" ;; | |
43 | esac | |
44 | case "$2,$clean_if_empty" in | |
45 | clean,) : ;; | |
46 | clean,?*) false ;; | |
47 | dirty,) false ;; | |
48 | dirty,?*) : ;; | |
49 | esac | |
50 | } | |
51 | ||
1abb3f14 | 52 | cat >bozbar-old <<\EOF |
a75d7b54 | 53 | This is a sample file used in two-way fast-forward merge |
1abb3f14 JH |
54 | tests. Its second line ends with a magic word bozbar |
55 | which will be modified by the merged head to gnusto. | |
56 | It has some extra lines so that external tools can | |
57 | successfully merge independent changes made to later | |
58 | lines (such as this one), avoiding line conflicts. | |
59 | EOF | |
60 | ||
61 | sed -e 's/bozbar/gnusto (earlier bozbar)/' bozbar-old >bozbar-new | |
62 | ||
c8596009 JH |
63 | test_expect_success \ |
64 | setup \ | |
65 | 'echo frotz >frotz && | |
66 | echo nitfol >nitfol && | |
1abb3f14 | 67 | cat bozbar-old >bozbar && |
c8596009 JH |
68 | echo rezrov >rezrov && |
69 | echo yomin >yomin && | |
5be60078 JH |
70 | git update-index --add nitfol bozbar rezrov && |
71 | treeH=`git write-tree` && | |
c8596009 | 72 | echo treeH $treeH && |
5be60078 | 73 | git ls-tree $treeH && |
c8596009 | 74 | |
1abb3f14 | 75 | cat bozbar-new >bozbar && |
5be60078 JH |
76 | git update-index --add frotz bozbar --force-remove rezrov && |
77 | git ls-files --stage >M.out && | |
78 | treeM=`git write-tree` && | |
c8596009 | 79 | echo treeM $treeM && |
5be60078 JH |
80 | git ls-tree $treeM && |
81 | git diff-tree $treeH $treeM' | |
c8596009 JH |
82 | |
83 | test_expect_success \ | |
84 | '1, 2, 3 - no carry forward' \ | |
85 | 'rm -f .git/index && | |
76bc82ca | 86 | read_tree_twoway $treeH $treeM && |
5be60078 | 87 | git ls-files --stage >1-3.out && |
3af82863 | 88 | test_cmp M.out 1-3.out && |
c8596009 JH |
89 | check_cache_at bozbar dirty && |
90 | check_cache_at frotz dirty && | |
91 | check_cache_at nitfol dirty' | |
92 | ||
93 | echo '+100644 X 0 yomin' >expected | |
94 | ||
95 | test_expect_success \ | |
96 | '4 - carry forward local addition.' \ | |
97 | 'rm -f .git/index && | |
ea5070c9 | 98 | read_tree_must_succeed $treeH && |
5be60078 JH |
99 | git checkout-index -u -f -q -a && |
100 | git update-index --add yomin && | |
76bc82ca | 101 | read_tree_twoway $treeH $treeM && |
315e7654 EN |
102 | git ls-files --stage >4.out && |
103 | test_must_fail git diff --no-index M.out 4.out >4diff.out && | |
c8596009 JH |
104 | compare_change 4diff.out expected && |
105 | check_cache_at yomin clean' | |
106 | ||
107 | test_expect_success \ | |
108 | '5 - carry forward local addition.' \ | |
109 | 'rm -f .git/index && | |
ea5070c9 | 110 | read_tree_must_succeed $treeH && |
5be60078 | 111 | git checkout-index -u -f -q -a && |
c8596009 | 112 | echo yomin >yomin && |
5be60078 | 113 | git update-index --add yomin && |
c8596009 | 114 | echo yomin yomin >yomin && |
76bc82ca | 115 | read_tree_twoway $treeH $treeM && |
315e7654 EN |
116 | git ls-files --stage >5.out && |
117 | test_must_fail git diff --no-index M.out 5.out >5diff.out && | |
c8596009 JH |
118 | compare_change 5diff.out expected && |
119 | check_cache_at yomin dirty' | |
120 | ||
121 | test_expect_success \ | |
122 | '6 - local addition already has the same.' \ | |
123 | 'rm -f .git/index && | |
ea5070c9 | 124 | read_tree_must_succeed $treeH && |
5be60078 JH |
125 | git checkout-index -u -f -q -a && |
126 | git update-index --add frotz && | |
76bc82ca | 127 | read_tree_twoway $treeH $treeM && |
5be60078 | 128 | git ls-files --stage >6.out && |
3af82863 | 129 | test_cmp M.out 6.out && |
c8596009 JH |
130 | check_cache_at frotz clean' |
131 | ||
132 | test_expect_success \ | |
133 | '7 - local addition already has the same.' \ | |
134 | 'rm -f .git/index && | |
ea5070c9 | 135 | read_tree_must_succeed $treeH && |
5be60078 | 136 | git checkout-index -u -f -q -a && |
c8596009 | 137 | echo frotz >frotz && |
5be60078 | 138 | git update-index --add frotz && |
c8596009 | 139 | echo frotz frotz >frotz && |
76bc82ca | 140 | read_tree_twoway $treeH $treeM && |
5be60078 | 141 | git ls-files --stage >7.out && |
3af82863 | 142 | test_cmp M.out 7.out && |
c8596009 JH |
143 | check_cache_at frotz dirty' |
144 | ||
145 | test_expect_success \ | |
146 | '8 - conflicting addition.' \ | |
147 | 'rm -f .git/index && | |
ea5070c9 | 148 | read_tree_must_succeed $treeH && |
5be60078 | 149 | git checkout-index -u -f -q -a && |
c8596009 | 150 | echo frotz frotz >frotz && |
5be60078 | 151 | git update-index --add frotz && |
76bc82ca | 152 | if read_tree_twoway $treeH $treeM; then false; else :; fi' |
c8596009 JH |
153 | |
154 | test_expect_success \ | |
155 | '9 - conflicting addition.' \ | |
156 | 'rm -f .git/index && | |
ea5070c9 | 157 | read_tree_must_succeed $treeH && |
5be60078 | 158 | git checkout-index -u -f -q -a && |
c8596009 | 159 | echo frotz frotz >frotz && |
5be60078 | 160 | git update-index --add frotz && |
c8596009 | 161 | echo frotz >frotz && |
76bc82ca | 162 | if read_tree_twoway $treeH $treeM; then false; else :; fi' |
c8596009 JH |
163 | |
164 | test_expect_success \ | |
165 | '10 - path removed.' \ | |
166 | 'rm -f .git/index && | |
ea5070c9 | 167 | read_tree_must_succeed $treeH && |
5be60078 | 168 | git checkout-index -u -f -q -a && |
c8596009 | 169 | echo rezrov >rezrov && |
5be60078 | 170 | git update-index --add rezrov && |
76bc82ca | 171 | read_tree_twoway $treeH $treeM && |
5be60078 | 172 | git ls-files --stage >10.out && |
3af82863 | 173 | test_cmp M.out 10.out' |
c8596009 JH |
174 | |
175 | test_expect_success \ | |
176 | '11 - dirty path removed.' \ | |
177 | 'rm -f .git/index && | |
ea5070c9 | 178 | read_tree_must_succeed $treeH && |
5be60078 | 179 | git checkout-index -u -f -q -a && |
c8596009 | 180 | echo rezrov >rezrov && |
5be60078 | 181 | git update-index --add rezrov && |
c8596009 | 182 | echo rezrov rezrov >rezrov && |
76bc82ca | 183 | if read_tree_twoway $treeH $treeM; then false; else :; fi' |
c8596009 JH |
184 | |
185 | test_expect_success \ | |
186 | '12 - unmatching local changes being removed.' \ | |
187 | 'rm -f .git/index && | |
ea5070c9 | 188 | read_tree_must_succeed $treeH && |
5be60078 | 189 | git checkout-index -u -f -q -a && |
c8596009 | 190 | echo rezrov rezrov >rezrov && |
5be60078 | 191 | git update-index --add rezrov && |
76bc82ca | 192 | if read_tree_twoway $treeH $treeM; then false; else :; fi' |
c8596009 JH |
193 | |
194 | test_expect_success \ | |
195 | '13 - unmatching local changes being removed.' \ | |
196 | 'rm -f .git/index && | |
ea5070c9 | 197 | read_tree_must_succeed $treeH && |
5be60078 | 198 | git checkout-index -u -f -q -a && |
c8596009 | 199 | echo rezrov rezrov >rezrov && |
5be60078 | 200 | git update-index --add rezrov && |
c8596009 | 201 | echo rezrov >rezrov && |
76bc82ca | 202 | if read_tree_twoway $treeH $treeM; then false; else :; fi' |
c8596009 JH |
203 | |
204 | cat >expected <<EOF | |
205 | -100644 X 0 nitfol | |
206 | +100644 X 0 nitfol | |
207 | EOF | |
208 | ||
209 | test_expect_success \ | |
210 | '14 - unchanged in two heads.' \ | |
211 | 'rm -f .git/index && | |
ea5070c9 | 212 | read_tree_must_succeed $treeH && |
5be60078 | 213 | git checkout-index -u -f -q -a && |
c8596009 | 214 | echo nitfol nitfol >nitfol && |
5be60078 | 215 | git update-index --add nitfol && |
76bc82ca | 216 | read_tree_twoway $treeH $treeM && |
315e7654 EN |
217 | git ls-files --stage >14.out && |
218 | test_must_fail git diff --no-index M.out 14.out >14diff.out && | |
c8596009 JH |
219 | compare_change 14diff.out expected && |
220 | check_cache_at nitfol clean' | |
221 | ||
222 | test_expect_success \ | |
223 | '15 - unchanged in two heads.' \ | |
224 | 'rm -f .git/index && | |
ea5070c9 | 225 | read_tree_must_succeed $treeH && |
5be60078 | 226 | git checkout-index -u -f -q -a && |
c8596009 | 227 | echo nitfol nitfol >nitfol && |
5be60078 | 228 | git update-index --add nitfol && |
c8596009 | 229 | echo nitfol nitfol nitfol >nitfol && |
76bc82ca | 230 | read_tree_twoway $treeH $treeM && |
315e7654 EN |
231 | git ls-files --stage >15.out && |
232 | test_must_fail git diff --no-index M.out 15.out >15diff.out && | |
c8596009 JH |
233 | compare_change 15diff.out expected && |
234 | check_cache_at nitfol dirty' | |
235 | ||
236 | test_expect_success \ | |
237 | '16 - conflicting local change.' \ | |
238 | 'rm -f .git/index && | |
ea5070c9 | 239 | read_tree_must_succeed $treeH && |
5be60078 | 240 | git checkout-index -u -f -q -a && |
c8596009 | 241 | echo bozbar bozbar >bozbar && |
5be60078 | 242 | git update-index --add bozbar && |
76bc82ca | 243 | if read_tree_twoway $treeH $treeM; then false; else :; fi' |
c8596009 JH |
244 | |
245 | test_expect_success \ | |
246 | '17 - conflicting local change.' \ | |
247 | 'rm -f .git/index && | |
ea5070c9 | 248 | read_tree_must_succeed $treeH && |
5be60078 | 249 | git checkout-index -u -f -q -a && |
c8596009 | 250 | echo bozbar bozbar >bozbar && |
5be60078 | 251 | git update-index --add bozbar && |
c8596009 | 252 | echo bozbar bozbar bozbar >bozbar && |
76bc82ca | 253 | if read_tree_twoway $treeH $treeM; then false; else :; fi' |
c8596009 JH |
254 | |
255 | test_expect_success \ | |
256 | '18 - local change already having a good result.' \ | |
257 | 'rm -f .git/index && | |
ea5070c9 | 258 | read_tree_must_succeed $treeH && |
5be60078 | 259 | git checkout-index -u -f -q -a && |
1abb3f14 | 260 | cat bozbar-new >bozbar && |
5be60078 | 261 | git update-index --add bozbar && |
76bc82ca | 262 | read_tree_twoway $treeH $treeM && |
5be60078 | 263 | git ls-files --stage >18.out && |
3af82863 | 264 | test_cmp M.out 18.out && |
c8596009 JH |
265 | check_cache_at bozbar clean' |
266 | ||
267 | test_expect_success \ | |
268 | '19 - local change already having a good result, further modified.' \ | |
269 | 'rm -f .git/index && | |
ea5070c9 | 270 | read_tree_must_succeed $treeH && |
5be60078 | 271 | git checkout-index -u -f -q -a && |
1abb3f14 | 272 | cat bozbar-new >bozbar && |
5be60078 | 273 | git update-index --add bozbar && |
c8596009 | 274 | echo gnusto gnusto >bozbar && |
76bc82ca | 275 | read_tree_twoway $treeH $treeM && |
5be60078 | 276 | git ls-files --stage >19.out && |
3af82863 | 277 | test_cmp M.out 19.out && |
c8596009 JH |
278 | check_cache_at bozbar dirty' |
279 | ||
280 | test_expect_success \ | |
281 | '20 - no local change, use new tree.' \ | |
282 | 'rm -f .git/index && | |
ea5070c9 | 283 | read_tree_must_succeed $treeH && |
5be60078 | 284 | git checkout-index -u -f -q -a && |
1abb3f14 | 285 | cat bozbar-old >bozbar && |
5be60078 | 286 | git update-index --add bozbar && |
76bc82ca | 287 | read_tree_twoway $treeH $treeM && |
5be60078 | 288 | git ls-files --stage >20.out && |
3af82863 | 289 | test_cmp M.out 20.out && |
c8596009 JH |
290 | check_cache_at bozbar dirty' |
291 | ||
292 | test_expect_success \ | |
293 | '21 - no local change, dirty cache.' \ | |
294 | 'rm -f .git/index && | |
ea5070c9 | 295 | read_tree_must_succeed $treeH && |
5be60078 | 296 | git checkout-index -u -f -q -a && |
1abb3f14 | 297 | cat bozbar-old >bozbar && |
5be60078 | 298 | git update-index --add bozbar && |
c8596009 | 299 | echo gnusto gnusto >bozbar && |
76bc82ca | 300 | if read_tree_twoway $treeH $treeM; then false; else :; fi' |
c8596009 | 301 | |
a75d7b54 | 302 | # This fails with straight two-way fast-forward. |
1abb3f14 JH |
303 | test_expect_success \ |
304 | '22 - local change cache updated.' \ | |
305 | 'rm -f .git/index && | |
ea5070c9 | 306 | read_tree_must_succeed $treeH && |
5be60078 | 307 | git checkout-index -u -f -q -a && |
1abb3f14 | 308 | sed -e "s/such as/SUCH AS/" bozbar-old >bozbar && |
5be60078 | 309 | git update-index --add bozbar && |
1abb3f14 JH |
310 | if read_tree_twoway $treeH $treeM; then false; else :; fi' |
311 | ||
c8596009 JH |
312 | # Also make sure we did not break DF vs DF/DF case. |
313 | test_expect_success \ | |
314 | 'DF vs DF/DF case setup.' \ | |
315 | 'rm -f .git/index && | |
316 | echo DF >DF && | |
5be60078 JH |
317 | git update-index --add DF && |
318 | treeDF=`git write-tree` && | |
c8596009 | 319 | echo treeDF $treeDF && |
5be60078 | 320 | git ls-tree $treeDF && |
c8596009 JH |
321 | |
322 | rm -f DF && | |
323 | mkdir DF && | |
324 | echo DF/DF >DF/DF && | |
5be60078 JH |
325 | git update-index --add --remove DF DF/DF && |
326 | treeDFDF=`git write-tree` && | |
c8596009 | 327 | echo treeDFDF $treeDFDF && |
5be60078 JH |
328 | git ls-tree $treeDFDF && |
329 | git ls-files --stage >DFDF.out' | |
c8596009 JH |
330 | |
331 | test_expect_success \ | |
332 | 'DF vs DF/DF case test.' \ | |
333 | 'rm -f .git/index && | |
334 | rm -fr DF && | |
335 | echo DF >DF && | |
5be60078 | 336 | git update-index --add DF && |
76bc82ca | 337 | read_tree_twoway $treeDF $treeDFDF && |
5be60078 | 338 | git ls-files --stage >DFDFcheck.out && |
3af82863 | 339 | test_cmp DFDF.out DFDFcheck.out && |
76bc82ca JH |
340 | check_cache_at DF/DF dirty && |
341 | :' | |
c8596009 | 342 | |
6b9315d5 CB |
343 | test_expect_success \ |
344 | 'a/b (untracked) vs a case setup.' \ | |
345 | 'rm -f .git/index && | |
346 | : >a && | |
347 | git update-index --add a && | |
348 | treeM=`git write-tree` && | |
349 | echo treeM $treeM && | |
350 | git ls-tree $treeM && | |
351 | git ls-files --stage >treeM.out && | |
352 | ||
353 | rm -f a && | |
354 | git update-index --remove a && | |
355 | mkdir a && | |
356 | : >a/b && | |
357 | treeH=`git write-tree` && | |
358 | echo treeH $treeH && | |
359 | git ls-tree $treeH' | |
360 | ||
361 | test_expect_success \ | |
362 | 'a/b (untracked) vs a, plus c/d case test.' \ | |
ea5070c9 | 363 | 'read_tree_u_must_fail -u -m "$treeH" "$treeM" && |
6b9315d5 CB |
364 | git ls-files --stage && |
365 | test -f a/b' | |
366 | ||
837e5fe9 CB |
367 | test_expect_success \ |
368 | 'a/b vs a, plus c/d case setup.' \ | |
369 | 'rm -f .git/index && | |
370 | rm -fr a && | |
371 | : >a && | |
372 | mkdir c && | |
373 | : >c/d && | |
374 | git update-index --add a c/d && | |
375 | treeM=`git write-tree` && | |
376 | echo treeM $treeM && | |
377 | git ls-tree $treeM && | |
378 | git ls-files --stage >treeM.out && | |
379 | ||
380 | rm -f a && | |
315e7654 | 381 | mkdir a && |
837e5fe9 CB |
382 | : >a/b && |
383 | git update-index --add --remove a a/b && | |
384 | treeH=`git write-tree` && | |
385 | echo treeH $treeH && | |
386 | git ls-tree $treeH' | |
387 | ||
388 | test_expect_success \ | |
389 | 'a/b vs a, plus c/d case test.' \ | |
ea5070c9 | 390 | 'read_tree_u_must_succeed -u -m "$treeH" "$treeM" && |
837e5fe9 CB |
391 | git ls-files --stage | tee >treeMcheck.out && |
392 | test_cmp treeM.out treeMcheck.out' | |
393 | ||
b1f47514 JH |
394 | test_expect_success '-m references the correct modified tree' ' |
395 | echo >file-a && | |
396 | echo >file-b && | |
397 | git add file-a file-b && | |
a48fcd83 | 398 | git commit -a -m "test for correct modified tree" && |
b1f47514 JH |
399 | git branch initial-mod && |
400 | echo b >file-b && | |
401 | git commit -a -m "B" && | |
402 | echo a >file-a && | |
403 | git add file-a && | |
404 | git ls-tree $(git write-tree) file-a >expect && | |
ea5070c9 | 405 | read_tree_must_succeed -m HEAD initial-mod && |
b1f47514 JH |
406 | git ls-tree $(git write-tree) file-a >actual && |
407 | test_cmp expect actual | |
408 | ' | |
409 | ||
c8596009 | 410 | test_done |