| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='merge-recursive backend test' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success 'setup 1' ' |
| 11 | |
| 12 | echo hello >a && |
| 13 | o0=$(git hash-object a) && |
| 14 | cp a b && |
| 15 | cp a c && |
| 16 | mkdir d && |
| 17 | cp a d/e && |
| 18 | |
| 19 | test_tick && |
| 20 | git add a b c d/e && |
| 21 | git commit -m initial && |
| 22 | c0=$(git rev-parse --verify HEAD) && |
| 23 | git branch side && |
| 24 | git branch df-1 && |
| 25 | git branch df-2 && |
| 26 | git branch df-3 && |
| 27 | git branch remove && |
| 28 | git branch submod && |
| 29 | git branch copy && |
| 30 | git branch rename && |
| 31 | git branch rename-ln && |
| 32 | |
| 33 | echo hello >>a && |
| 34 | cp a d/e && |
| 35 | o1=$(git hash-object a) && |
| 36 | |
| 37 | git add a d/e && |
| 38 | |
| 39 | test_tick && |
| 40 | git commit -m "main modifies a and d/e" && |
| 41 | c1=$(git rev-parse --verify HEAD) && |
| 42 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 43 | ( |
| 44 | echo "100644 blob $o1 a" && |
| 45 | echo "100644 blob $o0 b" && |
| 46 | echo "100644 blob $o0 c" && |
| 47 | echo "100644 blob $o1 d/e" && |
| 48 | echo "100644 $o1 0 a" && |
| 49 | echo "100644 $o0 0 b" && |
| 50 | echo "100644 $o0 0 c" && |
| 51 | echo "100644 $o1 0 d/e" |
| 52 | ) >expected && |
| 53 | test_cmp expected actual |
| 54 | ' |
| 55 | |
| 56 | test_expect_success 'setup 2' ' |
| 57 | |
| 58 | rm -rf [abcd] && |
| 59 | git checkout side && |
| 60 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 61 | ( |
| 62 | echo "100644 blob $o0 a" && |
| 63 | echo "100644 blob $o0 b" && |
| 64 | echo "100644 blob $o0 c" && |
| 65 | echo "100644 blob $o0 d/e" && |
| 66 | echo "100644 $o0 0 a" && |
| 67 | echo "100644 $o0 0 b" && |
| 68 | echo "100644 $o0 0 c" && |
| 69 | echo "100644 $o0 0 d/e" |
| 70 | ) >expected && |
| 71 | test_cmp expected actual && |
| 72 | |
| 73 | echo goodbye >>a && |
| 74 | o2=$(git hash-object a) && |
| 75 | |
| 76 | git add a && |
| 77 | |
| 78 | test_tick && |
| 79 | git commit -m "side modifies a" && |
| 80 | c2=$(git rev-parse --verify HEAD) && |
| 81 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 82 | ( |
| 83 | echo "100644 blob $o2 a" && |
| 84 | echo "100644 blob $o0 b" && |
| 85 | echo "100644 blob $o0 c" && |
| 86 | echo "100644 blob $o0 d/e" && |
| 87 | echo "100644 $o2 0 a" && |
| 88 | echo "100644 $o0 0 b" && |
| 89 | echo "100644 $o0 0 c" && |
| 90 | echo "100644 $o0 0 d/e" |
| 91 | ) >expected && |
| 92 | test_cmp expected actual |
| 93 | ' |
| 94 | |
| 95 | test_expect_success 'setup 3' ' |
| 96 | |
| 97 | rm -rf [abcd] && |
| 98 | git checkout df-1 && |
| 99 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 100 | ( |
| 101 | echo "100644 blob $o0 a" && |
| 102 | echo "100644 blob $o0 b" && |
| 103 | echo "100644 blob $o0 c" && |
| 104 | echo "100644 blob $o0 d/e" && |
| 105 | echo "100644 $o0 0 a" && |
| 106 | echo "100644 $o0 0 b" && |
| 107 | echo "100644 $o0 0 c" && |
| 108 | echo "100644 $o0 0 d/e" |
| 109 | ) >expected && |
| 110 | test_cmp expected actual && |
| 111 | |
| 112 | rm -f b && mkdir b && echo df-1 >b/c && git add b/c && |
| 113 | o3=$(git hash-object b/c) && |
| 114 | |
| 115 | test_tick && |
| 116 | git commit -m "df-1 makes b/c" && |
| 117 | c3=$(git rev-parse --verify HEAD) && |
| 118 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 119 | ( |
| 120 | echo "100644 blob $o0 a" && |
| 121 | echo "100644 blob $o3 b/c" && |
| 122 | echo "100644 blob $o0 c" && |
| 123 | echo "100644 blob $o0 d/e" && |
| 124 | echo "100644 $o0 0 a" && |
| 125 | echo "100644 $o3 0 b/c" && |
| 126 | echo "100644 $o0 0 c" && |
| 127 | echo "100644 $o0 0 d/e" |
| 128 | ) >expected && |
| 129 | test_cmp expected actual |
| 130 | ' |
| 131 | |
| 132 | test_expect_success 'setup 4' ' |
| 133 | |
| 134 | rm -rf [abcd] && |
| 135 | git checkout df-2 && |
| 136 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 137 | ( |
| 138 | echo "100644 blob $o0 a" && |
| 139 | echo "100644 blob $o0 b" && |
| 140 | echo "100644 blob $o0 c" && |
| 141 | echo "100644 blob $o0 d/e" && |
| 142 | echo "100644 $o0 0 a" && |
| 143 | echo "100644 $o0 0 b" && |
| 144 | echo "100644 $o0 0 c" && |
| 145 | echo "100644 $o0 0 d/e" |
| 146 | ) >expected && |
| 147 | test_cmp expected actual && |
| 148 | |
| 149 | rm -f a && mkdir a && echo df-2 >a/c && git add a/c && |
| 150 | o4=$(git hash-object a/c) && |
| 151 | |
| 152 | test_tick && |
| 153 | git commit -m "df-2 makes a/c" && |
| 154 | c4=$(git rev-parse --verify HEAD) && |
| 155 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 156 | ( |
| 157 | echo "100644 blob $o4 a/c" && |
| 158 | echo "100644 blob $o0 b" && |
| 159 | echo "100644 blob $o0 c" && |
| 160 | echo "100644 blob $o0 d/e" && |
| 161 | echo "100644 $o4 0 a/c" && |
| 162 | echo "100644 $o0 0 b" && |
| 163 | echo "100644 $o0 0 c" && |
| 164 | echo "100644 $o0 0 d/e" |
| 165 | ) >expected && |
| 166 | test_cmp expected actual |
| 167 | ' |
| 168 | |
| 169 | test_expect_success 'setup 5' ' |
| 170 | |
| 171 | rm -rf [abcd] && |
| 172 | git checkout remove && |
| 173 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 174 | ( |
| 175 | echo "100644 blob $o0 a" && |
| 176 | echo "100644 blob $o0 b" && |
| 177 | echo "100644 blob $o0 c" && |
| 178 | echo "100644 blob $o0 d/e" && |
| 179 | echo "100644 $o0 0 a" && |
| 180 | echo "100644 $o0 0 b" && |
| 181 | echo "100644 $o0 0 c" && |
| 182 | echo "100644 $o0 0 d/e" |
| 183 | ) >expected && |
| 184 | test_cmp expected actual && |
| 185 | |
| 186 | rm -f b && |
| 187 | echo remove-conflict >a && |
| 188 | |
| 189 | git add a && |
| 190 | git rm b && |
| 191 | o5=$(git hash-object a) && |
| 192 | |
| 193 | test_tick && |
| 194 | git commit -m "remove removes b and modifies a" && |
| 195 | c5=$(git rev-parse --verify HEAD) && |
| 196 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 197 | ( |
| 198 | echo "100644 blob $o5 a" && |
| 199 | echo "100644 blob $o0 c" && |
| 200 | echo "100644 blob $o0 d/e" && |
| 201 | echo "100644 $o5 0 a" && |
| 202 | echo "100644 $o0 0 c" && |
| 203 | echo "100644 $o0 0 d/e" |
| 204 | ) >expected && |
| 205 | test_cmp expected actual |
| 206 | |
| 207 | ' |
| 208 | |
| 209 | test_expect_success 'setup 6' ' |
| 210 | |
| 211 | rm -rf [abcd] && |
| 212 | git checkout df-3 && |
| 213 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 214 | ( |
| 215 | echo "100644 blob $o0 a" && |
| 216 | echo "100644 blob $o0 b" && |
| 217 | echo "100644 blob $o0 c" && |
| 218 | echo "100644 blob $o0 d/e" && |
| 219 | echo "100644 $o0 0 a" && |
| 220 | echo "100644 $o0 0 b" && |
| 221 | echo "100644 $o0 0 c" && |
| 222 | echo "100644 $o0 0 d/e" |
| 223 | ) >expected && |
| 224 | test_cmp expected actual && |
| 225 | |
| 226 | rm -fr d && echo df-3 >d && git add d && |
| 227 | o6=$(git hash-object d) && |
| 228 | |
| 229 | test_tick && |
| 230 | git commit -m "df-3 makes d" && |
| 231 | c6=$(git rev-parse --verify HEAD) && |
| 232 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 233 | ( |
| 234 | echo "100644 blob $o0 a" && |
| 235 | echo "100644 blob $o0 b" && |
| 236 | echo "100644 blob $o0 c" && |
| 237 | echo "100644 blob $o6 d" && |
| 238 | echo "100644 $o0 0 a" && |
| 239 | echo "100644 $o0 0 b" && |
| 240 | echo "100644 $o0 0 c" && |
| 241 | echo "100644 $o6 0 d" |
| 242 | ) >expected && |
| 243 | test_cmp expected actual |
| 244 | ' |
| 245 | |
| 246 | test_expect_success 'setup 7' ' |
| 247 | |
| 248 | git checkout submod && |
| 249 | git rm d/e && |
| 250 | test_tick && |
| 251 | git commit -m "remove d/e" && |
| 252 | git update-index --add --cacheinfo 160000 $c1 d && |
| 253 | test_tick && |
| 254 | git commit -m "make d/ a submodule" |
| 255 | ' |
| 256 | |
| 257 | test_expect_success 'setup 8' ' |
| 258 | git checkout rename && |
| 259 | git mv a e && |
| 260 | git add e && |
| 261 | test_tick && |
| 262 | git commit -m "rename a->e" && |
| 263 | c7=$(git rev-parse --verify HEAD) && |
| 264 | git checkout rename-ln && |
| 265 | git mv a e && |
| 266 | test_ln_s_add e a && |
| 267 | test_tick && |
| 268 | git commit -m "rename a->e, symlink a->e" && |
| 269 | oln=$(printf e | git hash-object --stdin) |
| 270 | ' |
| 271 | |
| 272 | test_expect_success 'setup 9' ' |
| 273 | git checkout copy && |
| 274 | cp a e && |
| 275 | git add e && |
| 276 | test_tick && |
| 277 | git commit -m "copy a->e" |
| 278 | ' |
| 279 | |
| 280 | test_expect_success 'merge-recursive simple' ' |
| 281 | |
| 282 | rm -fr [abcd] && |
| 283 | git checkout -f "$c2" && |
| 284 | |
| 285 | test_expect_code 1 git merge-recursive "$c0" -- "$c2" "$c1" |
| 286 | ' |
| 287 | |
| 288 | test_expect_success 'merge-recursive result' ' |
| 289 | |
| 290 | git ls-files -s >actual && |
| 291 | ( |
| 292 | echo "100644 $o0 1 a" && |
| 293 | echo "100644 $o2 2 a" && |
| 294 | echo "100644 $o1 3 a" && |
| 295 | echo "100644 $o0 0 b" && |
| 296 | echo "100644 $o0 0 c" && |
| 297 | echo "100644 $o1 0 d/e" |
| 298 | ) >expected && |
| 299 | test_cmp expected actual |
| 300 | |
| 301 | ' |
| 302 | |
| 303 | test_expect_success 'fail if the index has unresolved entries' ' |
| 304 | |
| 305 | rm -fr [abcd] && |
| 306 | git checkout -f "$c1" && |
| 307 | |
| 308 | test_must_fail git merge "$c5" && |
| 309 | test_must_fail git merge "$c5" 2> out && |
| 310 | test_grep "not possible because you have unmerged files" out && |
| 311 | git add -u && |
| 312 | test_must_fail git merge "$c5" 2> out && |
| 313 | test_grep "You have not concluded your merge" out && |
| 314 | rm -f .git/MERGE_HEAD && |
| 315 | test_must_fail git merge "$c5" 2> out && |
| 316 | test_grep "Your local changes to the following files would be overwritten by merge:" out |
| 317 | ' |
| 318 | |
| 319 | test_expect_success 'merge-recursive remove conflict' ' |
| 320 | |
| 321 | rm -fr [abcd] && |
| 322 | git checkout -f "$c1" && |
| 323 | |
| 324 | test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c5" |
| 325 | ' |
| 326 | |
| 327 | test_expect_success 'merge-recursive remove conflict' ' |
| 328 | |
| 329 | git ls-files -s >actual && |
| 330 | ( |
| 331 | echo "100644 $o0 1 a" && |
| 332 | echo "100644 $o1 2 a" && |
| 333 | echo "100644 $o5 3 a" && |
| 334 | echo "100644 $o0 0 c" && |
| 335 | echo "100644 $o1 0 d/e" |
| 336 | ) >expected && |
| 337 | test_cmp expected actual |
| 338 | |
| 339 | ' |
| 340 | |
| 341 | test_expect_success 'merge-recursive d/f simple' ' |
| 342 | rm -fr [abcd] && |
| 343 | git reset --hard && |
| 344 | git checkout -f "$c1" && |
| 345 | |
| 346 | git merge-recursive "$c0" -- "$c1" "$c3" |
| 347 | ' |
| 348 | |
| 349 | test_expect_success 'merge-recursive result' ' |
| 350 | |
| 351 | git ls-files -s >actual && |
| 352 | ( |
| 353 | echo "100644 $o1 0 a" && |
| 354 | echo "100644 $o3 0 b/c" && |
| 355 | echo "100644 $o0 0 c" && |
| 356 | echo "100644 $o1 0 d/e" |
| 357 | ) >expected && |
| 358 | test_cmp expected actual |
| 359 | |
| 360 | ' |
| 361 | |
| 362 | test_expect_success 'merge-recursive d/f conflict' ' |
| 363 | |
| 364 | rm -fr [abcd] && |
| 365 | git reset --hard && |
| 366 | git checkout -f "$c1" && |
| 367 | |
| 368 | test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c4" |
| 369 | ' |
| 370 | |
| 371 | test_expect_success 'merge-recursive d/f conflict result' ' |
| 372 | |
| 373 | git ls-files -s >actual && |
| 374 | ( |
| 375 | echo "100644 $o4 0 a/c" && |
| 376 | echo "100644 $o0 1 a~$c1" && |
| 377 | echo "100644 $o1 2 a~$c1" && |
| 378 | echo "100644 $o0 0 b" && |
| 379 | echo "100644 $o0 0 c" && |
| 380 | echo "100644 $o1 0 d/e" |
| 381 | ) >expected && |
| 382 | test_cmp expected actual |
| 383 | |
| 384 | ' |
| 385 | |
| 386 | test_expect_success 'merge-recursive d/f conflict the other way' ' |
| 387 | |
| 388 | rm -fr [abcd] && |
| 389 | git reset --hard && |
| 390 | git checkout -f "$c4" && |
| 391 | |
| 392 | test_expect_code 1 git merge-recursive "$c0" -- "$c4" "$c1" |
| 393 | ' |
| 394 | |
| 395 | test_expect_success 'merge-recursive d/f conflict result the other way' ' |
| 396 | |
| 397 | git ls-files -s >actual && |
| 398 | ( |
| 399 | echo "100644 $o4 0 a/c" && |
| 400 | echo "100644 $o0 1 a~$c1" && |
| 401 | echo "100644 $o1 3 a~$c1" && |
| 402 | echo "100644 $o0 0 b" && |
| 403 | echo "100644 $o0 0 c" && |
| 404 | echo "100644 $o1 0 d/e" |
| 405 | ) >expected && |
| 406 | test_cmp expected actual |
| 407 | |
| 408 | ' |
| 409 | |
| 410 | test_expect_success 'merge-recursive d/f conflict' ' |
| 411 | |
| 412 | rm -fr [abcd] && |
| 413 | git reset --hard && |
| 414 | git checkout -f "$c1" && |
| 415 | |
| 416 | test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c6" |
| 417 | ' |
| 418 | |
| 419 | test_expect_success 'merge-recursive d/f conflict result' ' |
| 420 | |
| 421 | git ls-files -s >actual && |
| 422 | ( |
| 423 | echo "100644 $o1 0 a" && |
| 424 | echo "100644 $o0 0 b" && |
| 425 | echo "100644 $o0 0 c" && |
| 426 | echo "100644 $o0 1 d/e" && |
| 427 | echo "100644 $o1 2 d/e" && |
| 428 | echo "100644 $o6 3 d~$c6" |
| 429 | ) >expected && |
| 430 | test_cmp expected actual |
| 431 | |
| 432 | ' |
| 433 | |
| 434 | test_expect_success 'merge-recursive d/f conflict' ' |
| 435 | |
| 436 | rm -fr [abcd] && |
| 437 | git reset --hard && |
| 438 | git checkout -f "$c6" && |
| 439 | |
| 440 | test_expect_code 1 git merge-recursive "$c0" -- "$c6" "$c1" |
| 441 | ' |
| 442 | |
| 443 | test_expect_success 'merge-recursive d/f conflict result' ' |
| 444 | |
| 445 | git ls-files -s >actual && |
| 446 | ( |
| 447 | echo "100644 $o1 0 a" && |
| 448 | echo "100644 $o0 0 b" && |
| 449 | echo "100644 $o0 0 c" && |
| 450 | echo "100644 $o0 1 d/e" && |
| 451 | echo "100644 $o1 3 d/e" && |
| 452 | echo "100644 $o6 2 d~$c6" |
| 453 | ) >expected && |
| 454 | test_cmp expected actual |
| 455 | |
| 456 | ' |
| 457 | |
| 458 | test_expect_success SYMLINKS 'dir in working tree with symlink ancestor does not produce d/f conflict' ' |
| 459 | git init sym && |
| 460 | ( |
| 461 | cd sym && |
| 462 | ln -s . foo && |
| 463 | mkdir bar && |
| 464 | >bar/file && |
| 465 | git add foo bar/file && |
| 466 | git commit -m "foo symlink" && |
| 467 | |
| 468 | git checkout -b branch1 && |
| 469 | git commit --allow-empty -m "empty commit" && |
| 470 | |
| 471 | git checkout main && |
| 472 | git rm foo && |
| 473 | mkdir foo && |
| 474 | >foo/bar && |
| 475 | git add foo/bar && |
| 476 | git commit -m "replace foo symlink with real foo dir and foo/bar file" && |
| 477 | |
| 478 | git checkout branch1 && |
| 479 | |
| 480 | git cherry-pick main && |
| 481 | test_path_is_dir foo && |
| 482 | test_path_is_file foo/bar |
| 483 | ) |
| 484 | ' |
| 485 | |
| 486 | test_expect_success 'reset and 3-way merge' ' |
| 487 | |
| 488 | git reset --hard "$c2" && |
| 489 | git read-tree -m "$c0" "$c2" "$c1" |
| 490 | |
| 491 | ' |
| 492 | |
| 493 | test_expect_success 'reset and bind merge' ' |
| 494 | |
| 495 | git reset --hard main && |
| 496 | git read-tree --prefix=M/ main && |
| 497 | git ls-files -s >actual && |
| 498 | ( |
| 499 | echo "100644 $o1 0 M/a" && |
| 500 | echo "100644 $o0 0 M/b" && |
| 501 | echo "100644 $o0 0 M/c" && |
| 502 | echo "100644 $o1 0 M/d/e" && |
| 503 | echo "100644 $o1 0 a" && |
| 504 | echo "100644 $o0 0 b" && |
| 505 | echo "100644 $o0 0 c" && |
| 506 | echo "100644 $o1 0 d/e" |
| 507 | ) >expected && |
| 508 | test_cmp expected actual && |
| 509 | |
| 510 | git read-tree --prefix=a1/ main && |
| 511 | git ls-files -s >actual && |
| 512 | ( |
| 513 | echo "100644 $o1 0 M/a" && |
| 514 | echo "100644 $o0 0 M/b" && |
| 515 | echo "100644 $o0 0 M/c" && |
| 516 | echo "100644 $o1 0 M/d/e" && |
| 517 | echo "100644 $o1 0 a" && |
| 518 | echo "100644 $o1 0 a1/a" && |
| 519 | echo "100644 $o0 0 a1/b" && |
| 520 | echo "100644 $o0 0 a1/c" && |
| 521 | echo "100644 $o1 0 a1/d/e" && |
| 522 | echo "100644 $o0 0 b" && |
| 523 | echo "100644 $o0 0 c" && |
| 524 | echo "100644 $o1 0 d/e" |
| 525 | ) >expected && |
| 526 | test_cmp expected actual && |
| 527 | |
| 528 | git read-tree --prefix=z/ main && |
| 529 | git ls-files -s >actual && |
| 530 | ( |
| 531 | echo "100644 $o1 0 M/a" && |
| 532 | echo "100644 $o0 0 M/b" && |
| 533 | echo "100644 $o0 0 M/c" && |
| 534 | echo "100644 $o1 0 M/d/e" && |
| 535 | echo "100644 $o1 0 a" && |
| 536 | echo "100644 $o1 0 a1/a" && |
| 537 | echo "100644 $o0 0 a1/b" && |
| 538 | echo "100644 $o0 0 a1/c" && |
| 539 | echo "100644 $o1 0 a1/d/e" && |
| 540 | echo "100644 $o0 0 b" && |
| 541 | echo "100644 $o0 0 c" && |
| 542 | echo "100644 $o1 0 d/e" && |
| 543 | echo "100644 $o1 0 z/a" && |
| 544 | echo "100644 $o0 0 z/b" && |
| 545 | echo "100644 $o0 0 z/c" && |
| 546 | echo "100644 $o1 0 z/d/e" |
| 547 | ) >expected && |
| 548 | test_cmp expected actual |
| 549 | |
| 550 | ' |
| 551 | |
| 552 | test_expect_success 'merge-recursive w/ empty work tree - ours has rename' ' |
| 553 | ( |
| 554 | GIT_WORK_TREE="$PWD/ours-has-rename-work" && |
| 555 | export GIT_WORK_TREE && |
| 556 | GIT_INDEX_FILE="$PWD/ours-has-rename-index" && |
| 557 | export GIT_INDEX_FILE && |
| 558 | mkdir "$GIT_WORK_TREE" && |
| 559 | git read-tree -i -m $c7 2>actual-err && |
| 560 | test_must_be_empty actual-err && |
| 561 | git update-index --ignore-missing --refresh 2>actual-err && |
| 562 | test_must_be_empty actual-err && |
| 563 | git merge-recursive $c0 -- $c7 $c3 2>actual-err && |
| 564 | test_must_be_empty actual-err && |
| 565 | git ls-files -s >actual-files 2>actual-err && |
| 566 | test_must_be_empty actual-err |
| 567 | ) && |
| 568 | cat >expected-files <<-EOF && |
| 569 | 100644 $o3 0 b/c |
| 570 | 100644 $o0 0 c |
| 571 | 100644 $o0 0 d/e |
| 572 | 100644 $o0 0 e |
| 573 | EOF |
| 574 | test_cmp expected-files actual-files |
| 575 | ' |
| 576 | |
| 577 | test_expect_success 'merge-recursive w/ empty work tree - theirs has rename' ' |
| 578 | ( |
| 579 | GIT_WORK_TREE="$PWD/theirs-has-rename-work" && |
| 580 | export GIT_WORK_TREE && |
| 581 | GIT_INDEX_FILE="$PWD/theirs-has-rename-index" && |
| 582 | export GIT_INDEX_FILE && |
| 583 | mkdir "$GIT_WORK_TREE" && |
| 584 | git read-tree -i -m $c3 2>actual-err && |
| 585 | test_must_be_empty actual-err && |
| 586 | git update-index --ignore-missing --refresh 2>actual-err && |
| 587 | test_must_be_empty actual-err && |
| 588 | git merge-recursive $c0 -- $c3 $c7 2>actual-err && |
| 589 | test_must_be_empty actual-err && |
| 590 | git ls-files -s >actual-files 2>actual-err && |
| 591 | test_must_be_empty actual-err |
| 592 | ) && |
| 593 | cat >expected-files <<-EOF && |
| 594 | 100644 $o3 0 b/c |
| 595 | 100644 $o0 0 c |
| 596 | 100644 $o0 0 d/e |
| 597 | 100644 $o0 0 e |
| 598 | EOF |
| 599 | test_cmp expected-files actual-files |
| 600 | ' |
| 601 | |
| 602 | test_expect_success 'merge removes empty directories' ' |
| 603 | |
| 604 | git reset --hard main && |
| 605 | git checkout -b rm && |
| 606 | git rm d/e && |
| 607 | git commit -mremoved-d/e && |
| 608 | git checkout main && |
| 609 | git merge -s recursive rm && |
| 610 | test_path_is_missing d |
| 611 | ' |
| 612 | |
| 613 | test_expect_success 'merge-recursive simple w/submodule' ' |
| 614 | |
| 615 | git checkout submod && |
| 616 | git merge remove |
| 617 | ' |
| 618 | |
| 619 | test_expect_success 'merge-recursive simple w/submodule result' ' |
| 620 | |
| 621 | git ls-files -s >actual && |
| 622 | ( |
| 623 | echo "100644 $o5 0 a" && |
| 624 | echo "100644 $o0 0 c" && |
| 625 | echo "160000 $c1 0 d" |
| 626 | ) >expected && |
| 627 | test_cmp expected actual |
| 628 | ' |
| 629 | |
| 630 | test_expect_success 'merge-recursive copy vs. rename' ' |
| 631 | git checkout -f copy && |
| 632 | git merge rename && |
| 633 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 634 | ( |
| 635 | echo "100644 blob $o0 b" && |
| 636 | echo "100644 blob $o0 c" && |
| 637 | echo "100644 blob $o0 d/e" && |
| 638 | echo "100644 blob $o0 e" && |
| 639 | echo "100644 $o0 0 b" && |
| 640 | echo "100644 $o0 0 c" && |
| 641 | echo "100644 $o0 0 d/e" && |
| 642 | echo "100644 $o0 0 e" |
| 643 | ) >expected && |
| 644 | test_cmp expected actual |
| 645 | ' |
| 646 | |
| 647 | test_expect_success 'merge-recursive rename vs. rename/symlink' ' |
| 648 | |
| 649 | git checkout -f rename && |
| 650 | git merge rename-ln && |
| 651 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
| 652 | ( |
| 653 | echo "120000 blob $oln a" && |
| 654 | echo "100644 blob $o0 b" && |
| 655 | echo "100644 blob $o0 c" && |
| 656 | echo "100644 blob $o0 d/e" && |
| 657 | echo "100644 blob $o0 e" && |
| 658 | echo "120000 $oln 0 a" && |
| 659 | echo "100644 $o0 0 b" && |
| 660 | echo "100644 $o0 0 c" && |
| 661 | echo "100644 $o0 0 d/e" && |
| 662 | echo "100644 $o0 0 e" |
| 663 | ) >expected && |
| 664 | test_cmp expected actual |
| 665 | ' |
| 666 | |
| 667 | test_expect_success 'merging with triple rename across D/F conflict' ' |
| 668 | git reset --hard HEAD && |
| 669 | git checkout -b topic && |
| 670 | git rm -rf . && |
| 671 | |
| 672 | echo "just a file" >sub1 && |
| 673 | mkdir -p sub2 && |
| 674 | echo content1 >sub2/file1 && |
| 675 | echo content2 >sub2/file2 && |
| 676 | echo content3 >sub2/file3 && |
| 677 | mkdir simple && |
| 678 | echo base >simple/bar && |
| 679 | git add -A && |
| 680 | test_tick && |
| 681 | git commit -m base && |
| 682 | |
| 683 | git checkout -b other && |
| 684 | echo more >>simple/bar && |
| 685 | test_tick && |
| 686 | git commit -a -m changesimplefile && |
| 687 | |
| 688 | git checkout topic && |
| 689 | git rm sub1 && |
| 690 | git mv sub2 sub1 && |
| 691 | test_tick && |
| 692 | git commit -m changefiletodir && |
| 693 | |
| 694 | test_tick && |
| 695 | git merge other |
| 696 | ' |
| 697 | |
| 698 | test_expect_success 'merge-recursive internal merge resolves to the sameness' ' |
| 699 | git reset --hard HEAD && |
| 700 | |
| 701 | # We are going to create a history leading to two criss-cross |
| 702 | # branches A and B. The common ancestor at the bottom, O0, |
| 703 | # has two child commits O1 and O2, both of which will be merge |
| 704 | # base between A and B, like so: |
| 705 | # |
| 706 | # O1---A |
| 707 | # / \ / |
| 708 | # O0 . |
| 709 | # \ / \ |
| 710 | # O2---B |
| 711 | # |
| 712 | # The recently added "check to see if the index is different from |
| 713 | # the tree into which something else is getting merged" check must |
| 714 | # NOT kick in when an inner merge between O1 and O2 is made. Both |
| 715 | # O1 and O2 happen to have the same tree as O0 in this test to |
| 716 | # trigger the bug---whether the inner merge is made by merging O2 |
| 717 | # into O1 or O1 into O2, their common ancestor O0 and the branch |
| 718 | # being merged have the same tree. We should not trigger the "is |
| 719 | # the index dirty?" check in this case. |
| 720 | |
| 721 | echo "zero" >file && |
| 722 | git add file && |
| 723 | test_tick && |
| 724 | git commit -m "O0" && |
| 725 | O0=$(git rev-parse HEAD) && |
| 726 | |
| 727 | test_tick && |
| 728 | git commit --allow-empty -m "O1" && |
| 729 | O1=$(git rev-parse HEAD) && |
| 730 | |
| 731 | git reset --hard $O0 && |
| 732 | test_tick && |
| 733 | git commit --allow-empty -m "O2" && |
| 734 | O2=$(git rev-parse HEAD) && |
| 735 | |
| 736 | test_tick && |
| 737 | git merge -s ours $O1 && |
| 738 | B=$(git rev-parse HEAD) && |
| 739 | |
| 740 | git reset --hard $O1 && |
| 741 | test_tick && |
| 742 | git merge -s ours $O2 && |
| 743 | A=$(git rev-parse HEAD) && |
| 744 | |
| 745 | git merge $B |
| 746 | ' |
| 747 | |
| 748 | test_done |