| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='pulling into void' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | modify () { |
| 11 | sed -e "$1" "$2" >"$2.x" && |
| 12 | mv "$2.x" "$2" |
| 13 | } |
| 14 | |
| 15 | test_pull_autostash () { |
| 16 | expect_parent_num="$1" && |
| 17 | shift && |
| 18 | git reset --hard before-rebase && |
| 19 | echo dirty >new_file && |
| 20 | git add new_file && |
| 21 | git pull "$@" . copy && |
| 22 | test_cmp_rev HEAD^"$expect_parent_num" copy && |
| 23 | echo dirty >expect && |
| 24 | test_cmp expect new_file && |
| 25 | echo "modified again" >expect && |
| 26 | test_cmp expect file |
| 27 | } |
| 28 | |
| 29 | test_pull_autostash_fail () { |
| 30 | git reset --hard before-rebase && |
| 31 | echo dirty >new_file && |
| 32 | git add new_file && |
| 33 | test_must_fail git pull "$@" . copy 2>err && |
| 34 | test_grep -E "uncommitted changes.|overwritten by merge:" err |
| 35 | } |
| 36 | |
| 37 | test_expect_success setup ' |
| 38 | echo file >file && |
| 39 | git add file && |
| 40 | git commit -a -m original |
| 41 | ' |
| 42 | |
| 43 | test_expect_success 'pulling into void' ' |
| 44 | git init cloned && |
| 45 | ( |
| 46 | cd cloned && |
| 47 | git pull .. |
| 48 | ) && |
| 49 | test_path_is_file file && |
| 50 | test_path_is_file cloned/file && |
| 51 | test_cmp file cloned/file |
| 52 | ' |
| 53 | |
| 54 | test_expect_success 'pulling into void using main:main' ' |
| 55 | git init cloned-uho && |
| 56 | ( |
| 57 | cd cloned-uho && |
| 58 | git pull .. main:main |
| 59 | ) && |
| 60 | test_path_is_file file && |
| 61 | test_path_is_file cloned-uho/file && |
| 62 | test_cmp file cloned-uho/file |
| 63 | ' |
| 64 | |
| 65 | test_expect_success 'pulling into void does not overwrite untracked files' ' |
| 66 | git init cloned-untracked && |
| 67 | ( |
| 68 | cd cloned-untracked && |
| 69 | echo untracked >file && |
| 70 | test_must_fail git pull .. main && |
| 71 | echo untracked >expect && |
| 72 | test_cmp expect file |
| 73 | ) |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 'pulling into void does not overwrite staged files' ' |
| 77 | git init cloned-staged-colliding && |
| 78 | ( |
| 79 | cd cloned-staged-colliding && |
| 80 | echo "alternate content" >file && |
| 81 | git add file && |
| 82 | test_must_fail git pull .. main && |
| 83 | echo "alternate content" >expect && |
| 84 | test_cmp expect file && |
| 85 | git cat-file blob :file >file.index && |
| 86 | test_cmp expect file.index |
| 87 | ) |
| 88 | ' |
| 89 | |
| 90 | test_expect_success 'pulling into void does not remove new staged files' ' |
| 91 | git init cloned-staged-new && |
| 92 | ( |
| 93 | cd cloned-staged-new && |
| 94 | echo "new tracked file" >newfile && |
| 95 | git add newfile && |
| 96 | git pull .. main && |
| 97 | echo "new tracked file" >expect && |
| 98 | test_cmp expect newfile && |
| 99 | git cat-file blob :newfile >newfile.index && |
| 100 | test_cmp expect newfile.index |
| 101 | ) |
| 102 | ' |
| 103 | |
| 104 | test_expect_success 'pulling into void must not create an octopus' ' |
| 105 | git init cloned-octopus && |
| 106 | ( |
| 107 | cd cloned-octopus && |
| 108 | test_must_fail git pull .. main main && |
| 109 | test_path_is_missing file |
| 110 | ) |
| 111 | ' |
| 112 | |
| 113 | test_expect_success 'test . as a remote' ' |
| 114 | git branch copy main && |
| 115 | git config branch.copy.remote . && |
| 116 | git config branch.copy.merge refs/heads/main && |
| 117 | echo updated >file && |
| 118 | git commit -a -m updated && |
| 119 | git checkout copy && |
| 120 | echo file >expect && |
| 121 | test_cmp expect file && |
| 122 | git pull && |
| 123 | echo updated >expect && |
| 124 | test_cmp expect file && |
| 125 | git reflog -1 >reflog.actual && |
| 126 | sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && |
| 127 | echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected && |
| 128 | test_cmp reflog.expected reflog.fuzzy |
| 129 | ' |
| 130 | |
| 131 | test_expect_success 'the default remote . should not break explicit pull' ' |
| 132 | git checkout -b second main^ && |
| 133 | echo modified >file && |
| 134 | git commit -a -m modified && |
| 135 | git checkout copy && |
| 136 | git reset --hard HEAD^ && |
| 137 | echo file >expect && |
| 138 | test_cmp expect file && |
| 139 | git pull --no-rebase . second && |
| 140 | echo modified >expect && |
| 141 | test_cmp expect file && |
| 142 | git reflog -1 >reflog.actual && |
| 143 | sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && |
| 144 | echo "OBJID HEAD@{0}: pull --no-rebase . second: Fast-forward" >reflog.expected && |
| 145 | test_cmp reflog.expected reflog.fuzzy |
| 146 | ' |
| 147 | |
| 148 | test_expect_success 'fail if wildcard spec does not match any refs' ' |
| 149 | git checkout -b test copy^ && |
| 150 | test_when_finished "git checkout -f copy && git branch -D test" && |
| 151 | echo file >expect && |
| 152 | test_cmp expect file && |
| 153 | test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err && |
| 154 | test_grep "no candidates for merging" err && |
| 155 | test_cmp expect file |
| 156 | ' |
| 157 | |
| 158 | test_expect_success 'fail if no branches specified with non-default remote' ' |
| 159 | git remote add test_remote . && |
| 160 | test_when_finished "git remote remove test_remote" && |
| 161 | git checkout -b test copy^ && |
| 162 | test_when_finished "git checkout -f copy && git branch -D test" && |
| 163 | echo file >expect && |
| 164 | test_cmp expect file && |
| 165 | test_config branch.test.remote origin && |
| 166 | test_must_fail git pull test_remote 2>err && |
| 167 | test_grep "specify a branch on the command line" err && |
| 168 | test_cmp expect file |
| 169 | ' |
| 170 | |
| 171 | test_expect_success 'fail if not on a branch' ' |
| 172 | git remote add origin . && |
| 173 | test_when_finished "git remote remove origin" && |
| 174 | git checkout HEAD^ && |
| 175 | test_when_finished "git checkout -f copy" && |
| 176 | echo file >expect && |
| 177 | test_cmp expect file && |
| 178 | test_must_fail git pull 2>err && |
| 179 | test_grep "not currently on a branch" err && |
| 180 | test_cmp expect file |
| 181 | ' |
| 182 | |
| 183 | test_expect_success 'fail if no configuration for current branch' ' |
| 184 | git remote add test_remote . && |
| 185 | test_when_finished "git remote remove test_remote" && |
| 186 | git checkout -b test copy^ && |
| 187 | test_when_finished "git checkout -f copy && git branch -D test" && |
| 188 | test_config branch.test.remote test_remote && |
| 189 | echo file >expect && |
| 190 | test_cmp expect file && |
| 191 | test_must_fail git pull 2>err && |
| 192 | test_grep "no tracking information" err && |
| 193 | test_cmp expect file |
| 194 | ' |
| 195 | |
| 196 | test_expect_success 'pull --all: fail if no configuration for current branch' ' |
| 197 | git remote add test_remote . && |
| 198 | test_when_finished "git remote remove test_remote" && |
| 199 | git checkout -b test copy^ && |
| 200 | test_when_finished "git checkout -f copy && git branch -D test" && |
| 201 | test_config branch.test.remote test_remote && |
| 202 | echo file >expect && |
| 203 | test_cmp expect file && |
| 204 | test_must_fail git pull --all 2>err && |
| 205 | test_grep "There is no tracking information" err && |
| 206 | test_cmp expect file |
| 207 | ' |
| 208 | |
| 209 | test_expect_success 'fail if upstream branch does not exist' ' |
| 210 | git checkout -b test copy^ && |
| 211 | test_when_finished "git checkout -f copy && git branch -D test" && |
| 212 | test_config branch.test.remote . && |
| 213 | test_config branch.test.merge refs/heads/nonexisting && |
| 214 | echo file >expect && |
| 215 | test_cmp expect file && |
| 216 | test_must_fail git pull 2>err && |
| 217 | test_grep "no such ref was fetched" err && |
| 218 | test_cmp expect file |
| 219 | ' |
| 220 | |
| 221 | test_expect_success 'fetch upstream branch even if refspec excludes it' ' |
| 222 | # the branch names are not important here except that |
| 223 | # the first one must not be a prefix of the second, |
| 224 | # since otherwise the ref-prefix protocol extension |
| 225 | # would match both |
| 226 | git branch in-refspec HEAD^ && |
| 227 | git branch not-in-refspec HEAD && |
| 228 | git init -b in-refspec downstream && |
| 229 | git -C downstream remote add -t in-refspec origin "file://$(pwd)/.git" && |
| 230 | git -C downstream config branch.in-refspec.remote origin && |
| 231 | git -C downstream config branch.in-refspec.merge refs/heads/not-in-refspec && |
| 232 | git -C downstream pull && |
| 233 | git rev-parse --verify not-in-refspec >expect && |
| 234 | git -C downstream rev-parse --verify HEAD >actual && |
| 235 | test_cmp expect actual |
| 236 | ' |
| 237 | |
| 238 | test_expect_success 'fail if the index has unresolved entries' ' |
| 239 | git checkout -b third second^ && |
| 240 | test_when_finished "git checkout -f copy && git branch -D third" && |
| 241 | echo file >expect && |
| 242 | test_cmp expect file && |
| 243 | test_commit modified2 file && |
| 244 | git ls-files -u >unmerged && |
| 245 | test_must_be_empty unmerged && |
| 246 | test_must_fail git pull --no-rebase . second && |
| 247 | git ls-files -u >unmerged && |
| 248 | test_file_not_empty unmerged && |
| 249 | cp file expected && |
| 250 | test_must_fail git pull . second 2>err && |
| 251 | test_grep "Pulling is not possible because you have unmerged files." err && |
| 252 | test_cmp expected file && |
| 253 | git add file && |
| 254 | git ls-files -u >unmerged && |
| 255 | test_must_be_empty unmerged && |
| 256 | test_must_fail git pull . second 2>err && |
| 257 | test_grep "You have not concluded your merge" err && |
| 258 | test_cmp expected file |
| 259 | ' |
| 260 | |
| 261 | test_expect_success 'fast-forwards working tree if branch head is updated' ' |
| 262 | git checkout -b third second^ && |
| 263 | test_when_finished "git checkout -f copy && git branch -D third" && |
| 264 | echo file >expect && |
| 265 | test_cmp expect file && |
| 266 | git pull . second:third 2>err && |
| 267 | test_grep "fetch updated the current branch head" err && |
| 268 | echo modified >expect && |
| 269 | test_cmp expect file && |
| 270 | test_cmp_rev third second |
| 271 | ' |
| 272 | |
| 273 | test_expect_success 'fast-forward fails with conflicting work tree' ' |
| 274 | git checkout -b third second^ && |
| 275 | test_when_finished "git checkout -f copy && git branch -D third" && |
| 276 | echo file >expect && |
| 277 | test_cmp expect file && |
| 278 | echo conflict >file && |
| 279 | test_must_fail git pull . second:third 2>err && |
| 280 | test_grep "Cannot fast-forward your working tree" err && |
| 281 | echo conflict >expect && |
| 282 | test_cmp expect file && |
| 283 | test_cmp_rev third second |
| 284 | ' |
| 285 | |
| 286 | test_expect_success '--rebase' ' |
| 287 | git branch to-rebase && |
| 288 | echo modified again >file && |
| 289 | git commit -m file file && |
| 290 | git checkout to-rebase && |
| 291 | echo new >file2 && |
| 292 | git add file2 && |
| 293 | git commit -m "new file" && |
| 294 | git tag before-rebase && |
| 295 | git pull --rebase . copy && |
| 296 | test_cmp_rev HEAD^ copy && |
| 297 | echo new >expect && |
| 298 | git show HEAD:file2 >actual && |
| 299 | test_cmp expect actual |
| 300 | ' |
| 301 | |
| 302 | test_expect_success '--rebase (merge) fast forward' ' |
| 303 | git reset --hard before-rebase && |
| 304 | git checkout -b ff && |
| 305 | echo another modification >file && |
| 306 | git commit -m third file && |
| 307 | |
| 308 | git checkout to-rebase && |
| 309 | git -c rebase.backend=merge pull --rebase . ff && |
| 310 | test_cmp_rev HEAD ff && |
| 311 | |
| 312 | # The above only validates the result. Did we actually bypass rebase? |
| 313 | git reflog -1 >reflog.actual && |
| 314 | sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && |
| 315 | echo "OBJID HEAD@{0}: pull --rebase . ff: Fast-forward" >reflog.expected && |
| 316 | test_cmp reflog.expected reflog.fuzzy |
| 317 | ' |
| 318 | |
| 319 | test_expect_success '--rebase (am) fast forward' ' |
| 320 | git reset --hard before-rebase && |
| 321 | |
| 322 | git -c rebase.backend=apply pull --rebase . ff && |
| 323 | test_cmp_rev HEAD ff && |
| 324 | |
| 325 | # The above only validates the result. Did we actually bypass rebase? |
| 326 | git reflog -1 >reflog.actual && |
| 327 | sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && |
| 328 | echo "OBJID HEAD@{0}: pull --rebase . ff: Fast-forward" >reflog.expected && |
| 329 | test_cmp reflog.expected reflog.fuzzy |
| 330 | ' |
| 331 | |
| 332 | test_expect_success '--rebase --autostash fast forward' ' |
| 333 | test_when_finished " |
| 334 | git reset --hard |
| 335 | git checkout to-rebase |
| 336 | git branch -D to-rebase-ff |
| 337 | git branch -D behind" && |
| 338 | git branch behind && |
| 339 | git checkout -b to-rebase-ff && |
| 340 | echo another modification >>file && |
| 341 | git add file && |
| 342 | git commit -m mod && |
| 343 | |
| 344 | git checkout behind && |
| 345 | echo dirty >file && |
| 346 | git pull --rebase --autostash . to-rebase-ff && |
| 347 | test_cmp_rev HEAD to-rebase-ff |
| 348 | ' |
| 349 | |
| 350 | test_expect_success '--rebase with rebase.autostash succeeds on ff' ' |
| 351 | test_when_finished "rm -fr src dst actual" && |
| 352 | git init src && |
| 353 | test_commit -C src "initial" file "content" && |
| 354 | git clone src dst && |
| 355 | test_commit -C src --printf "more_content" file "more content\ncontent\n" && |
| 356 | echo "dirty" >>dst/file && |
| 357 | test_config -C dst rebase.autostash true && |
| 358 | git -C dst pull --rebase >actual 2>&1 && |
| 359 | test_grep -q "Fast-forward" actual && |
| 360 | test_grep -q "Applied autostash." actual |
| 361 | ' |
| 362 | |
| 363 | test_expect_success '--rebase with conflicts shows advice' ' |
| 364 | test_when_finished "git rebase --abort; git checkout -f to-rebase" && |
| 365 | git checkout -b seq && |
| 366 | test_seq 5 >seq.txt && |
| 367 | git add seq.txt && |
| 368 | test_tick && |
| 369 | git commit -m "Add seq.txt" && |
| 370 | echo 6 >>seq.txt && |
| 371 | test_tick && |
| 372 | git commit -m "Append to seq.txt" seq.txt && |
| 373 | git checkout -b with-conflicts HEAD^ && |
| 374 | echo conflicting >>seq.txt && |
| 375 | test_tick && |
| 376 | git commit -m "Create conflict" seq.txt && |
| 377 | test_must_fail git pull --rebase . seq 2>err >out && |
| 378 | test_grep "Resolve all conflicts manually" err |
| 379 | ' |
| 380 | |
| 381 | test_expect_success 'failed --rebase shows advice' ' |
| 382 | test_when_finished "git rebase --abort; git checkout -f to-rebase" && |
| 383 | git checkout -b diverging && |
| 384 | test_commit attributes .gitattributes "* text=auto" attrs && |
| 385 | sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" && |
| 386 | git update-index --cacheinfo 0644 $sha1 file && |
| 387 | git commit -m v1-with-cr && |
| 388 | # force checkout because `git reset --hard` will not leave clean `file` |
| 389 | git checkout -f -b fails-to-rebase HEAD^ && |
| 390 | test_commit v2-without-cr file "2" file2-lf && |
| 391 | test_must_fail git pull --rebase . diverging 2>err >out && |
| 392 | test_grep "Resolve all conflicts manually" err |
| 393 | ' |
| 394 | |
| 395 | test_expect_success '--rebase fails with multiple branches' ' |
| 396 | git reset --hard before-rebase && |
| 397 | test_must_fail git pull --rebase . copy main 2>err && |
| 398 | test_cmp_rev HEAD before-rebase && |
| 399 | test_grep "Cannot rebase onto multiple branches" err && |
| 400 | echo modified >expect && |
| 401 | git show HEAD:file >actual && |
| 402 | test_cmp expect actual |
| 403 | ' |
| 404 | |
| 405 | test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' ' |
| 406 | test_config rebase.autostash true && |
| 407 | test_pull_autostash 1 --rebase |
| 408 | ' |
| 409 | |
| 410 | test_expect_success 'pull --rebase --autostash & rebase.autostash=true' ' |
| 411 | test_config rebase.autostash true && |
| 412 | test_pull_autostash 1 --rebase --autostash |
| 413 | ' |
| 414 | |
| 415 | test_expect_success 'pull --rebase --autostash & rebase.autostash=false' ' |
| 416 | test_config rebase.autostash false && |
| 417 | test_pull_autostash 1 --rebase --autostash |
| 418 | ' |
| 419 | |
| 420 | test_expect_success 'pull --rebase --autostash & rebase.autostash unset' ' |
| 421 | test_unconfig rebase.autostash && |
| 422 | test_pull_autostash 1 --rebase --autostash |
| 423 | ' |
| 424 | |
| 425 | test_expect_success 'pull --rebase --no-autostash & rebase.autostash=true' ' |
| 426 | test_config rebase.autostash true && |
| 427 | test_pull_autostash_fail --rebase --no-autostash |
| 428 | ' |
| 429 | |
| 430 | test_expect_success 'pull --rebase --no-autostash & rebase.autostash=false' ' |
| 431 | test_config rebase.autostash false && |
| 432 | test_pull_autostash_fail --rebase --no-autostash |
| 433 | ' |
| 434 | |
| 435 | test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' ' |
| 436 | test_unconfig rebase.autostash && |
| 437 | test_pull_autostash_fail --rebase --no-autostash |
| 438 | ' |
| 439 | |
| 440 | test_expect_success 'pull succeeds with dirty working directory and merge.autostash set' ' |
| 441 | test_config merge.autostash true && |
| 442 | test_pull_autostash 2 --no-rebase |
| 443 | ' |
| 444 | |
| 445 | test_expect_success 'pull --autostash & merge.autostash=true' ' |
| 446 | test_config merge.autostash true && |
| 447 | test_pull_autostash 2 --autostash --no-rebase |
| 448 | ' |
| 449 | |
| 450 | test_expect_success 'pull --autostash & merge.autostash=false' ' |
| 451 | test_config merge.autostash false && |
| 452 | test_pull_autostash 2 --autostash --no-rebase |
| 453 | ' |
| 454 | |
| 455 | test_expect_success 'pull --autostash & merge.autostash unset' ' |
| 456 | test_unconfig merge.autostash && |
| 457 | test_pull_autostash 2 --autostash --no-rebase |
| 458 | ' |
| 459 | |
| 460 | test_expect_success 'pull --no-autostash & merge.autostash=true' ' |
| 461 | test_config merge.autostash true && |
| 462 | test_pull_autostash_fail --no-autostash --no-rebase |
| 463 | ' |
| 464 | |
| 465 | test_expect_success 'pull --no-autostash & merge.autostash=false' ' |
| 466 | test_config merge.autostash false && |
| 467 | test_pull_autostash_fail --no-autostash --no-rebase |
| 468 | ' |
| 469 | |
| 470 | test_expect_success 'pull --no-autostash & merge.autostash unset' ' |
| 471 | test_unconfig merge.autostash && |
| 472 | test_pull_autostash_fail --no-autostash --no-rebase |
| 473 | ' |
| 474 | |
| 475 | test_expect_success 'pull succeeds with dirty working directory and pull.autostash=true' ' |
| 476 | test_config pull.autostash true && |
| 477 | test_pull_autostash 1 --rebase && |
| 478 | test_pull_autostash 2 --no-rebase && |
| 479 | test_pull_autostash 1 --autostash --rebase && |
| 480 | test_pull_autostash 2 --autostash --no-rebase |
| 481 | ' |
| 482 | |
| 483 | test_expect_success 'pull fails with dirty working directory and pull.autostash=false' ' |
| 484 | test_config pull.autostash false && |
| 485 | test_pull_autostash_fail --rebase && |
| 486 | test_pull_autostash_fail --no-rebase && |
| 487 | test_pull_autostash_fail --no-autostash --rebase && |
| 488 | test_pull_autostash_fail --no-autostash --no-rebase |
| 489 | ' |
| 490 | |
| 491 | test_expect_success 'pull --autostash overrides pull.autostash=false' ' |
| 492 | test_config pull.autostash false && |
| 493 | test_pull_autostash 1 --autostash --rebase && |
| 494 | test_pull_autostash 2 --autostash --no-rebase |
| 495 | ' |
| 496 | |
| 497 | test_expect_success 'pull --no-autostash overrides pull.autostash=true' ' |
| 498 | test_config pull.autostash true && |
| 499 | test_pull_autostash_fail --no-autostash --rebase && |
| 500 | test_pull_autostash_fail --no-autostash --no-rebase |
| 501 | ' |
| 502 | |
| 503 | test_expect_success 'pull.autostash=true overrides rebase.autostash' ' |
| 504 | test_config pull.autostash true && |
| 505 | test_config rebase.autostash true && |
| 506 | test_pull_autostash 1 --rebase && |
| 507 | test_config rebase.autostash false && |
| 508 | test_pull_autostash 1 --rebase |
| 509 | ' |
| 510 | |
| 511 | test_expect_success 'pull.autostash=false overrides rebase.autostash' ' |
| 512 | test_config pull.autostash false && |
| 513 | test_config rebase.autostash true && |
| 514 | test_pull_autostash_fail --rebase && |
| 515 | test_config rebase.autostash false && |
| 516 | test_pull_autostash_fail --rebase |
| 517 | ' |
| 518 | |
| 519 | test_expect_success 'pull.autostash=true overrides merge.autostash' ' |
| 520 | test_config pull.autostash true && |
| 521 | test_config merge.autostash true && |
| 522 | test_pull_autostash 2 --no-rebase && |
| 523 | test_config merge.autostash false && |
| 524 | test_pull_autostash 2 --no-rebase |
| 525 | ' |
| 526 | |
| 527 | test_expect_success 'pull.autostash=false overrides merge.autostash' ' |
| 528 | test_config pull.autostash false && |
| 529 | test_config merge.autostash true && |
| 530 | test_pull_autostash_fail --no-rebase && |
| 531 | test_config merge.autostash false && |
| 532 | test_pull_autostash_fail --no-rebase |
| 533 | ' |
| 534 | |
| 535 | test_expect_success 'pull.rebase' ' |
| 536 | git reset --hard before-rebase && |
| 537 | test_config pull.rebase true && |
| 538 | git pull . copy && |
| 539 | test_cmp_rev HEAD^ copy && |
| 540 | echo new >expect && |
| 541 | git show HEAD:file2 >actual && |
| 542 | test_cmp expect actual |
| 543 | ' |
| 544 | |
| 545 | test_expect_success 'pull --autostash & pull.rebase=true' ' |
| 546 | test_config pull.rebase true && |
| 547 | test_pull_autostash 1 --autostash |
| 548 | ' |
| 549 | |
| 550 | test_expect_success 'pull --no-autostash & pull.rebase=true' ' |
| 551 | test_config pull.rebase true && |
| 552 | test_pull_autostash_fail --no-autostash |
| 553 | ' |
| 554 | |
| 555 | test_expect_success 'branch.to-rebase.rebase' ' |
| 556 | git reset --hard before-rebase && |
| 557 | test_config branch.to-rebase.rebase true && |
| 558 | git pull . copy && |
| 559 | test_cmp_rev HEAD^ copy && |
| 560 | echo new >expect && |
| 561 | git show HEAD:file2 >actual && |
| 562 | test_cmp expect actual |
| 563 | ' |
| 564 | |
| 565 | test_expect_success 'branch.to-rebase.rebase should override pull.rebase' ' |
| 566 | git reset --hard before-rebase && |
| 567 | test_config pull.rebase true && |
| 568 | test_config branch.to-rebase.rebase false && |
| 569 | git pull . copy && |
| 570 | test_cmp_rev ! HEAD^ copy && |
| 571 | echo new >expect && |
| 572 | git show HEAD:file2 >actual && |
| 573 | test_cmp expect actual |
| 574 | ' |
| 575 | |
| 576 | test_expect_success 'pull --rebase warns on --verify-signatures' ' |
| 577 | git reset --hard before-rebase && |
| 578 | git pull --rebase --verify-signatures . copy 2>err && |
| 579 | test_cmp_rev HEAD^ copy && |
| 580 | echo new >expect && |
| 581 | git show HEAD:file2 >actual && |
| 582 | test_cmp expect actual && |
| 583 | test_grep "ignoring --verify-signatures for rebase" err |
| 584 | ' |
| 585 | |
| 586 | test_expect_success 'pull --rebase does not warn on --no-verify-signatures' ' |
| 587 | git reset --hard before-rebase && |
| 588 | git pull --rebase --no-verify-signatures . copy 2>err && |
| 589 | test_cmp_rev HEAD^ copy && |
| 590 | echo new >expect && |
| 591 | git show HEAD:file2 >actual && |
| 592 | test_cmp expect actual && |
| 593 | test_grep ! "verify-signatures" err |
| 594 | ' |
| 595 | |
| 596 | # add a feature branch, keep-merge, that is merged into main, so the |
| 597 | # test can try preserving the merge commit (or not) with various |
| 598 | # --rebase flags/pull.rebase settings. |
| 599 | test_expect_success 'preserve merge setup' ' |
| 600 | git reset --hard before-rebase && |
| 601 | git checkout -b keep-merge second^ && |
| 602 | test_commit file3 && |
| 603 | git checkout to-rebase && |
| 604 | git merge keep-merge && |
| 605 | git tag before-preserve-rebase |
| 606 | ' |
| 607 | |
| 608 | test_expect_success 'pull.rebase=false create a new merge commit' ' |
| 609 | git reset --hard before-preserve-rebase && |
| 610 | test_config pull.rebase false && |
| 611 | git pull . copy && |
| 612 | test_cmp_rev HEAD^1 before-preserve-rebase && |
| 613 | test_cmp_rev HEAD^2 copy && |
| 614 | echo file3 >expect && |
| 615 | git show HEAD:file3.t >actual && |
| 616 | test_cmp expect actual |
| 617 | ' |
| 618 | |
| 619 | test_expect_success 'pull.rebase=true flattens keep-merge' ' |
| 620 | git reset --hard before-preserve-rebase && |
| 621 | test_config pull.rebase true && |
| 622 | git pull . copy && |
| 623 | test_cmp_rev HEAD^^ copy && |
| 624 | echo file3 >expect && |
| 625 | git show HEAD:file3.t >actual && |
| 626 | test_cmp expect actual |
| 627 | ' |
| 628 | |
| 629 | test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' ' |
| 630 | git reset --hard before-preserve-rebase && |
| 631 | test_config pull.rebase 1 && |
| 632 | git pull . copy && |
| 633 | test_cmp_rev HEAD^^ copy && |
| 634 | echo file3 >expect && |
| 635 | git show HEAD:file3.t >actual && |
| 636 | test_cmp expect actual |
| 637 | ' |
| 638 | |
| 639 | test_expect_success 'pull.rebase=interactive' ' |
| 640 | write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF && |
| 641 | echo I was here >fake.out && |
| 642 | false |
| 643 | EOF |
| 644 | test_set_editor "$TRASH_DIRECTORY/fake-editor" && |
| 645 | test_when_finished "test_might_fail git rebase --abort" && |
| 646 | test_must_fail git pull --rebase=interactive . copy && |
| 647 | echo "I was here" >expect && |
| 648 | test_cmp expect fake.out |
| 649 | ' |
| 650 | |
| 651 | test_expect_success 'pull --rebase=i' ' |
| 652 | write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF && |
| 653 | echo I was here, too >fake.out && |
| 654 | false |
| 655 | EOF |
| 656 | test_set_editor "$TRASH_DIRECTORY/fake-editor" && |
| 657 | test_when_finished "test_might_fail git rebase --abort" && |
| 658 | test_must_fail git pull --rebase=i . copy && |
| 659 | echo "I was here, too" >expect && |
| 660 | test_cmp expect fake.out |
| 661 | ' |
| 662 | |
| 663 | test_expect_success 'pull.rebase=invalid fails' ' |
| 664 | git reset --hard before-preserve-rebase && |
| 665 | test_config pull.rebase invalid && |
| 666 | test_must_fail git pull . copy |
| 667 | ' |
| 668 | |
| 669 | test_expect_success '--rebase=false create a new merge commit' ' |
| 670 | git reset --hard before-preserve-rebase && |
| 671 | test_config pull.rebase true && |
| 672 | git pull --rebase=false . copy && |
| 673 | test_cmp_rev HEAD^1 before-preserve-rebase && |
| 674 | test_cmp_rev HEAD^2 copy && |
| 675 | echo file3 >expect && |
| 676 | git show HEAD:file3.t >actual && |
| 677 | test_cmp expect actual |
| 678 | ' |
| 679 | |
| 680 | test_expect_success '--rebase=true rebases and flattens keep-merge' ' |
| 681 | git reset --hard before-preserve-rebase && |
| 682 | test_config pull.rebase merges && |
| 683 | git pull --rebase=true . copy && |
| 684 | test_cmp_rev HEAD^^ copy && |
| 685 | echo file3 >expect && |
| 686 | git show HEAD:file3.t >actual && |
| 687 | test_cmp expect actual |
| 688 | ' |
| 689 | |
| 690 | test_expect_success '--rebase=invalid fails' ' |
| 691 | git reset --hard before-preserve-rebase && |
| 692 | test_must_fail git pull --rebase=invalid . copy |
| 693 | ' |
| 694 | |
| 695 | test_expect_success '--rebase overrides pull.rebase=merges and flattens keep-merge' ' |
| 696 | git reset --hard before-preserve-rebase && |
| 697 | test_config pull.rebase merges && |
| 698 | git pull --rebase . copy && |
| 699 | test_cmp_rev HEAD^^ copy && |
| 700 | echo file3 >expect && |
| 701 | git show HEAD:file3.t >actual && |
| 702 | test_cmp expect actual |
| 703 | ' |
| 704 | |
| 705 | test_expect_success '--rebase with rebased upstream' ' |
| 706 | git remote add -f me . && |
| 707 | git checkout copy && |
| 708 | git tag copy-orig && |
| 709 | git reset --hard HEAD^ && |
| 710 | echo conflicting modification >file && |
| 711 | git commit -m conflict file && |
| 712 | git checkout to-rebase && |
| 713 | echo file >file2 && |
| 714 | git commit -m to-rebase file2 && |
| 715 | git tag to-rebase-orig && |
| 716 | git pull --rebase me copy && |
| 717 | echo "conflicting modification" >expect && |
| 718 | test_cmp expect file && |
| 719 | echo file >expect && |
| 720 | test_cmp expect file2 |
| 721 | ' |
| 722 | |
| 723 | test_expect_success '--rebase -f with rebased upstream' ' |
| 724 | test_when_finished "test_might_fail git rebase --abort" && |
| 725 | git reset --hard to-rebase-orig && |
| 726 | git pull --rebase -f me copy && |
| 727 | echo "conflicting modification" >expect && |
| 728 | test_cmp expect file && |
| 729 | echo file >expect && |
| 730 | test_cmp expect file2 |
| 731 | ' |
| 732 | |
| 733 | test_expect_success '--rebase with rebased default upstream' ' |
| 734 | git update-ref refs/remotes/me/copy copy-orig && |
| 735 | git checkout --track -b to-rebase2 me/copy && |
| 736 | git reset --hard to-rebase-orig && |
| 737 | git pull --rebase && |
| 738 | echo "conflicting modification" >expect && |
| 739 | test_cmp expect file && |
| 740 | echo file >expect && |
| 741 | test_cmp expect file2 |
| 742 | ' |
| 743 | |
| 744 | test_expect_success 'rebased upstream + fetch + pull --rebase' ' |
| 745 | |
| 746 | git update-ref refs/remotes/me/copy copy-orig && |
| 747 | git reset --hard to-rebase-orig && |
| 748 | git checkout --track -b to-rebase3 me/copy && |
| 749 | git reset --hard to-rebase-orig && |
| 750 | git fetch && |
| 751 | git pull --rebase && |
| 752 | echo "conflicting modification" >expect && |
| 753 | test_cmp expect file && |
| 754 | echo file >expect && |
| 755 | test_cmp expect file2 |
| 756 | |
| 757 | ' |
| 758 | |
| 759 | test_expect_success 'pull --rebase dies early with dirty working directory' ' |
| 760 | git checkout to-rebase && |
| 761 | git update-ref refs/remotes/me/copy copy^ && |
| 762 | COPY="$(git rev-parse --verify me/copy)" && |
| 763 | git rebase --onto $COPY copy && |
| 764 | test_config branch.to-rebase.remote me && |
| 765 | test_config branch.to-rebase.merge refs/heads/copy && |
| 766 | test_config branch.to-rebase.rebase true && |
| 767 | echo dirty >>file && |
| 768 | git add file && |
| 769 | test_must_fail git pull && |
| 770 | test_cmp_rev "$COPY" me/copy && |
| 771 | git checkout HEAD -- file && |
| 772 | git pull && |
| 773 | test_cmp_rev ! "$COPY" me/copy |
| 774 | ' |
| 775 | |
| 776 | test_expect_success 'pull --rebase works on branch yet to be born' ' |
| 777 | git rev-parse main >expect && |
| 778 | mkdir empty_repo && |
| 779 | ( |
| 780 | cd empty_repo && |
| 781 | git init && |
| 782 | git pull --rebase .. main && |
| 783 | git rev-parse HEAD >../actual |
| 784 | ) && |
| 785 | test_cmp expect actual |
| 786 | ' |
| 787 | |
| 788 | test_expect_success 'pull --rebase fails on unborn branch with staged changes' ' |
| 789 | test_when_finished "rm -rf empty_repo2" && |
| 790 | git init empty_repo2 && |
| 791 | ( |
| 792 | cd empty_repo2 && |
| 793 | echo staged-file >staged-file && |
| 794 | git add staged-file && |
| 795 | echo staged-file >expect && |
| 796 | git ls-files >actual && |
| 797 | test_cmp expect actual && |
| 798 | test_must_fail git pull --rebase .. main 2>err && |
| 799 | git ls-files >actual && |
| 800 | test_cmp expect actual && |
| 801 | git show :staged-file >actual && |
| 802 | test_cmp expect actual && |
| 803 | test_grep "unborn branch with changes added to the index" err |
| 804 | ) |
| 805 | ' |
| 806 | |
| 807 | test_expect_success 'pull --rebase fails on corrupt HEAD' ' |
| 808 | test_when_finished "rm -rf corrupt" && |
| 809 | git init corrupt && |
| 810 | ( |
| 811 | cd corrupt && |
| 812 | test_commit one && |
| 813 | git rev-parse --verify HEAD >head && |
| 814 | obj=$(sed "s#^..#&/#" head) && |
| 815 | rm -f .git/objects/$obj && |
| 816 | test_must_fail git pull --rebase |
| 817 | ) |
| 818 | ' |
| 819 | |
| 820 | test_expect_success 'setup for detecting upstreamed changes' ' |
| 821 | test_create_repo src && |
| 822 | test_commit -C src --printf one stuff "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" && |
| 823 | git clone src dst && |
| 824 | ( |
| 825 | cd src && |
| 826 | modify s/5/43/ stuff && |
| 827 | git commit -a -m "5->43" && |
| 828 | modify s/6/42/ stuff && |
| 829 | git commit -a -m "Make it bigger" |
| 830 | ) && |
| 831 | ( |
| 832 | cd dst && |
| 833 | modify s/5/43/ stuff && |
| 834 | git commit -a -m "Independent discovery of 5->43" |
| 835 | ) |
| 836 | ' |
| 837 | |
| 838 | test_expect_success 'git pull --rebase detects upstreamed changes' ' |
| 839 | ( |
| 840 | cd dst && |
| 841 | git pull --rebase && |
| 842 | git ls-files -u >untracked && |
| 843 | test_must_be_empty untracked |
| 844 | ) |
| 845 | ' |
| 846 | |
| 847 | test_expect_success 'setup for avoiding reapplying old patches' ' |
| 848 | ( |
| 849 | cd dst && |
| 850 | test_might_fail git rebase --abort && |
| 851 | git reset --hard origin/main |
| 852 | ) && |
| 853 | git clone --bare src src-replace.git && |
| 854 | rm -rf src && |
| 855 | mv src-replace.git src && |
| 856 | ( |
| 857 | cd dst && |
| 858 | modify s/2/22/ stuff && |
| 859 | git commit -a -m "Change 2" && |
| 860 | modify s/3/33/ stuff && |
| 861 | git commit -a -m "Change 3" && |
| 862 | modify s/4/44/ stuff && |
| 863 | git commit -a -m "Change 4" && |
| 864 | git push && |
| 865 | |
| 866 | modify s/44/55/ stuff && |
| 867 | git commit --amend -a -m "Modified Change 4" |
| 868 | ) |
| 869 | ' |
| 870 | |
| 871 | test_expect_success 'git pull --rebase does not reapply old patches' ' |
| 872 | ( |
| 873 | cd dst && |
| 874 | test_must_fail git pull --rebase && |
| 875 | cat .git/rebase-merge/done .git/rebase-merge/git-rebase-todo >work && |
| 876 | grep -v -e ^\# -e ^$ work >patches && |
| 877 | test_line_count = 1 patches && |
| 878 | rm -f work |
| 879 | ) |
| 880 | ' |
| 881 | |
| 882 | test_expect_success 'git pull --rebase against local branch' ' |
| 883 | git checkout -b copy2 to-rebase-orig && |
| 884 | git pull --rebase . to-rebase && |
| 885 | echo "conflicting modification" >expect && |
| 886 | test_cmp expect file && |
| 887 | echo file >expect && |
| 888 | test_cmp expect file2 |
| 889 | ' |
| 890 | |
| 891 | test_done |