t / t5520-pull.shon commit apply: reject input that touches outside the working area (c536c07)
   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
  12D=`pwd`
  13
  14test_expect_success setup '
  15
  16        echo file >file &&
  17        git add file &&
  18        git commit -a -m original
  19
  20'
  21
  22test_expect_success 'pulling into void' '
  23        mkdir cloned &&
  24        cd cloned &&
  25        git init &&
  26        git pull ..
  27'
  28
  29cd "$D"
  30
  31test_expect_success 'checking the results' '
  32        test -f file &&
  33        test -f cloned/file &&
  34        test_cmp file cloned/file
  35'
  36
  37test_expect_success 'pulling into void using master:master' '
  38        mkdir cloned-uho &&
  39        (
  40                cd cloned-uho &&
  41                git init &&
  42                git pull .. master:master
  43        ) &&
  44        test -f file &&
  45        test -f cloned-uho/file &&
  46        test_cmp file cloned-uho/file
  47'
  48
  49test_expect_success 'pulling into void does not overwrite untracked files' '
  50        git init cloned-untracked &&
  51        (
  52                cd cloned-untracked &&
  53                echo untracked >file &&
  54                test_must_fail git pull .. master &&
  55                echo untracked >expect &&
  56                test_cmp expect file
  57        )
  58'
  59
  60test_expect_success 'pulling into void does not overwrite staged files' '
  61        git init cloned-staged-colliding &&
  62        (
  63                cd cloned-staged-colliding &&
  64                echo "alternate content" >file &&
  65                git add file &&
  66                test_must_fail git pull .. master &&
  67                echo "alternate content" >expect &&
  68                test_cmp expect file &&
  69                git cat-file blob :file >file.index &&
  70                test_cmp expect file.index
  71        )
  72'
  73
  74
  75test_expect_success 'pulling into void does not remove new staged files' '
  76        git init cloned-staged-new &&
  77        (
  78                cd cloned-staged-new &&
  79                echo "new tracked file" >newfile &&
  80                git add newfile &&
  81                git pull .. master &&
  82                echo "new tracked file" >expect &&
  83                test_cmp expect newfile &&
  84                git cat-file blob :newfile >newfile.index &&
  85                test_cmp expect newfile.index
  86        )
  87'
  88
  89test_expect_success 'test . as a remote' '
  90
  91        git branch copy master &&
  92        git config branch.copy.remote . &&
  93        git config branch.copy.merge refs/heads/master &&
  94        echo updated >file &&
  95        git commit -a -m updated &&
  96        git checkout copy &&
  97        test `cat file` = file &&
  98        git pull &&
  99        test `cat file` = updated
 100'
 101
 102test_expect_success 'the default remote . should not break explicit pull' '
 103        git checkout -b second master^ &&
 104        echo modified >file &&
 105        git commit -a -m modified &&
 106        git checkout copy &&
 107        git reset --hard HEAD^ &&
 108        test `cat file` = file &&
 109        git pull . second &&
 110        test `cat file` = modified
 111'
 112
 113test_expect_success '--rebase' '
 114        git branch to-rebase &&
 115        echo modified again > file &&
 116        git commit -m file file &&
 117        git checkout to-rebase &&
 118        echo new > file2 &&
 119        git add file2 &&
 120        git commit -m "new file" &&
 121        git tag before-rebase &&
 122        git pull --rebase . copy &&
 123        test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
 124        test new = $(git show HEAD:file2)
 125'
 126test_expect_success 'pull.rebase' '
 127        git reset --hard before-rebase &&
 128        test_config pull.rebase true &&
 129        git pull . copy &&
 130        test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
 131        test new = $(git show HEAD:file2)
 132'
 133
 134test_expect_success 'branch.to-rebase.rebase' '
 135        git reset --hard before-rebase &&
 136        test_config branch.to-rebase.rebase true &&
 137        git pull . copy &&
 138        test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
 139        test new = $(git show HEAD:file2)
 140'
 141
 142test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 143        git reset --hard before-rebase &&
 144        test_config pull.rebase true &&
 145        test_config branch.to-rebase.rebase false &&
 146        git pull . copy &&
 147        test $(git rev-parse HEAD^) != $(git rev-parse copy) &&
 148        test new = $(git show HEAD:file2)
 149'
 150
 151# add a feature branch, keep-merge, that is merged into master, so the
 152# test can try preserving the merge commit (or not) with various
 153# --rebase flags/pull.rebase settings.
 154test_expect_success 'preserve merge setup' '
 155        git reset --hard before-rebase &&
 156        git checkout -b keep-merge second^ &&
 157        test_commit file3 &&
 158        git checkout to-rebase &&
 159        git merge keep-merge &&
 160        git tag before-preserve-rebase
 161'
 162
 163test_expect_success 'pull.rebase=false create a new merge commit' '
 164        git reset --hard before-preserve-rebase &&
 165        test_config pull.rebase false &&
 166        git pull . copy &&
 167        test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&
 168        test $(git rev-parse HEAD^2) = $(git rev-parse copy) &&
 169        test file3 = $(git show HEAD:file3.t)
 170'
 171
 172test_expect_success 'pull.rebase=true flattens keep-merge' '
 173        git reset --hard before-preserve-rebase &&
 174        test_config pull.rebase true &&
 175        git pull . copy &&
 176        test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
 177        test file3 = $(git show HEAD:file3.t)
 178'
 179
 180test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 181        git reset --hard before-preserve-rebase &&
 182        test_config pull.rebase 1 &&
 183        git pull . copy &&
 184        test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
 185        test file3 = $(git show HEAD:file3.t)
 186'
 187
 188test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' '
 189        git reset --hard before-preserve-rebase &&
 190        test_config pull.rebase preserve &&
 191        git pull . copy &&
 192        test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
 193        test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
 194'
 195
 196test_expect_success 'pull.rebase=invalid fails' '
 197        git reset --hard before-preserve-rebase &&
 198        test_config pull.rebase invalid &&
 199        ! git pull . copy
 200'
 201
 202test_expect_success '--rebase=false create a new merge commit' '
 203        git reset --hard before-preserve-rebase &&
 204        test_config pull.rebase true &&
 205        git pull --rebase=false . copy &&
 206        test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&
 207        test $(git rev-parse HEAD^2) = $(git rev-parse copy) &&
 208        test file3 = $(git show HEAD:file3.t)
 209'
 210
 211test_expect_success '--rebase=true rebases and flattens keep-merge' '
 212        git reset --hard before-preserve-rebase &&
 213        test_config pull.rebase preserve &&
 214        git pull --rebase=true . copy &&
 215        test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
 216        test file3 = $(git show HEAD:file3.t)
 217'
 218
 219test_expect_success '--rebase=preserve rebases and merges keep-merge' '
 220        git reset --hard before-preserve-rebase &&
 221        test_config pull.rebase true &&
 222        git pull --rebase=preserve . copy &&
 223        test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
 224        test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
 225'
 226
 227test_expect_success '--rebase=invalid fails' '
 228        git reset --hard before-preserve-rebase &&
 229        ! git pull --rebase=invalid . copy
 230'
 231
 232test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
 233        git reset --hard before-preserve-rebase &&
 234        test_config pull.rebase preserve &&
 235        git pull --rebase . copy &&
 236        test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
 237        test file3 = $(git show HEAD:file3.t)
 238'
 239
 240test_expect_success '--rebase with rebased upstream' '
 241
 242        git remote add -f me . &&
 243        git checkout copy &&
 244        git tag copy-orig &&
 245        git reset --hard HEAD^ &&
 246        echo conflicting modification > file &&
 247        git commit -m conflict file &&
 248        git checkout to-rebase &&
 249        echo file > file2 &&
 250        git commit -m to-rebase file2 &&
 251        git tag to-rebase-orig &&
 252        git pull --rebase me copy &&
 253        test "conflicting modification" = "$(cat file)" &&
 254        test file = $(cat file2)
 255
 256'
 257
 258test_expect_success '--rebase with rebased default upstream' '
 259
 260        git update-ref refs/remotes/me/copy copy-orig &&
 261        git checkout --track -b to-rebase2 me/copy &&
 262        git reset --hard to-rebase-orig &&
 263        git pull --rebase &&
 264        test "conflicting modification" = "$(cat file)" &&
 265        test file = $(cat file2)
 266
 267'
 268
 269test_expect_success 'rebased upstream + fetch + pull --rebase' '
 270
 271        git update-ref refs/remotes/me/copy copy-orig &&
 272        git reset --hard to-rebase-orig &&
 273        git checkout --track -b to-rebase3 me/copy &&
 274        git reset --hard to-rebase-orig &&
 275        git fetch &&
 276        git pull --rebase &&
 277        test "conflicting modification" = "$(cat file)" &&
 278        test file = "$(cat file2)"
 279
 280'
 281
 282test_expect_success 'pull --rebase dies early with dirty working directory' '
 283
 284        git checkout to-rebase &&
 285        git update-ref refs/remotes/me/copy copy^ &&
 286        COPY=$(git rev-parse --verify me/copy) &&
 287        git rebase --onto $COPY copy &&
 288        test_config branch.to-rebase.remote me &&
 289        test_config branch.to-rebase.merge refs/heads/copy &&
 290        test_config branch.to-rebase.rebase true &&
 291        echo dirty >> file &&
 292        git add file &&
 293        test_must_fail git pull &&
 294        test $COPY = $(git rev-parse --verify me/copy) &&
 295        git checkout HEAD -- file &&
 296        git pull &&
 297        test $COPY != $(git rev-parse --verify me/copy)
 298
 299'
 300
 301test_expect_success 'pull --rebase works on branch yet to be born' '
 302        git rev-parse master >expect &&
 303        mkdir empty_repo &&
 304        (cd empty_repo &&
 305         git init &&
 306         git pull --rebase .. master &&
 307         git rev-parse HEAD >../actual
 308        ) &&
 309        test_cmp expect actual
 310'
 311
 312test_expect_success 'setup for detecting upstreamed changes' '
 313        mkdir src &&
 314        (cd src &&
 315         git init &&
 316         printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
 317         git add stuff &&
 318         git commit -m "Initial revision"
 319        ) &&
 320        git clone src dst &&
 321        (cd src &&
 322         modify s/5/43/ stuff &&
 323         git commit -a -m "5->43" &&
 324         modify s/6/42/ stuff &&
 325         git commit -a -m "Make it bigger"
 326        ) &&
 327        (cd dst &&
 328         modify s/5/43/ stuff &&
 329         git commit -a -m "Independent discovery of 5->43"
 330        )
 331'
 332
 333test_expect_success 'git pull --rebase detects upstreamed changes' '
 334        (cd dst &&
 335         git pull --rebase &&
 336         test -z "$(git ls-files -u)"
 337        )
 338'
 339
 340test_expect_success 'setup for avoiding reapplying old patches' '
 341        (cd dst &&
 342         test_might_fail git rebase --abort &&
 343         git reset --hard origin/master
 344        ) &&
 345        git clone --bare src src-replace.git &&
 346        rm -rf src &&
 347        mv src-replace.git src &&
 348        (cd dst &&
 349         modify s/2/22/ stuff &&
 350         git commit -a -m "Change 2" &&
 351         modify s/3/33/ stuff &&
 352         git commit -a -m "Change 3" &&
 353         modify s/4/44/ stuff &&
 354         git commit -a -m "Change 4" &&
 355         git push &&
 356
 357         modify s/44/55/ stuff &&
 358         git commit --amend -a -m "Modified Change 4"
 359        )
 360'
 361
 362test_expect_success 'git pull --rebase does not reapply old patches' '
 363        (cd dst &&
 364         test_must_fail git pull --rebase &&
 365         test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
 366        )
 367'
 368
 369test_expect_success 'git pull --rebase against local branch' '
 370        git checkout -b copy2 to-rebase-orig &&
 371        git pull --rebase . to-rebase &&
 372        test "conflicting modification" = "$(cat file)" &&
 373        test file = "$(cat file2)"
 374'
 375
 376test_done