| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Lars Hjemli |
| 4 | # |
| 5 | |
| 6 | test_description='git merge |
| 7 | |
| 8 | Testing basic merge operations/option parsing. |
| 9 | |
| 10 | ! [c0] commit 0 |
| 11 | ! [c1] commit 1 |
| 12 | ! [c2] commit 2 |
| 13 | ! [c3] commit 3 |
| 14 | ! [c4] c4 |
| 15 | ! [c5] c5 |
| 16 | ! [c6] c6 |
| 17 | * [main] Merge commit 'c1' |
| 18 | -------- |
| 19 | - [main] Merge commit 'c1' |
| 20 | + * [c1] commit 1 |
| 21 | + [c6] c6 |
| 22 | + [c5] c5 |
| 23 | ++ [c4] c4 |
| 24 | ++++ [c3] commit 3 |
| 25 | + [c2] commit 2 |
| 26 | +++++++* [c0] commit 0 |
| 27 | ' |
| 28 | |
| 29 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 30 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 31 | |
| 32 | . ./test-lib.sh |
| 33 | . "$TEST_DIRECTORY"/lib-gpg.sh |
| 34 | |
| 35 | test_write_lines 1 2 3 4 5 6 7 8 9 >file |
| 36 | cp file file.orig |
| 37 | test_write_lines '1 X' 2 3 4 5 6 7 8 9 >file.1 |
| 38 | test_write_lines 1 2 '3 X' 4 5 6 7 8 9 >file.3 |
| 39 | test_write_lines 1 2 3 4 '5 X' 6 7 8 9 >file.5 |
| 40 | test_write_lines 1 2 3 4 5 6 7 8 '9 X' >file.9 |
| 41 | test_write_lines 1 2 3 4 5 6 7 8 '9 Y' >file.9y |
| 42 | test_write_lines '1 X' 2 3 4 5 6 7 8 9 >result.1 |
| 43 | test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5 |
| 44 | test_write_lines '1 X' 2 3 4 5 6 7 8 '9 X' >result.1-9 |
| 45 | test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9 |
| 46 | test_write_lines '1 X' 2 '3 X' 4 '5 X' 6 7 8 '9 X' >result.1-3-5-9 |
| 47 | test_write_lines 1 2 3 4 5 6 7 8 '9 Z' >result.9z |
| 48 | |
| 49 | create_merge_msgs () { |
| 50 | echo "Merge tag 'c2'" >msg.1-5 && |
| 51 | echo "Merge tags 'c2' and 'c3'" >msg.1-5-9 && |
| 52 | { |
| 53 | echo "Squashed commit of the following:" && |
| 54 | echo && |
| 55 | git log --no-merges ^HEAD c1 |
| 56 | } >squash.1 && |
| 57 | { |
| 58 | echo "Squashed commit of the following:" && |
| 59 | echo && |
| 60 | git log --no-merges ^HEAD c2 |
| 61 | } >squash.1-5 && |
| 62 | { |
| 63 | echo "Squashed commit of the following:" && |
| 64 | echo && |
| 65 | git log --no-merges ^HEAD c2 c3 |
| 66 | } >squash.1-5-9 && |
| 67 | { |
| 68 | echo "* tag 'c3':" && |
| 69 | echo " commit 3" |
| 70 | } >msg.log |
| 71 | } |
| 72 | |
| 73 | verify_merge () { |
| 74 | test_cmp "$2" "$1" && |
| 75 | git update-index --refresh && |
| 76 | git diff --exit-code && |
| 77 | if test -n "$3" |
| 78 | then |
| 79 | git show -s --pretty=tformat:%s HEAD >msg.act && |
| 80 | test_cmp "$3" msg.act |
| 81 | fi |
| 82 | } |
| 83 | |
| 84 | verify_head () { |
| 85 | echo "$1" >head.expected && |
| 86 | git rev-parse HEAD >head.actual && |
| 87 | test_cmp head.expected head.actual |
| 88 | } |
| 89 | |
| 90 | verify_parents () { |
| 91 | test_write_lines "$@" >parents.expected && |
| 92 | >parents.actual && |
| 93 | i=1 && |
| 94 | while test $i -le $# |
| 95 | do |
| 96 | git rev-parse HEAD^$i >>parents.actual && |
| 97 | i=$(expr $i + 1) || |
| 98 | return 1 |
| 99 | done && |
| 100 | test_must_fail git rev-parse --verify "HEAD^$i" && |
| 101 | test_cmp parents.expected parents.actual |
| 102 | } |
| 103 | |
| 104 | verify_mergeheads () { |
| 105 | test_write_lines "$@" >mergehead.expected && |
| 106 | while read sha1 rest |
| 107 | do |
| 108 | git rev-parse $sha1 || return 1 |
| 109 | done <.git/MERGE_HEAD >mergehead.actual && |
| 110 | test_cmp mergehead.expected mergehead.actual |
| 111 | } |
| 112 | |
| 113 | verify_no_mergehead () { |
| 114 | ! test -e .git/MERGE_HEAD |
| 115 | } |
| 116 | |
| 117 | test_expect_success 'setup' ' |
| 118 | git add file && |
| 119 | test_tick && |
| 120 | git commit -m "commit 0" && |
| 121 | git tag c0 && |
| 122 | c0=$(git rev-parse HEAD) && |
| 123 | cp file.1 file && |
| 124 | git add file && |
| 125 | cp file.1 other && |
| 126 | git add other && |
| 127 | test_tick && |
| 128 | git commit -m "commit 1" && |
| 129 | git tag c1 && |
| 130 | c1=$(git rev-parse HEAD) && |
| 131 | git reset --hard "$c0" && |
| 132 | cp file.5 file && |
| 133 | git add file && |
| 134 | test_tick && |
| 135 | git commit -m "commit 2" && |
| 136 | git tag c2 && |
| 137 | c2=$(git rev-parse HEAD) && |
| 138 | git reset --hard "$c0" && |
| 139 | cp file.9y file && |
| 140 | git add file && |
| 141 | test_tick && |
| 142 | git commit -m "commit 7" && |
| 143 | git tag c7 && |
| 144 | git reset --hard "$c0" && |
| 145 | cp file.9 file && |
| 146 | git add file && |
| 147 | test_tick && |
| 148 | git commit -m "commit 3" && |
| 149 | git tag c3 && |
| 150 | c3=$(git rev-parse HEAD) && |
| 151 | git reset --hard "$c0" && |
| 152 | create_merge_msgs |
| 153 | ' |
| 154 | |
| 155 | test_debug 'git log --graph --decorate --oneline --all' |
| 156 | |
| 157 | test_expect_success 'test option parsing' ' |
| 158 | test_must_fail git merge -$ c1 && |
| 159 | test_must_fail git merge --no-such c1 && |
| 160 | test_must_fail git merge -s foobar c1 && |
| 161 | test_must_fail git merge -s=foobar c1 && |
| 162 | test_must_fail git merge -m && |
| 163 | test_must_fail git merge --abort foobar && |
| 164 | test_must_fail git merge --abort --quiet && |
| 165 | test_must_fail git merge --continue foobar && |
| 166 | test_must_fail git merge --continue --quiet && |
| 167 | test_must_fail git merge |
| 168 | ' |
| 169 | |
| 170 | test_expect_success 'merge -h with invalid index' ' |
| 171 | mkdir broken && |
| 172 | ( |
| 173 | cd broken && |
| 174 | git init && |
| 175 | >.git/index && |
| 176 | test_expect_code 129 git merge -h >usage |
| 177 | ) && |
| 178 | test_grep "[Uu]sage: git merge" broken/usage |
| 179 | ' |
| 180 | |
| 181 | test_expect_success 'reject non-strategy with a git-merge-foo name' ' |
| 182 | test_must_fail git merge -s index c1 |
| 183 | ' |
| 184 | |
| 185 | test_expect_success 'merge c0 with c1' ' |
| 186 | echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected && |
| 187 | |
| 188 | cat >expect <<-\EOF && |
| 189 | Updating FROM..TO |
| 190 | Fast-forward |
| 191 | file | 2 +- |
| 192 | other | 9 +++++++++ |
| 193 | 2 files changed, 10 insertions(+), 1 deletion(-) |
| 194 | create mode 100644 other |
| 195 | EOF |
| 196 | |
| 197 | git reset --hard c0 && |
| 198 | git merge c1 >out && |
| 199 | sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual && |
| 200 | test_cmp expect actual && |
| 201 | verify_merge file result.1 && |
| 202 | verify_head "$c1" && |
| 203 | |
| 204 | git reflog -1 >reflog.actual && |
| 205 | sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy && |
| 206 | test_cmp reflog.expected reflog.fuzzy |
| 207 | ' |
| 208 | |
| 209 | test_debug 'git log --graph --decorate --oneline --all' |
| 210 | |
| 211 | test_expect_success 'merge c0 with c1 with --ff-only' ' |
| 212 | git reset --hard c0 && |
| 213 | git merge --ff-only c1 && |
| 214 | git merge --ff-only HEAD c0 c1 && |
| 215 | verify_merge file result.1 && |
| 216 | verify_head "$c1" |
| 217 | ' |
| 218 | |
| 219 | test_expect_success 'the same merge with merge.stat=diffstat' ' |
| 220 | cat >expect <<-\EOF && |
| 221 | Updating FROM..TO |
| 222 | Fast-forward |
| 223 | file | 2 +- |
| 224 | other | 9 +++++++++ |
| 225 | 2 files changed, 10 insertions(+), 1 deletion(-) |
| 226 | create mode 100644 other |
| 227 | EOF |
| 228 | |
| 229 | git reset --hard c0 && |
| 230 | git -c merge.stat=diffstat merge c1 >out && |
| 231 | sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual && |
| 232 | test_cmp expect actual |
| 233 | ' |
| 234 | |
| 235 | test_expect_success 'the same merge with compact summary' ' |
| 236 | cat >expect <<-\EOF && |
| 237 | Updating FROM..TO |
| 238 | Fast-forward |
| 239 | file | 2 +- |
| 240 | other (new) | 9 +++++++++ |
| 241 | 2 files changed, 10 insertions(+), 1 deletion(-) |
| 242 | EOF |
| 243 | |
| 244 | git reset --hard c0 && |
| 245 | git merge --compact-summary c1 >out && |
| 246 | sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual && |
| 247 | test_cmp expect actual |
| 248 | ' |
| 249 | |
| 250 | test_expect_success 'the same merge with compact summary' ' |
| 251 | cat >expect <<-\EOF && |
| 252 | Updating FROM..TO |
| 253 | Fast-forward |
| 254 | file | 2 +- |
| 255 | other (new) | 9 +++++++++ |
| 256 | 2 files changed, 10 insertions(+), 1 deletion(-) |
| 257 | EOF |
| 258 | |
| 259 | git reset --hard c0 && |
| 260 | git merge --compact-summary c1 >out && |
| 261 | sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual && |
| 262 | test_cmp expect actual |
| 263 | ' |
| 264 | |
| 265 | test_expect_success 'the same merge with merge.stat=compact' ' |
| 266 | cat >expect <<-\EOF && |
| 267 | Updating FROM..TO |
| 268 | Fast-forward |
| 269 | file | 2 +- |
| 270 | other (new) | 9 +++++++++ |
| 271 | 2 files changed, 10 insertions(+), 1 deletion(-) |
| 272 | EOF |
| 273 | |
| 274 | git reset --hard c0 && |
| 275 | git -c merge.stat=compact merge c1 >out && |
| 276 | sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual && |
| 277 | test_cmp expect actual |
| 278 | ' |
| 279 | |
| 280 | test_debug 'git log --graph --decorate --oneline --all' |
| 281 | |
| 282 | test_expect_success 'merge from unborn branch' ' |
| 283 | git checkout -f main && |
| 284 | test_might_fail git branch -D kid && |
| 285 | |
| 286 | echo "OBJID HEAD@{0}: initial pull" >reflog.expected && |
| 287 | |
| 288 | git checkout --orphan kid && |
| 289 | test_when_finished "git checkout -f main" && |
| 290 | git rm -fr . && |
| 291 | test_tick && |
| 292 | git merge --ff-only c1 && |
| 293 | verify_merge file result.1 && |
| 294 | verify_head "$c1" && |
| 295 | |
| 296 | git reflog -1 >reflog.actual && |
| 297 | sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy && |
| 298 | test_cmp reflog.expected reflog.fuzzy |
| 299 | ' |
| 300 | |
| 301 | test_debug 'git log --graph --decorate --oneline --all' |
| 302 | |
| 303 | test_expect_success 'merge c1 with c2' ' |
| 304 | git reset --hard c1 && |
| 305 | test_tick && |
| 306 | git merge c2 && |
| 307 | verify_merge file result.1-5 msg.1-5 && |
| 308 | verify_parents $c1 $c2 |
| 309 | ' |
| 310 | |
| 311 | test_expect_success 'merge c1 with c2 when index.lock exists' ' |
| 312 | test_when_finished rm .git/index.lock && |
| 313 | git reset --hard c1 && |
| 314 | >.git/index.lock && |
| 315 | test_must_fail git merge c2 && |
| 316 | test_path_is_missing .git/MERGE_HEAD && |
| 317 | test_path_is_missing .git/MERGE_MODE && |
| 318 | test_path_is_missing .git/MERGE_MSG |
| 319 | ' |
| 320 | |
| 321 | test_expect_success 'merge --squash c3 with c7' ' |
| 322 | git reset --hard c3 && |
| 323 | test_must_fail git merge --squash c7 && |
| 324 | cat result.9z >file && |
| 325 | git commit --no-edit -a && |
| 326 | |
| 327 | cat >expect <<-EOF && |
| 328 | Squashed commit of the following: |
| 329 | |
| 330 | $(git show -s c7) |
| 331 | |
| 332 | # Conflicts: |
| 333 | # file |
| 334 | EOF |
| 335 | git cat-file commit HEAD >raw && |
| 336 | sed -e "1,/^$/d" raw >actual && |
| 337 | test_cmp expect actual |
| 338 | ' |
| 339 | |
| 340 | test_expect_success 'merge --squash --autostash conflict does not attempt to apply autostash' ' |
| 341 | git reset --hard c3 && |
| 342 | >unrelated && |
| 343 | git add unrelated && |
| 344 | test_must_fail git merge --squash c7 --autostash >out 2>err && |
| 345 | ! grep "Applying autostash resulted in conflicts." err && |
| 346 | grep "When finished, apply stashed changes with \`git stash pop\`" out |
| 347 | ' |
| 348 | |
| 349 | test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' ' |
| 350 | git config commit.cleanup scissors && |
| 351 | git reset --hard c3 && |
| 352 | test_must_fail git merge c7 && |
| 353 | cat result.9z >file && |
| 354 | git commit --no-edit -a && |
| 355 | |
| 356 | cat >expect <<-\EOF && |
| 357 | Merge tag '"'"'c7'"'"' |
| 358 | |
| 359 | # ------------------------ >8 ------------------------ |
| 360 | # Do not modify or remove the line above. |
| 361 | # Everything below it will be ignored. |
| 362 | # |
| 363 | # Conflicts: |
| 364 | # file |
| 365 | EOF |
| 366 | git cat-file commit HEAD >raw && |
| 367 | sed -e "1,/^$/d" raw >actual && |
| 368 | test_cmp expect actual |
| 369 | ' |
| 370 | |
| 371 | test_expect_success 'merge c3 with c7 with --squash commit.cleanup = scissors' ' |
| 372 | git config commit.cleanup scissors && |
| 373 | git reset --hard c3 && |
| 374 | test_must_fail git merge --squash c7 && |
| 375 | cat result.9z >file && |
| 376 | git commit --no-edit -a && |
| 377 | |
| 378 | cat >expect <<-EOF && |
| 379 | Squashed commit of the following: |
| 380 | |
| 381 | $(git show -s c7) |
| 382 | |
| 383 | # ------------------------ >8 ------------------------ |
| 384 | # Do not modify or remove the line above. |
| 385 | # Everything below it will be ignored. |
| 386 | # |
| 387 | # Conflicts: |
| 388 | # file |
| 389 | EOF |
| 390 | git cat-file commit HEAD >raw && |
| 391 | sed -e "1,/^$/d" raw >actual && |
| 392 | test_cmp expect actual |
| 393 | ' |
| 394 | |
| 395 | test_debug 'git log --graph --decorate --oneline --all' |
| 396 | |
| 397 | test_expect_success 'merge c1 with c2 and c3' ' |
| 398 | git reset --hard c1 && |
| 399 | test_tick && |
| 400 | git merge c2 c3 && |
| 401 | verify_merge file result.1-5-9 msg.1-5-9 && |
| 402 | verify_parents $c1 $c2 $c3 |
| 403 | ' |
| 404 | |
| 405 | test_debug 'git log --graph --decorate --oneline --all' |
| 406 | |
| 407 | test_expect_success 'merges with --ff-only' ' |
| 408 | git reset --hard c1 && |
| 409 | test_tick && |
| 410 | test_must_fail git merge --ff-only c2 && |
| 411 | test_must_fail git merge --ff-only c3 && |
| 412 | test_must_fail git merge --ff-only c2 c3 && |
| 413 | git reset --hard c0 && |
| 414 | git merge c3 && |
| 415 | verify_head $c3 |
| 416 | ' |
| 417 | |
| 418 | test_expect_success 'merges with merge.ff=only' ' |
| 419 | git reset --hard c1 && |
| 420 | test_tick && |
| 421 | test_config merge.ff "only" && |
| 422 | test_must_fail git merge c2 && |
| 423 | test_must_fail git merge c3 && |
| 424 | test_must_fail git merge c2 c3 && |
| 425 | git reset --hard c0 && |
| 426 | git merge c3 && |
| 427 | verify_head $c3 |
| 428 | ' |
| 429 | |
| 430 | test_expect_success 'merge c0 with c1 (no-commit)' ' |
| 431 | git reset --hard c0 && |
| 432 | git merge --no-commit c1 && |
| 433 | verify_merge file result.1 && |
| 434 | verify_head $c1 |
| 435 | ' |
| 436 | |
| 437 | test_debug 'git log --graph --decorate --oneline --all' |
| 438 | |
| 439 | test_expect_success 'merge c1 with c2 (no-commit)' ' |
| 440 | git reset --hard c1 && |
| 441 | git merge --no-commit c2 && |
| 442 | verify_merge file result.1-5 && |
| 443 | verify_head $c1 && |
| 444 | verify_mergeheads $c2 |
| 445 | ' |
| 446 | |
| 447 | test_debug 'git log --graph --decorate --oneline --all' |
| 448 | |
| 449 | test_expect_success 'merge c1 with c2 and c3 (no-commit)' ' |
| 450 | git reset --hard c1 && |
| 451 | git merge --no-commit c2 c3 && |
| 452 | verify_merge file result.1-5-9 && |
| 453 | verify_head $c1 && |
| 454 | verify_mergeheads $c2 $c3 |
| 455 | ' |
| 456 | |
| 457 | test_debug 'git log --graph --decorate --oneline --all' |
| 458 | |
| 459 | test_expect_success 'merge c0 with c1 (squash)' ' |
| 460 | git reset --hard c0 && |
| 461 | git merge --squash c1 && |
| 462 | verify_merge file result.1 && |
| 463 | verify_head $c0 && |
| 464 | verify_no_mergehead && |
| 465 | test_cmp squash.1 .git/SQUASH_MSG |
| 466 | ' |
| 467 | |
| 468 | test_debug 'git log --graph --decorate --oneline --all' |
| 469 | |
| 470 | test_expect_success 'merge c0 with c1 (squash, ff-only)' ' |
| 471 | git reset --hard c0 && |
| 472 | git merge --squash --ff-only c1 && |
| 473 | verify_merge file result.1 && |
| 474 | verify_head $c0 && |
| 475 | verify_no_mergehead && |
| 476 | test_cmp squash.1 .git/SQUASH_MSG |
| 477 | ' |
| 478 | |
| 479 | test_debug 'git log --graph --decorate --oneline --all' |
| 480 | |
| 481 | test_expect_success 'merge c1 with c2 (squash)' ' |
| 482 | git reset --hard c1 && |
| 483 | git merge --squash c2 && |
| 484 | verify_merge file result.1-5 && |
| 485 | verify_head $c1 && |
| 486 | verify_no_mergehead && |
| 487 | test_cmp squash.1-5 .git/SQUASH_MSG |
| 488 | ' |
| 489 | |
| 490 | test_debug 'git log --graph --decorate --oneline --all' |
| 491 | |
| 492 | test_expect_success 'unsuccessful merge of c1 with c2 (squash, ff-only)' ' |
| 493 | git reset --hard c1 && |
| 494 | test_must_fail git merge --squash --ff-only c2 |
| 495 | ' |
| 496 | |
| 497 | test_debug 'git log --graph --decorate --oneline --all' |
| 498 | |
| 499 | test_expect_success 'merge c1 with c2 and c3 (squash)' ' |
| 500 | git reset --hard c1 && |
| 501 | git merge --squash c2 c3 && |
| 502 | verify_merge file result.1-5-9 && |
| 503 | verify_head $c1 && |
| 504 | verify_no_mergehead && |
| 505 | test_cmp squash.1-5-9 .git/SQUASH_MSG |
| 506 | ' |
| 507 | |
| 508 | test_debug 'git log --graph --decorate --oneline --all' |
| 509 | |
| 510 | test_expect_success 'merge c1 with c2 (no-commit in config)' ' |
| 511 | git reset --hard c1 && |
| 512 | test_config branch.main.mergeoptions "--no-commit" && |
| 513 | git merge c2 && |
| 514 | verify_merge file result.1-5 && |
| 515 | verify_head $c1 && |
| 516 | verify_mergeheads $c2 |
| 517 | ' |
| 518 | |
| 519 | test_debug 'git log --graph --decorate --oneline --all' |
| 520 | |
| 521 | test_expect_success 'merge c1 with c2 (log in config)' ' |
| 522 | git reset --hard c1 && |
| 523 | git merge --log c2 && |
| 524 | git show -s --pretty=tformat:%s%n%b >expect && |
| 525 | |
| 526 | test_config branch.main.mergeoptions "--log" && |
| 527 | git reset --hard c1 && |
| 528 | git merge c2 && |
| 529 | git show -s --pretty=tformat:%s%n%b >actual && |
| 530 | |
| 531 | test_cmp expect actual |
| 532 | ' |
| 533 | |
| 534 | test_expect_success 'merge c1 with c2 (log in config gets overridden)' ' |
| 535 | git reset --hard c1 && |
| 536 | git merge c2 && |
| 537 | git show -s --pretty=tformat:%s%n%b >expect && |
| 538 | |
| 539 | test_config branch.main.mergeoptions "--no-log" && |
| 540 | test_config merge.log "true" && |
| 541 | git reset --hard c1 && |
| 542 | git merge c2 && |
| 543 | git show -s --pretty=tformat:%s%n%b >actual && |
| 544 | |
| 545 | test_cmp expect actual |
| 546 | ' |
| 547 | |
| 548 | test_expect_success 'merge c1 with c2 (squash in config)' ' |
| 549 | git reset --hard c1 && |
| 550 | test_config branch.main.mergeoptions "--squash" && |
| 551 | git merge c2 && |
| 552 | verify_merge file result.1-5 && |
| 553 | verify_head $c1 && |
| 554 | verify_no_mergehead && |
| 555 | test_cmp squash.1-5 .git/SQUASH_MSG |
| 556 | ' |
| 557 | |
| 558 | test_debug 'git log --graph --decorate --oneline --all' |
| 559 | |
| 560 | test_expect_success 'override config option -n with --summary' ' |
| 561 | git reset --hard c1 && |
| 562 | test_config branch.main.mergeoptions "-n" && |
| 563 | test_tick && |
| 564 | git merge --summary c2 >diffstat.txt && |
| 565 | verify_merge file result.1-5 msg.1-5 && |
| 566 | verify_parents $c1 $c2 && |
| 567 | if ! grep "^ file | *2 +-$" diffstat.txt |
| 568 | then |
| 569 | echo "[OOPS] diffstat was not generated with --summary" |
| 570 | false |
| 571 | fi |
| 572 | ' |
| 573 | |
| 574 | test_expect_success 'override config option -n with --stat' ' |
| 575 | git reset --hard c1 && |
| 576 | test_config branch.main.mergeoptions "-n" && |
| 577 | test_tick && |
| 578 | git merge --stat c2 >diffstat.txt && |
| 579 | verify_merge file result.1-5 msg.1-5 && |
| 580 | verify_parents $c1 $c2 && |
| 581 | if ! grep "^ file | *2 +-$" diffstat.txt |
| 582 | then |
| 583 | echo "[OOPS] diffstat was not generated with --stat" |
| 584 | false |
| 585 | fi |
| 586 | ' |
| 587 | |
| 588 | test_debug 'git log --graph --decorate --oneline --all' |
| 589 | |
| 590 | test_expect_success 'override config option --stat' ' |
| 591 | git reset --hard c1 && |
| 592 | test_config branch.main.mergeoptions "--stat" && |
| 593 | test_tick && |
| 594 | git merge -n c2 >diffstat.txt && |
| 595 | verify_merge file result.1-5 msg.1-5 && |
| 596 | verify_parents $c1 $c2 && |
| 597 | if grep "^ file | *2 +-$" diffstat.txt |
| 598 | then |
| 599 | echo "[OOPS] diffstat was generated" |
| 600 | false |
| 601 | fi |
| 602 | ' |
| 603 | |
| 604 | test_debug 'git log --graph --decorate --oneline --all' |
| 605 | |
| 606 | test_expect_success 'merge c1 with c2 (override --no-commit)' ' |
| 607 | git reset --hard c1 && |
| 608 | test_config branch.main.mergeoptions "--no-commit" && |
| 609 | test_tick && |
| 610 | git merge --commit c2 && |
| 611 | verify_merge file result.1-5 msg.1-5 && |
| 612 | verify_parents $c1 $c2 |
| 613 | ' |
| 614 | |
| 615 | test_debug 'git log --graph --decorate --oneline --all' |
| 616 | |
| 617 | test_expect_success 'merge c1 with c2 (override --squash)' ' |
| 618 | git reset --hard c1 && |
| 619 | test_config branch.main.mergeoptions "--squash" && |
| 620 | test_tick && |
| 621 | git merge --no-squash c2 && |
| 622 | verify_merge file result.1-5 msg.1-5 && |
| 623 | verify_parents $c1 $c2 |
| 624 | ' |
| 625 | |
| 626 | test_debug 'git log --graph --decorate --oneline --all' |
| 627 | |
| 628 | test_expect_success 'merge c0 with c1 (no-ff)' ' |
| 629 | git reset --hard c0 && |
| 630 | test_tick && |
| 631 | git merge --no-ff c1 && |
| 632 | verify_merge file result.1 && |
| 633 | verify_parents $c0 $c1 |
| 634 | ' |
| 635 | |
| 636 | test_debug 'git log --graph --decorate --oneline --all' |
| 637 | |
| 638 | test_expect_success 'merge c0 with c1 (merge.ff=false)' ' |
| 639 | git reset --hard c0 && |
| 640 | test_config merge.ff "false" && |
| 641 | test_tick && |
| 642 | git merge c1 && |
| 643 | verify_merge file result.1 && |
| 644 | verify_parents $c0 $c1 |
| 645 | ' |
| 646 | test_debug 'git log --graph --decorate --oneline --all' |
| 647 | |
| 648 | test_expect_success 'combine branch.main.mergeoptions with merge.ff' ' |
| 649 | git reset --hard c0 && |
| 650 | test_config branch.main.mergeoptions "--ff" && |
| 651 | test_config merge.ff "false" && |
| 652 | test_tick && |
| 653 | git merge c1 && |
| 654 | verify_merge file result.1 && |
| 655 | verify_parents "$c0" |
| 656 | ' |
| 657 | |
| 658 | test_expect_success 'tolerate unknown values for merge.ff' ' |
| 659 | git reset --hard c0 && |
| 660 | test_config merge.ff "something-new" && |
| 661 | test_tick && |
| 662 | git merge c1 2>message && |
| 663 | verify_head "$c1" && |
| 664 | test_must_be_empty message |
| 665 | ' |
| 666 | |
| 667 | test_expect_success 'combining --squash and --no-ff is refused' ' |
| 668 | git reset --hard c0 && |
| 669 | test_must_fail git merge --squash --no-ff c1 && |
| 670 | test_must_fail git merge --no-ff --squash c1 |
| 671 | ' |
| 672 | |
| 673 | test_expect_success 'combining --squash and --commit is refused' ' |
| 674 | git reset --hard c0 && |
| 675 | test_must_fail git merge --squash --commit c1 && |
| 676 | test_must_fail git merge --commit --squash c1 |
| 677 | ' |
| 678 | |
| 679 | test_expect_success 'option --ff-only overwrites --no-ff' ' |
| 680 | git merge --no-ff --ff-only c1 && |
| 681 | test_must_fail git merge --no-ff --ff-only c2 |
| 682 | ' |
| 683 | |
| 684 | test_expect_success 'option --no-ff overrides merge.ff=only config' ' |
| 685 | git reset --hard c0 && |
| 686 | test_config merge.ff only && |
| 687 | git merge --no-ff c1 |
| 688 | ' |
| 689 | |
| 690 | test_expect_success 'merge c0 with c1 (ff overrides no-ff)' ' |
| 691 | git reset --hard c0 && |
| 692 | test_config branch.main.mergeoptions "--no-ff" && |
| 693 | git merge --ff c1 && |
| 694 | verify_merge file result.1 && |
| 695 | verify_head $c1 |
| 696 | ' |
| 697 | |
| 698 | test_expect_success 'merge log message' ' |
| 699 | git reset --hard c0 && |
| 700 | git merge --no-log c2 && |
| 701 | git show -s --pretty=format:%b HEAD >msg.act && |
| 702 | test_must_be_empty msg.act && |
| 703 | |
| 704 | git reset --hard c0 && |
| 705 | test_config branch.main.mergeoptions "--no-ff" && |
| 706 | git merge --no-log c2 && |
| 707 | git show -s --pretty=format:%b HEAD >msg.act && |
| 708 | test_must_be_empty msg.act && |
| 709 | |
| 710 | git merge --log c3 && |
| 711 | git show -s --pretty=format:%b HEAD >msg.act && |
| 712 | test_cmp msg.log msg.act && |
| 713 | |
| 714 | git reset --hard HEAD^ && |
| 715 | test_config merge.log "yes" && |
| 716 | git merge c3 && |
| 717 | git show -s --pretty=format:%b HEAD >msg.act && |
| 718 | test_cmp msg.log msg.act |
| 719 | ' |
| 720 | |
| 721 | test_debug 'git log --graph --decorate --oneline --all' |
| 722 | |
| 723 | test_expect_success 'merge c1 with c0, c2, c0, and c1' ' |
| 724 | git reset --hard c1 && |
| 725 | test_tick && |
| 726 | git merge c0 c2 c0 c1 && |
| 727 | verify_merge file result.1-5 && |
| 728 | verify_parents $c1 $c2 |
| 729 | ' |
| 730 | |
| 731 | test_debug 'git log --graph --decorate --oneline --all' |
| 732 | |
| 733 | test_expect_success 'merge c1 with c0, c2, c0, and c1' ' |
| 734 | git reset --hard c1 && |
| 735 | test_tick && |
| 736 | git merge c0 c2 c0 c1 && |
| 737 | verify_merge file result.1-5 && |
| 738 | verify_parents $c1 $c2 |
| 739 | ' |
| 740 | |
| 741 | test_debug 'git log --graph --decorate --oneline --all' |
| 742 | |
| 743 | test_expect_success 'merge c1 with c1 and c2' ' |
| 744 | git reset --hard c1 && |
| 745 | test_tick && |
| 746 | git merge c1 c2 && |
| 747 | verify_merge file result.1-5 && |
| 748 | verify_parents $c1 $c2 |
| 749 | ' |
| 750 | |
| 751 | test_debug 'git log --graph --decorate --oneline --all' |
| 752 | |
| 753 | test_expect_success 'merge fast-forward in a dirty tree' ' |
| 754 | git reset --hard c0 && |
| 755 | mv file file1 && |
| 756 | cat file1 >file && |
| 757 | rm -f file1 && |
| 758 | git merge c2 |
| 759 | ' |
| 760 | |
| 761 | test_debug 'git log --graph --decorate --oneline --all' |
| 762 | |
| 763 | test_expect_success 'in-index merge' ' |
| 764 | git reset --hard c0 && |
| 765 | git merge --no-ff -s resolve c1 >out && |
| 766 | test_grep "Wonderful." out && |
| 767 | verify_parents $c0 $c1 |
| 768 | ' |
| 769 | |
| 770 | test_debug 'git log --graph --decorate --oneline --all' |
| 771 | |
| 772 | test_expect_success 'refresh the index before merging' ' |
| 773 | git reset --hard c1 && |
| 774 | cp file file.n && mv -f file.n file && |
| 775 | git merge c3 |
| 776 | ' |
| 777 | |
| 778 | test_expect_success 'merge with --autostash' ' |
| 779 | git reset --hard c1 && |
| 780 | git merge-file file file.orig file.9 && |
| 781 | git merge --autostash c2 2>err && |
| 782 | test_grep "Applied autostash." err && |
| 783 | git show HEAD:file >merge-result && |
| 784 | test_cmp result.1-5 merge-result && |
| 785 | test_cmp result.1-5-9 file |
| 786 | ' |
| 787 | |
| 788 | test_expect_success 'merge with merge.autoStash' ' |
| 789 | test_config merge.autoStash true && |
| 790 | git reset --hard c1 && |
| 791 | git merge-file file file.orig file.9 && |
| 792 | git merge c2 2>err && |
| 793 | test_grep "Applied autostash." err && |
| 794 | git show HEAD:file >merge-result && |
| 795 | test_cmp result.1-5 merge-result && |
| 796 | test_cmp result.1-5-9 file |
| 797 | ' |
| 798 | |
| 799 | test_expect_success 'fast-forward merge with --autostash' ' |
| 800 | git reset --hard c0 && |
| 801 | git merge-file file file.orig file.5 && |
| 802 | git merge --autostash c1 2>err && |
| 803 | test_grep "Applied autostash." err && |
| 804 | test_cmp result.1-5 file |
| 805 | ' |
| 806 | |
| 807 | test_expect_success 'failed fast-forward merge with --autostash' ' |
| 808 | git reset --hard c0 && |
| 809 | git merge-file file file.orig file.5 && |
| 810 | cp file.5 other && |
| 811 | test_when_finished "rm other" && |
| 812 | test_must_fail git merge --autostash c1 2>err && |
| 813 | test_grep "Applied autostash." err && |
| 814 | test_cmp file.5 file |
| 815 | ' |
| 816 | |
| 817 | test_expect_success 'octopus merge with --autostash' ' |
| 818 | git reset --hard c1 && |
| 819 | git merge-file file file.orig file.3 && |
| 820 | git merge --autostash c2 c3 2>err && |
| 821 | test_grep "Applied autostash." err && |
| 822 | git show HEAD:file >merge-result && |
| 823 | test_cmp result.1-5-9 merge-result && |
| 824 | test_cmp result.1-3-5-9 file |
| 825 | ' |
| 826 | |
| 827 | test_expect_success 'failed merge (exit 2) with --autostash' ' |
| 828 | git reset --hard c1 && |
| 829 | git merge-file file file.orig file.5 && |
| 830 | test_must_fail git merge -s recursive --autostash c2 c3 2>err && |
| 831 | test_grep "Applied autostash." err && |
| 832 | test_cmp result.1-5 file |
| 833 | ' |
| 834 | |
| 835 | test_expect_success 'conflicted merge with --autostash, --abort restores stash' ' |
| 836 | git reset --hard c3 && |
| 837 | cp file.1 file && |
| 838 | test_must_fail git merge --autostash c7 && |
| 839 | git merge --abort 2>err && |
| 840 | test_grep "Applied autostash." err && |
| 841 | test_cmp file.1 file |
| 842 | ' |
| 843 | |
| 844 | test_expect_success 'completed merge (git commit) with --no-commit and --autostash' ' |
| 845 | git reset --hard c1 && |
| 846 | git merge-file file file.orig file.9 && |
| 847 | git diff >expect && |
| 848 | git merge --no-commit --autostash c2 && |
| 849 | git stash show -p MERGE_AUTOSTASH >actual && |
| 850 | test_cmp expect actual && |
| 851 | git commit 2>err && |
| 852 | test_grep "Applied autostash." err && |
| 853 | git show HEAD:file >merge-result && |
| 854 | test_cmp result.1-5 merge-result && |
| 855 | test_cmp result.1-5-9 file |
| 856 | ' |
| 857 | |
| 858 | test_expect_success 'completed merge (git merge --continue) with --no-commit and --autostash' ' |
| 859 | git reset --hard c1 && |
| 860 | git merge-file file file.orig file.9 && |
| 861 | git diff >expect && |
| 862 | git merge --no-commit --autostash c2 && |
| 863 | git stash show -p MERGE_AUTOSTASH >actual && |
| 864 | test_cmp expect actual && |
| 865 | git merge --continue 2>err && |
| 866 | test_grep "Applied autostash." err && |
| 867 | git show HEAD:file >merge-result && |
| 868 | test_cmp result.1-5 merge-result && |
| 869 | test_cmp result.1-5-9 file |
| 870 | ' |
| 871 | |
| 872 | test_expect_success 'aborted merge (merge --abort) with --no-commit and --autostash' ' |
| 873 | git reset --hard c1 && |
| 874 | git merge-file file file.orig file.9 && |
| 875 | git diff >expect && |
| 876 | git merge --no-commit --autostash c2 && |
| 877 | git stash show -p MERGE_AUTOSTASH >actual && |
| 878 | test_cmp expect actual && |
| 879 | git merge --abort 2>err && |
| 880 | test_grep "Applied autostash." err && |
| 881 | git diff >actual && |
| 882 | test_cmp expect actual |
| 883 | ' |
| 884 | |
| 885 | test_expect_success 'aborted merge (reset --hard) with --no-commit and --autostash' ' |
| 886 | git reset --hard c1 && |
| 887 | git merge-file file file.orig file.9 && |
| 888 | git diff >expect && |
| 889 | git merge --no-commit --autostash c2 && |
| 890 | git stash show -p MERGE_AUTOSTASH >actual && |
| 891 | test_cmp expect actual && |
| 892 | git reset --hard 2>err && |
| 893 | test_grep "Autostash exists; creating a new stash entry." err && |
| 894 | git diff --exit-code |
| 895 | ' |
| 896 | |
| 897 | test_expect_success 'quit merge with --no-commit and --autostash' ' |
| 898 | git reset --hard c1 && |
| 899 | git merge-file file file.orig file.9 && |
| 900 | git diff >expect && |
| 901 | git merge --no-commit --autostash c2 && |
| 902 | git stash show -p MERGE_AUTOSTASH >actual && |
| 903 | test_cmp expect actual && |
| 904 | git diff HEAD >expect && |
| 905 | git merge --quit 2>err && |
| 906 | test_grep "Autostash exists; creating a new stash entry." err && |
| 907 | git diff HEAD >actual && |
| 908 | test_cmp expect actual |
| 909 | ' |
| 910 | |
| 911 | test_expect_success 'merge with conflicted --autostash changes' ' |
| 912 | git reset --hard c1 && |
| 913 | git merge-file file file.orig file.9y && |
| 914 | git diff >expect && |
| 915 | test_when_finished "test_might_fail git stash drop" && |
| 916 | git merge --autostash c3 2>err && |
| 917 | test_grep "applying them" err && |
| 918 | test_grep "resulted in conflicts" err && |
| 919 | git show HEAD:file >merge-result && |
| 920 | test_cmp result.1-9 merge-result && |
| 921 | git stash show -p >actual && |
| 922 | test_cmp expect actual |
| 923 | ' |
| 924 | |
| 925 | cat >expected.branch <<\EOF |
| 926 | Merge branch 'c5-branch' (early part) |
| 927 | EOF |
| 928 | cat >expected.tag <<\EOF |
| 929 | Merge commit 'c5~1' |
| 930 | EOF |
| 931 | |
| 932 | test_expect_success 'merge early part of c2' ' |
| 933 | git reset --hard c3 && |
| 934 | echo c4 >c4.c && |
| 935 | git add c4.c && |
| 936 | git commit -m c4 && |
| 937 | git tag c4 && |
| 938 | echo c5 >c5.c && |
| 939 | git add c5.c && |
| 940 | git commit -m c5 && |
| 941 | git tag c5 && |
| 942 | git reset --hard c3 && |
| 943 | echo c6 >c6.c && |
| 944 | git add c6.c && |
| 945 | git commit -m c6 && |
| 946 | git tag c6 && |
| 947 | git branch -f c5-branch c5 && |
| 948 | git merge c5-branch~1 && |
| 949 | git show -s --pretty=tformat:%s HEAD >actual.branch && |
| 950 | git reset --keep HEAD^ && |
| 951 | git merge c5~1 && |
| 952 | git show -s --pretty=tformat:%s HEAD >actual.tag && |
| 953 | test_cmp expected.branch actual.branch && |
| 954 | test_cmp expected.tag actual.tag |
| 955 | ' |
| 956 | |
| 957 | test_debug 'git log --graph --decorate --oneline --all' |
| 958 | |
| 959 | test_expect_success 'merge --no-ff --no-commit && commit' ' |
| 960 | git reset --hard c0 && |
| 961 | git merge --no-ff --no-commit c1 && |
| 962 | EDITOR=: git commit && |
| 963 | verify_parents $c0 $c1 |
| 964 | ' |
| 965 | |
| 966 | test_debug 'git log --graph --decorate --oneline --all' |
| 967 | |
| 968 | test_expect_success 'amending no-ff merge commit' ' |
| 969 | EDITOR=: git commit --amend && |
| 970 | verify_parents $c0 $c1 |
| 971 | ' |
| 972 | |
| 973 | test_debug 'git log --graph --decorate --oneline --all' |
| 974 | |
| 975 | cat >editor <<\EOF |
| 976 | #!/bin/sh |
| 977 | # Add a new message string that was not in the template |
| 978 | ( |
| 979 | echo "Merge work done on the side branch c1" |
| 980 | echo |
| 981 | cat "$1" |
| 982 | ) >"$1.tmp" && mv "$1.tmp" "$1" |
| 983 | # strip comments and blank lines from end of message |
| 984 | sed -e '/^#/d' "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' >expected |
| 985 | EOF |
| 986 | chmod 755 editor |
| 987 | |
| 988 | test_expect_success 'merge --no-ff --edit' ' |
| 989 | git reset --hard c0 && |
| 990 | EDITOR=./editor git merge --no-ff --edit c1 && |
| 991 | verify_parents $c0 $c1 && |
| 992 | git cat-file commit HEAD >raw && |
| 993 | grep "work done on the side branch" raw && |
| 994 | sed "1,/^$/d" >actual raw && |
| 995 | test_cmp expected actual |
| 996 | ' |
| 997 | |
| 998 | test_expect_success 'merge annotated/signed tag w/o tracking' ' |
| 999 | test_when_finished "rm -rf dst; git tag -d anno1" && |
| 1000 | git tag -a -m "anno c1" anno1 c1 && |
| 1001 | git init dst && |
| 1002 | git rev-parse c1 >dst/expect && |
| 1003 | ( |
| 1004 | # c0 fast-forwards to c1 but because this repository |
| 1005 | # is not a "downstream" whose refs/tags follows along |
| 1006 | # tag from the "upstream", this pull defaults to --no-ff |
| 1007 | cd dst && |
| 1008 | git pull .. c0 && |
| 1009 | git pull .. anno1 && |
| 1010 | git rev-parse HEAD^2 >actual && |
| 1011 | test_cmp expect actual |
| 1012 | ) |
| 1013 | ' |
| 1014 | |
| 1015 | test_expect_success 'merge annotated/signed tag w/ tracking' ' |
| 1016 | test_when_finished "rm -rf dst; git tag -d anno1" && |
| 1017 | git tag -a -m "anno c1" anno1 c1 && |
| 1018 | git init dst && |
| 1019 | git rev-parse c1 >dst/expect && |
| 1020 | ( |
| 1021 | # c0 fast-forwards to c1 and because this repository |
| 1022 | # is a "downstream" whose refs/tags follows along |
| 1023 | # tag from the "upstream", this pull defaults to --ff |
| 1024 | cd dst && |
| 1025 | git remote add origin .. && |
| 1026 | git pull origin c0 && |
| 1027 | git fetch origin && |
| 1028 | git merge anno1 && |
| 1029 | git rev-parse HEAD >actual && |
| 1030 | test_cmp expect actual |
| 1031 | ) |
| 1032 | ' |
| 1033 | |
| 1034 | test_expect_success GPG 'merge --ff-only tag' ' |
| 1035 | git reset --hard c0 && |
| 1036 | git commit --allow-empty -m "A newer commit" && |
| 1037 | git tag -s -m "A newer commit" signed && |
| 1038 | git reset --hard c0 && |
| 1039 | |
| 1040 | git merge --ff-only signed && |
| 1041 | git rev-parse signed^0 >expect && |
| 1042 | git rev-parse HEAD >actual && |
| 1043 | test_cmp expect actual |
| 1044 | ' |
| 1045 | |
| 1046 | test_expect_success GPG 'merge --no-edit tag should skip editor' ' |
| 1047 | git reset --hard c0 && |
| 1048 | git commit --allow-empty -m "A newer commit" && |
| 1049 | git tag -f -s -m "A newer commit" signed && |
| 1050 | git reset --hard c0 && |
| 1051 | |
| 1052 | EDITOR=false git merge --no-edit --no-ff signed && |
| 1053 | git rev-parse signed^0 >expect && |
| 1054 | git rev-parse HEAD^2 >actual && |
| 1055 | test_cmp expect actual |
| 1056 | ' |
| 1057 | |
| 1058 | test_expect_success 'set up mod-256 conflict scenario' ' |
| 1059 | # 256 near-identical stanzas... |
| 1060 | for i in $(test_seq 1 256); do |
| 1061 | for j in 1 2 3 4 5; do |
| 1062 | echo $i-$j || return 1 |
| 1063 | done |
| 1064 | done >file && |
| 1065 | git add file && |
| 1066 | git commit -m base && |
| 1067 | |
| 1068 | # one side changes the first line of each to "main" |
| 1069 | sed s/-1/-main/ file >tmp && |
| 1070 | mv tmp file && |
| 1071 | git commit -am main && |
| 1072 | |
| 1073 | # and the other to "side"; merging the two will |
| 1074 | # yield 256 separate conflicts |
| 1075 | git checkout -b side HEAD^ && |
| 1076 | sed s/-1/-side/ file >tmp && |
| 1077 | mv tmp file && |
| 1078 | git commit -am side |
| 1079 | ' |
| 1080 | |
| 1081 | test_expect_success 'merge detects mod-256 conflicts (recursive)' ' |
| 1082 | git reset --hard && |
| 1083 | test_must_fail git merge -s recursive main |
| 1084 | ' |
| 1085 | |
| 1086 | test_expect_success 'merge detects mod-256 conflicts (resolve)' ' |
| 1087 | git reset --hard && |
| 1088 | test_must_fail git merge -s resolve main |
| 1089 | ' |
| 1090 | |
| 1091 | test_expect_success 'merge nothing into void' ' |
| 1092 | git init void && |
| 1093 | ( |
| 1094 | cd void && |
| 1095 | git remote add up .. && |
| 1096 | git fetch up && |
| 1097 | test_must_fail git merge FETCH_HEAD |
| 1098 | ) |
| 1099 | ' |
| 1100 | |
| 1101 | test_expect_success 'merge can be completed with --continue' ' |
| 1102 | git reset --hard c0 && |
| 1103 | git merge --no-ff --no-commit c1 && |
| 1104 | git merge --continue && |
| 1105 | verify_parents $c0 $c1 |
| 1106 | ' |
| 1107 | |
| 1108 | write_script .git/FAKE_EDITOR <<EOF |
| 1109 | # kill -TERM command added below. |
| 1110 | EOF |
| 1111 | |
| 1112 | test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' ' |
| 1113 | git reset --hard c0 && |
| 1114 | ! "$SHELL_PATH" -c '\'' |
| 1115 | echo kill -TERM $$ >>.git/FAKE_EDITOR |
| 1116 | GIT_EDITOR=.git/FAKE_EDITOR |
| 1117 | export GIT_EDITOR |
| 1118 | exec git merge --no-ff --edit c1'\'' && |
| 1119 | git merge --continue && |
| 1120 | verify_parents $c0 $c1 |
| 1121 | ' |
| 1122 | |
| 1123 | test_expect_success 'merge --quit' ' |
| 1124 | git init merge-quit && |
| 1125 | ( |
| 1126 | cd merge-quit && |
| 1127 | test_commit base && |
| 1128 | echo one >>base.t && |
| 1129 | git commit -am one && |
| 1130 | git branch one && |
| 1131 | git checkout base && |
| 1132 | echo two >>base.t && |
| 1133 | git commit -am two && |
| 1134 | test_must_fail git -c rerere.enabled=true merge one && |
| 1135 | test_path_is_file .git/MERGE_HEAD && |
| 1136 | test_path_is_file .git/MERGE_MODE && |
| 1137 | test_path_is_file .git/MERGE_MSG && |
| 1138 | git rerere status >rerere.before && |
| 1139 | git merge --quit && |
| 1140 | test_path_is_missing .git/MERGE_HEAD && |
| 1141 | test_path_is_missing .git/MERGE_MODE && |
| 1142 | test_path_is_missing .git/MERGE_MSG && |
| 1143 | git rerere status >rerere.after && |
| 1144 | test_must_be_empty rerere.after && |
| 1145 | ! test_cmp rerere.after rerere.before |
| 1146 | ) |
| 1147 | ' |
| 1148 | |
| 1149 | test_expect_success 'merge suggests matching remote refname' ' |
| 1150 | git commit --allow-empty -m not-local && |
| 1151 | git update-ref refs/remotes/origin/not-local HEAD && |
| 1152 | git reset --hard HEAD^ && |
| 1153 | |
| 1154 | # This is white-box testing hackery; we happen to know |
| 1155 | # that reading packed refs is more picky about the memory |
| 1156 | # ownership of strings we pass to for_each_ref() callbacks. |
| 1157 | git pack-refs --all --prune && |
| 1158 | |
| 1159 | test_must_fail git merge not-local 2>stderr && |
| 1160 | grep origin/not-local stderr |
| 1161 | ' |
| 1162 | |
| 1163 | test_expect_success 'suggested names are not ambiguous' ' |
| 1164 | git update-ref refs/heads/origin/not-local HEAD && |
| 1165 | test_must_fail git merge not-local 2>stderr && |
| 1166 | grep remotes/origin/not-local stderr |
| 1167 | ' |
| 1168 | |
| 1169 | test_done |