t / t5520-pull.shon commit t5520: test for failure if index has unresolved entries (05438af)
   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
  90        git branch copy master &&
  91        git config branch.copy.remote . &&
  92        git config branch.copy.merge refs/heads/master &&
  93        echo updated >file &&
  94        git commit -a -m updated &&
  95        git checkout copy &&
  96        test "$(cat file)" = file &&
  97        git pull &&
  98        test "$(cat file)" = updated
  99'
 100
 101test_expect_success 'the default remote . should not break explicit pull' '
 102        git checkout -b second master^ &&
 103        echo modified >file &&
 104        git commit -a -m modified &&
 105        git checkout copy &&
 106        git reset --hard HEAD^ &&
 107        test "$(cat file)" = file &&
 108        git pull . second &&
 109        test "$(cat file)" = modified
 110'
 111
 112test_expect_success 'fail if wildcard spec does not match any refs' '
 113        git checkout -b test copy^ &&
 114        test_when_finished "git checkout -f copy && git branch -D test" &&
 115        test "$(cat file)" = file &&
 116        test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 117        test_i18ngrep "no candidates for merging" err &&
 118        test "$(cat file)" = file
 119'
 120
 121test_expect_success 'fail if no branches specified with non-default remote' '
 122        git remote add test_remote . &&
 123        test_when_finished "git remote remove test_remote" &&
 124        git checkout -b test copy^ &&
 125        test_when_finished "git checkout -f copy && git branch -D test" &&
 126        test "$(cat file)" = file &&
 127        test_config branch.test.remote origin &&
 128        test_must_fail git pull test_remote 2>err &&
 129        test_i18ngrep "specify a branch on the command line" err &&
 130        test "$(cat file)" = file
 131'
 132
 133test_expect_success 'fail if not on a branch' '
 134        git remote add origin . &&
 135        test_when_finished "git remote remove origin" &&
 136        git checkout HEAD^ &&
 137        test_when_finished "git checkout -f copy" &&
 138        test "$(cat file)" = file &&
 139        test_must_fail git pull 2>err &&
 140        test_i18ngrep "not currently on a branch" err &&
 141        test "$(cat file)" = file
 142'
 143
 144test_expect_success 'fail if no configuration for current branch' '
 145        git remote add test_remote . &&
 146        test_when_finished "git remote remove test_remote" &&
 147        git checkout -b test copy^ &&
 148        test_when_finished "git checkout -f copy && git branch -D test" &&
 149        test_config branch.test.remote test_remote &&
 150        test "$(cat file)" = file &&
 151        test_must_fail git pull 2>err &&
 152        test_i18ngrep "no tracking information" err &&
 153        test "$(cat file)" = file
 154'
 155
 156test_expect_success 'fail if upstream branch does not exist' '
 157        git checkout -b test copy^ &&
 158        test_when_finished "git checkout -f copy && git branch -D test" &&
 159        test_config branch.test.remote . &&
 160        test_config branch.test.merge refs/heads/nonexisting &&
 161        test "$(cat file)" = file &&
 162        test_must_fail git pull 2>err &&
 163        test_i18ngrep "no such ref was fetched" err &&
 164        test "$(cat file)" = file
 165'
 166
 167test_expect_success 'fail if the index has unresolved entries' '
 168        git checkout -b third second^ &&
 169        test_when_finished "git checkout -f copy && git branch -D third" &&
 170        test "$(cat file)" = file &&
 171        test_commit modified2 file &&
 172        test -z "$(git ls-files -u)" &&
 173        test_must_fail git pull . second &&
 174        test -n "$(git ls-files -u)" &&
 175        cp file expected &&
 176        test_must_fail git pull . second 2>err &&
 177        test_i18ngrep "Pull is not possible because you have unmerged files" err &&
 178        test_cmp expected file &&
 179        git add file &&
 180        test -z "$(git ls-files -u)" &&
 181        test_must_fail git pull . second 2>err &&
 182        test_i18ngrep "You have not concluded your merge" err &&
 183        test_cmp expected file
 184'
 185
 186test_expect_success '--rebase' '
 187        git branch to-rebase &&
 188        echo modified again > file &&
 189        git commit -m file file &&
 190        git checkout to-rebase &&
 191        echo new > file2 &&
 192        git add file2 &&
 193        git commit -m "new file" &&
 194        git tag before-rebase &&
 195        git pull --rebase . copy &&
 196        test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
 197        test new = "$(git show HEAD:file2)"
 198'
 199test_expect_success 'pull.rebase' '
 200        git reset --hard before-rebase &&
 201        test_config pull.rebase true &&
 202        git pull . copy &&
 203        test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
 204        test new = "$(git show HEAD:file2)"
 205'
 206
 207test_expect_success 'branch.to-rebase.rebase' '
 208        git reset --hard before-rebase &&
 209        test_config branch.to-rebase.rebase true &&
 210        git pull . copy &&
 211        test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
 212        test new = "$(git show HEAD:file2)"
 213'
 214
 215test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 216        git reset --hard before-rebase &&
 217        test_config pull.rebase true &&
 218        test_config branch.to-rebase.rebase false &&
 219        git pull . copy &&
 220        test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
 221        test new = "$(git show HEAD:file2)"
 222'
 223
 224# add a feature branch, keep-merge, that is merged into master, so the
 225# test can try preserving the merge commit (or not) with various
 226# --rebase flags/pull.rebase settings.
 227test_expect_success 'preserve merge setup' '
 228        git reset --hard before-rebase &&
 229        git checkout -b keep-merge second^ &&
 230        test_commit file3 &&
 231        git checkout to-rebase &&
 232        git merge keep-merge &&
 233        git tag before-preserve-rebase
 234'
 235
 236test_expect_success 'pull.rebase=false create a new merge commit' '
 237        git reset --hard before-preserve-rebase &&
 238        test_config pull.rebase false &&
 239        git pull . copy &&
 240        test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
 241        test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
 242        test file3 = "$(git show HEAD:file3.t)"
 243'
 244
 245test_expect_success 'pull.rebase=true flattens keep-merge' '
 246        git reset --hard before-preserve-rebase &&
 247        test_config pull.rebase true &&
 248        git pull . copy &&
 249        test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
 250        test file3 = "$(git show HEAD:file3.t)"
 251'
 252
 253test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 254        git reset --hard before-preserve-rebase &&
 255        test_config pull.rebase 1 &&
 256        git pull . copy &&
 257        test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
 258        test file3 = "$(git show HEAD:file3.t)"
 259'
 260
 261test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' '
 262        git reset --hard before-preserve-rebase &&
 263        test_config pull.rebase preserve &&
 264        git pull . copy &&
 265        test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
 266        test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
 267'
 268
 269test_expect_success 'pull.rebase=invalid fails' '
 270        git reset --hard before-preserve-rebase &&
 271        test_config pull.rebase invalid &&
 272        ! git pull . copy
 273'
 274
 275test_expect_success '--rebase=false create a new merge commit' '
 276        git reset --hard before-preserve-rebase &&
 277        test_config pull.rebase true &&
 278        git pull --rebase=false . copy &&
 279        test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
 280        test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
 281        test file3 = "$(git show HEAD:file3.t)"
 282'
 283
 284test_expect_success '--rebase=true rebases and flattens keep-merge' '
 285        git reset --hard before-preserve-rebase &&
 286        test_config pull.rebase preserve &&
 287        git pull --rebase=true . copy &&
 288        test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
 289        test file3 = "$(git show HEAD:file3.t)"
 290'
 291
 292test_expect_success '--rebase=preserve rebases and merges keep-merge' '
 293        git reset --hard before-preserve-rebase &&
 294        test_config pull.rebase true &&
 295        git pull --rebase=preserve . copy &&
 296        test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
 297        test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
 298'
 299
 300test_expect_success '--rebase=invalid fails' '
 301        git reset --hard before-preserve-rebase &&
 302        ! git pull --rebase=invalid . copy
 303'
 304
 305test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
 306        git reset --hard before-preserve-rebase &&
 307        test_config pull.rebase preserve &&
 308        git pull --rebase . copy &&
 309        test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
 310        test file3 = "$(git show HEAD:file3.t)"
 311'
 312
 313test_expect_success '--rebase with rebased upstream' '
 314
 315        git remote add -f me . &&
 316        git checkout copy &&
 317        git tag copy-orig &&
 318        git reset --hard HEAD^ &&
 319        echo conflicting modification > file &&
 320        git commit -m conflict file &&
 321        git checkout to-rebase &&
 322        echo file > file2 &&
 323        git commit -m to-rebase file2 &&
 324        git tag to-rebase-orig &&
 325        git pull --rebase me copy &&
 326        test "conflicting modification" = "$(cat file)" &&
 327        test file = "$(cat file2)"
 328
 329'
 330
 331test_expect_success '--rebase with rebased default upstream' '
 332
 333        git update-ref refs/remotes/me/copy copy-orig &&
 334        git checkout --track -b to-rebase2 me/copy &&
 335        git reset --hard to-rebase-orig &&
 336        git pull --rebase &&
 337        test "conflicting modification" = "$(cat file)" &&
 338        test file = "$(cat file2)"
 339
 340'
 341
 342test_expect_success 'rebased upstream + fetch + pull --rebase' '
 343
 344        git update-ref refs/remotes/me/copy copy-orig &&
 345        git reset --hard to-rebase-orig &&
 346        git checkout --track -b to-rebase3 me/copy &&
 347        git reset --hard to-rebase-orig &&
 348        git fetch &&
 349        git pull --rebase &&
 350        test "conflicting modification" = "$(cat file)" &&
 351        test file = "$(cat file2)"
 352
 353'
 354
 355test_expect_success 'pull --rebase dies early with dirty working directory' '
 356
 357        git checkout to-rebase &&
 358        git update-ref refs/remotes/me/copy copy^ &&
 359        COPY="$(git rev-parse --verify me/copy)" &&
 360        git rebase --onto $COPY copy &&
 361        test_config branch.to-rebase.remote me &&
 362        test_config branch.to-rebase.merge refs/heads/copy &&
 363        test_config branch.to-rebase.rebase true &&
 364        echo dirty >> file &&
 365        git add file &&
 366        test_must_fail git pull &&
 367        test "$COPY" = "$(git rev-parse --verify me/copy)" &&
 368        git checkout HEAD -- file &&
 369        git pull &&
 370        test "$COPY" != "$(git rev-parse --verify me/copy)"
 371
 372'
 373
 374test_expect_success 'pull --rebase works on branch yet to be born' '
 375        git rev-parse master >expect &&
 376        mkdir empty_repo &&
 377        (cd empty_repo &&
 378         git init &&
 379         git pull --rebase .. master &&
 380         git rev-parse HEAD >../actual
 381        ) &&
 382        test_cmp expect actual
 383'
 384
 385test_expect_success 'setup for detecting upstreamed changes' '
 386        mkdir src &&
 387        (cd src &&
 388         git init &&
 389         printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
 390         git add stuff &&
 391         git commit -m "Initial revision"
 392        ) &&
 393        git clone src dst &&
 394        (cd src &&
 395         modify s/5/43/ stuff &&
 396         git commit -a -m "5->43" &&
 397         modify s/6/42/ stuff &&
 398         git commit -a -m "Make it bigger"
 399        ) &&
 400        (cd dst &&
 401         modify s/5/43/ stuff &&
 402         git commit -a -m "Independent discovery of 5->43"
 403        )
 404'
 405
 406test_expect_success 'git pull --rebase detects upstreamed changes' '
 407        (cd dst &&
 408         git pull --rebase &&
 409         test -z "$(git ls-files -u)"
 410        )
 411'
 412
 413test_expect_success 'setup for avoiding reapplying old patches' '
 414        (cd dst &&
 415         test_might_fail git rebase --abort &&
 416         git reset --hard origin/master
 417        ) &&
 418        git clone --bare src src-replace.git &&
 419        rm -rf src &&
 420        mv src-replace.git src &&
 421        (cd dst &&
 422         modify s/2/22/ stuff &&
 423         git commit -a -m "Change 2" &&
 424         modify s/3/33/ stuff &&
 425         git commit -a -m "Change 3" &&
 426         modify s/4/44/ stuff &&
 427         git commit -a -m "Change 4" &&
 428         git push &&
 429
 430         modify s/44/55/ stuff &&
 431         git commit --amend -a -m "Modified Change 4"
 432        )
 433'
 434
 435test_expect_success 'git pull --rebase does not reapply old patches' '
 436        (cd dst &&
 437         test_must_fail git pull --rebase &&
 438         test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
 439        )
 440'
 441
 442test_expect_success 'git pull --rebase against local branch' '
 443        git checkout -b copy2 to-rebase-orig &&
 444        git pull --rebase . to-rebase &&
 445        test "conflicting modification" = "$(cat file)" &&
 446        test file = "$(cat file2)"
 447'
 448
 449test_done