t / t5520-pull.shon commit Merge branch 'ss/fix-config-fd-leak' into maint (8136099)
   1#!/bin/sh
   2
   3test_description='pulling into void'
   4
   5. ./test-lib.sh
   6
   7modify () {
   8        sed -e "$1" <"$2" >"$2.x" &&
   9        mv "$2.x" "$2"
  10}
  11
  12test_expect_success setup '
  13        echo file >file &&
  14        git add file &&
  15        git commit -a -m original
  16'
  17
  18test_expect_success 'pulling into void' '
  19        git init cloned &&
  20        (
  21                cd cloned &&
  22                git pull ..
  23        ) &&
  24        test -f file &&
  25        test -f cloned/file &&
  26        test_cmp file cloned/file
  27'
  28
  29test_expect_success 'pulling into void using master:master' '
  30        git init cloned-uho &&
  31        (
  32                cd cloned-uho &&
  33                git pull .. master:master
  34        ) &&
  35        test -f file &&
  36        test -f cloned-uho/file &&
  37        test_cmp file cloned-uho/file
  38'
  39
  40test_expect_success 'pulling into void does not overwrite untracked files' '
  41        git init cloned-untracked &&
  42        (
  43                cd cloned-untracked &&
  44                echo untracked >file &&
  45                test_must_fail git pull .. master &&
  46                echo untracked >expect &&
  47                test_cmp expect file
  48        )
  49'
  50
  51test_expect_success 'pulling into void does not overwrite staged files' '
  52        git init cloned-staged-colliding &&
  53        (
  54                cd cloned-staged-colliding &&
  55                echo "alternate content" >file &&
  56                git add file &&
  57                test_must_fail git pull .. master &&
  58                echo "alternate content" >expect &&
  59                test_cmp expect file &&
  60                git cat-file blob :file >file.index &&
  61                test_cmp expect file.index
  62        )
  63'
  64
  65test_expect_success 'pulling into void does not remove new staged files' '
  66        git init cloned-staged-new &&
  67        (
  68                cd cloned-staged-new &&
  69                echo "new tracked file" >newfile &&
  70                git add newfile &&
  71                git pull .. master &&
  72                echo "new tracked file" >expect &&
  73                test_cmp expect newfile &&
  74                git cat-file blob :newfile >newfile.index &&
  75                test_cmp expect newfile.index
  76        )
  77'
  78
  79test_expect_success 'pulling into void must not create an octopus' '
  80        git init cloned-octopus &&
  81        (
  82                cd cloned-octopus &&
  83                test_must_fail git pull .. master master &&
  84                ! test -f file
  85        )
  86'
  87
  88test_expect_success 'test . as a remote' '
  89        git branch copy master &&
  90        git config branch.copy.remote . &&
  91        git config branch.copy.merge refs/heads/master &&
  92        echo updated >file &&
  93        git commit -a -m updated &&
  94        git checkout copy &&
  95        test "$(cat file)" = file &&
  96        git pull &&
  97        test "$(cat file)" = updated &&
  98        git reflog -1 >reflog.actual &&
  99        sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 100        echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
 101        test_cmp reflog.expected reflog.fuzzy
 102'
 103
 104test_expect_success 'the default remote . should not break explicit pull' '
 105        git checkout -b second master^ &&
 106        echo modified >file &&
 107        git commit -a -m modified &&
 108        git checkout copy &&
 109        git reset --hard HEAD^ &&
 110        test "$(cat file)" = file &&
 111        git pull . second &&
 112        test "$(cat file)" = modified &&
 113        git reflog -1 >reflog.actual &&
 114        sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 115        echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
 116        test_cmp reflog.expected reflog.fuzzy
 117'
 118
 119test_expect_success 'fail if wildcard spec does not match any refs' '
 120        git checkout -b test copy^ &&
 121        test_when_finished "git checkout -f copy && git branch -D test" &&
 122        test "$(cat file)" = file &&
 123        test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 124        test_i18ngrep "no candidates for merging" err &&
 125        test "$(cat file)" = file
 126'
 127
 128test_expect_success 'fail if no branches specified with non-default remote' '
 129        git remote add test_remote . &&
 130        test_when_finished "git remote remove test_remote" &&
 131        git checkout -b test copy^ &&
 132        test_when_finished "git checkout -f copy && git branch -D test" &&
 133        test "$(cat file)" = file &&
 134        test_config branch.test.remote origin &&
 135        test_must_fail git pull test_remote 2>err &&
 136        test_i18ngrep "specify a branch on the command line" err &&
 137        test "$(cat file)" = file
 138'
 139
 140test_expect_success 'fail if not on a branch' '
 141        git remote add origin . &&
 142        test_when_finished "git remote remove origin" &&
 143        git checkout HEAD^ &&
 144        test_when_finished "git checkout -f copy" &&
 145        test "$(cat file)" = file &&
 146        test_must_fail git pull 2>err &&
 147        test_i18ngrep "not currently on a branch" err &&
 148        test "$(cat file)" = file
 149'
 150
 151test_expect_success 'fail if no configuration for current branch' '
 152        git remote add test_remote . &&
 153        test_when_finished "git remote remove test_remote" &&
 154        git checkout -b test copy^ &&
 155        test_when_finished "git checkout -f copy && git branch -D test" &&
 156        test_config branch.test.remote test_remote &&
 157        test "$(cat file)" = file &&
 158        test_must_fail git pull 2>err &&
 159        test_i18ngrep "no tracking information" err &&
 160        test "$(cat file)" = file
 161'
 162
 163test_expect_success 'pull --all: fail if no configuration for current branch' '
 164        git remote add test_remote . &&
 165        test_when_finished "git remote remove test_remote" &&
 166        git checkout -b test copy^ &&
 167        test_when_finished "git checkout -f copy && git branch -D test" &&
 168        test_config branch.test.remote test_remote &&
 169        test "$(cat file)" = file &&
 170        test_must_fail git pull --all 2>err &&
 171        test_i18ngrep "There is no tracking information" err &&
 172        test "$(cat file)" = file
 173'
 174
 175test_expect_success 'fail if upstream branch does not exist' '
 176        git checkout -b test copy^ &&
 177        test_when_finished "git checkout -f copy && git branch -D test" &&
 178        test_config branch.test.remote . &&
 179        test_config branch.test.merge refs/heads/nonexisting &&
 180        test "$(cat file)" = file &&
 181        test_must_fail git pull 2>err &&
 182        test_i18ngrep "no such ref was fetched" err &&
 183        test "$(cat file)" = file
 184'
 185
 186test_expect_success 'fail if the index has unresolved entries' '
 187        git checkout -b third second^ &&
 188        test_when_finished "git checkout -f copy && git branch -D third" &&
 189        test "$(cat file)" = file &&
 190        test_commit modified2 file &&
 191        test -z "$(git ls-files -u)" &&
 192        test_must_fail git pull . second &&
 193        test -n "$(git ls-files -u)" &&
 194        cp file expected &&
 195        test_must_fail git pull . second 2>err &&
 196        test_i18ngrep "Pull is not possible because you have unmerged files" err &&
 197        test_cmp expected file &&
 198        git add file &&
 199        test -z "$(git ls-files -u)" &&
 200        test_must_fail git pull . second 2>err &&
 201        test_i18ngrep "You have not concluded your merge" err &&
 202        test_cmp expected file
 203'
 204
 205test_expect_success 'fast-forwards working tree if branch head is updated' '
 206        git checkout -b third second^ &&
 207        test_when_finished "git checkout -f copy && git branch -D third" &&
 208        test "$(cat file)" = file &&
 209        git pull . second:third 2>err &&
 210        test_i18ngrep "fetch updated the current branch head" err &&
 211        test "$(cat file)" = modified &&
 212        test "$(git rev-parse third)" = "$(git rev-parse second)"
 213'
 214
 215test_expect_success 'fast-forward fails with conflicting work tree' '
 216        git checkout -b third second^ &&
 217        test_when_finished "git checkout -f copy && git branch -D third" &&
 218        test "$(cat file)" = file &&
 219        echo conflict >file &&
 220        test_must_fail git pull . second:third 2>err &&
 221        test_i18ngrep "Cannot fast-forward your working tree" err &&
 222        test "$(cat file)" = conflict &&
 223        test "$(git rev-parse third)" = "$(git rev-parse second)"
 224'
 225
 226test_expect_success '--rebase' '
 227        git branch to-rebase &&
 228        echo modified again > file &&
 229        git commit -m file file &&
 230        git checkout to-rebase &&
 231        echo new > file2 &&
 232        git add file2 &&
 233        git commit -m "new file" &&
 234        git tag before-rebase &&
 235        git pull --rebase . copy &&
 236        test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
 237        test new = "$(git show HEAD:file2)"
 238'
 239
 240test_expect_success '--rebase fails with multiple branches' '
 241        git reset --hard before-rebase &&
 242        test_must_fail git pull --rebase . copy master 2>err &&
 243        test "$(git rev-parse HEAD)" = "$(git rev-parse before-rebase)" &&
 244        test_i18ngrep "Cannot rebase onto multiple branches" err &&
 245        test modified = "$(git show HEAD:file)"
 246'
 247
 248test_expect_success 'pull.rebase' '
 249        git reset --hard before-rebase &&
 250        test_config pull.rebase true &&
 251        git pull . copy &&
 252        test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
 253        test new = "$(git show HEAD:file2)"
 254'
 255
 256test_expect_success 'branch.to-rebase.rebase' '
 257        git reset --hard before-rebase &&
 258        test_config branch.to-rebase.rebase true &&
 259        git pull . copy &&
 260        test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
 261        test new = "$(git show HEAD:file2)"
 262'
 263
 264test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 265        git reset --hard before-rebase &&
 266        test_config pull.rebase true &&
 267        test_config branch.to-rebase.rebase false &&
 268        git pull . copy &&
 269        test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
 270        test new = "$(git show HEAD:file2)"
 271'
 272
 273# add a feature branch, keep-merge, that is merged into master, so the
 274# test can try preserving the merge commit (or not) with various
 275# --rebase flags/pull.rebase settings.
 276test_expect_success 'preserve merge setup' '
 277        git reset --hard before-rebase &&
 278        git checkout -b keep-merge second^ &&
 279        test_commit file3 &&
 280        git checkout to-rebase &&
 281        git merge keep-merge &&
 282        git tag before-preserve-rebase
 283'
 284
 285test_expect_success 'pull.rebase=false create a new merge commit' '
 286        git reset --hard before-preserve-rebase &&
 287        test_config pull.rebase false &&
 288        git pull . copy &&
 289        test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
 290        test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
 291        test file3 = "$(git show HEAD:file3.t)"
 292'
 293
 294test_expect_success 'pull.rebase=true flattens keep-merge' '
 295        git reset --hard before-preserve-rebase &&
 296        test_config pull.rebase true &&
 297        git pull . copy &&
 298        test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
 299        test file3 = "$(git show HEAD:file3.t)"
 300'
 301
 302test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 303        git reset --hard before-preserve-rebase &&
 304        test_config pull.rebase 1 &&
 305        git pull . copy &&
 306        test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
 307        test file3 = "$(git show HEAD:file3.t)"
 308'
 309
 310test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' '
 311        git reset --hard before-preserve-rebase &&
 312        test_config pull.rebase preserve &&
 313        git pull . copy &&
 314        test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
 315        test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
 316'
 317
 318test_expect_success 'pull.rebase=invalid fails' '
 319        git reset --hard before-preserve-rebase &&
 320        test_config pull.rebase invalid &&
 321        ! git pull . copy
 322'
 323
 324test_expect_success '--rebase=false create a new merge commit' '
 325        git reset --hard before-preserve-rebase &&
 326        test_config pull.rebase true &&
 327        git pull --rebase=false . copy &&
 328        test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
 329        test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
 330        test file3 = "$(git show HEAD:file3.t)"
 331'
 332
 333test_expect_success '--rebase=true rebases and flattens keep-merge' '
 334        git reset --hard before-preserve-rebase &&
 335        test_config pull.rebase preserve &&
 336        git pull --rebase=true . copy &&
 337        test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
 338        test file3 = "$(git show HEAD:file3.t)"
 339'
 340
 341test_expect_success '--rebase=preserve rebases and merges keep-merge' '
 342        git reset --hard before-preserve-rebase &&
 343        test_config pull.rebase true &&
 344        git pull --rebase=preserve . copy &&
 345        test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
 346        test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
 347'
 348
 349test_expect_success '--rebase=invalid fails' '
 350        git reset --hard before-preserve-rebase &&
 351        ! git pull --rebase=invalid . copy
 352'
 353
 354test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
 355        git reset --hard before-preserve-rebase &&
 356        test_config pull.rebase preserve &&
 357        git pull --rebase . copy &&
 358        test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
 359        test file3 = "$(git show HEAD:file3.t)"
 360'
 361
 362test_expect_success '--rebase with rebased upstream' '
 363
 364        git remote add -f me . &&
 365        git checkout copy &&
 366        git tag copy-orig &&
 367        git reset --hard HEAD^ &&
 368        echo conflicting modification > file &&
 369        git commit -m conflict file &&
 370        git checkout to-rebase &&
 371        echo file > file2 &&
 372        git commit -m to-rebase file2 &&
 373        git tag to-rebase-orig &&
 374        git pull --rebase me copy &&
 375        test "conflicting modification" = "$(cat file)" &&
 376        test file = "$(cat file2)"
 377
 378'
 379
 380test_expect_success '--rebase -f with rebased upstream' '
 381        test_when_finished "test_might_fail git rebase --abort" &&
 382        git reset --hard to-rebase-orig &&
 383        git pull --rebase -f me copy &&
 384        test "conflicting modification" = "$(cat file)" &&
 385        test file = "$(cat file2)"
 386'
 387
 388test_expect_success '--rebase with rebased default upstream' '
 389
 390        git update-ref refs/remotes/me/copy copy-orig &&
 391        git checkout --track -b to-rebase2 me/copy &&
 392        git reset --hard to-rebase-orig &&
 393        git pull --rebase &&
 394        test "conflicting modification" = "$(cat file)" &&
 395        test file = "$(cat file2)"
 396
 397'
 398
 399test_expect_success 'rebased upstream + fetch + pull --rebase' '
 400
 401        git update-ref refs/remotes/me/copy copy-orig &&
 402        git reset --hard to-rebase-orig &&
 403        git checkout --track -b to-rebase3 me/copy &&
 404        git reset --hard to-rebase-orig &&
 405        git fetch &&
 406        git pull --rebase &&
 407        test "conflicting modification" = "$(cat file)" &&
 408        test file = "$(cat file2)"
 409
 410'
 411
 412test_expect_success 'pull --rebase dies early with dirty working directory' '
 413
 414        git checkout to-rebase &&
 415        git update-ref refs/remotes/me/copy copy^ &&
 416        COPY="$(git rev-parse --verify me/copy)" &&
 417        git rebase --onto $COPY copy &&
 418        test_config branch.to-rebase.remote me &&
 419        test_config branch.to-rebase.merge refs/heads/copy &&
 420        test_config branch.to-rebase.rebase true &&
 421        echo dirty >> file &&
 422        git add file &&
 423        test_must_fail git pull &&
 424        test "$COPY" = "$(git rev-parse --verify me/copy)" &&
 425        git checkout HEAD -- file &&
 426        git pull &&
 427        test "$COPY" != "$(git rev-parse --verify me/copy)"
 428
 429'
 430
 431test_expect_success 'pull --rebase works on branch yet to be born' '
 432        git rev-parse master >expect &&
 433        mkdir empty_repo &&
 434        (cd empty_repo &&
 435         git init &&
 436         git pull --rebase .. master &&
 437         git rev-parse HEAD >../actual
 438        ) &&
 439        test_cmp expect actual
 440'
 441
 442test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
 443        test_when_finished "rm -rf empty_repo2" &&
 444        git init empty_repo2 &&
 445        (
 446                cd empty_repo2 &&
 447                echo staged-file >staged-file &&
 448                git add staged-file &&
 449                test "$(git ls-files)" = staged-file &&
 450                test_must_fail git pull --rebase .. master 2>err &&
 451                test "$(git ls-files)" = staged-file &&
 452                test "$(git show :staged-file)" = staged-file &&
 453                test_i18ngrep "unborn branch with changes added to the index" err
 454        )
 455'
 456
 457test_expect_success 'setup for detecting upstreamed changes' '
 458        mkdir src &&
 459        (cd src &&
 460         git init &&
 461         printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
 462         git add stuff &&
 463         git commit -m "Initial revision"
 464        ) &&
 465        git clone src dst &&
 466        (cd src &&
 467         modify s/5/43/ stuff &&
 468         git commit -a -m "5->43" &&
 469         modify s/6/42/ stuff &&
 470         git commit -a -m "Make it bigger"
 471        ) &&
 472        (cd dst &&
 473         modify s/5/43/ stuff &&
 474         git commit -a -m "Independent discovery of 5->43"
 475        )
 476'
 477
 478test_expect_success 'git pull --rebase detects upstreamed changes' '
 479        (cd dst &&
 480         git pull --rebase &&
 481         test -z "$(git ls-files -u)"
 482        )
 483'
 484
 485test_expect_success 'setup for avoiding reapplying old patches' '
 486        (cd dst &&
 487         test_might_fail git rebase --abort &&
 488         git reset --hard origin/master
 489        ) &&
 490        git clone --bare src src-replace.git &&
 491        rm -rf src &&
 492        mv src-replace.git src &&
 493        (cd dst &&
 494         modify s/2/22/ stuff &&
 495         git commit -a -m "Change 2" &&
 496         modify s/3/33/ stuff &&
 497         git commit -a -m "Change 3" &&
 498         modify s/4/44/ stuff &&
 499         git commit -a -m "Change 4" &&
 500         git push &&
 501
 502         modify s/44/55/ stuff &&
 503         git commit --amend -a -m "Modified Change 4"
 504        )
 505'
 506
 507test_expect_success 'git pull --rebase does not reapply old patches' '
 508        (cd dst &&
 509         test_must_fail git pull --rebase &&
 510         test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
 511        )
 512'
 513
 514test_expect_success 'git pull --rebase against local branch' '
 515        git checkout -b copy2 to-rebase-orig &&
 516        git pull --rebase . to-rebase &&
 517        test "conflicting modification" = "$(cat file)" &&
 518        test file = "$(cat file2)"
 519'
 520
 521test_done