t / t5520-pull.shon commit Merge branch 'db/delta-applier' into svn-fe (a8d3d26)
   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 'test . as a remote' '
  61
  62        git branch copy master &&
  63        git config branch.copy.remote . &&
  64        git config branch.copy.merge refs/heads/master &&
  65        echo updated >file &&
  66        git commit -a -m updated &&
  67        git checkout copy &&
  68        test `cat file` = file &&
  69        git pull &&
  70        test `cat file` = updated
  71'
  72
  73test_expect_success 'the default remote . should not break explicit pull' '
  74        git checkout -b second master^ &&
  75        echo modified >file &&
  76        git commit -a -m modified &&
  77        git checkout copy &&
  78        git reset --hard HEAD^ &&
  79        test `cat file` = file &&
  80        git pull . second &&
  81        test `cat file` = modified
  82'
  83
  84test_expect_success '--rebase' '
  85        git branch to-rebase &&
  86        echo modified again > file &&
  87        git commit -m file file &&
  88        git checkout to-rebase &&
  89        echo new > file2 &&
  90        git add file2 &&
  91        git commit -m "new file" &&
  92        git tag before-rebase &&
  93        git pull --rebase . copy &&
  94        test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
  95        test new = $(git show HEAD:file2)
  96'
  97
  98test_expect_success 'branch.to-rebase.rebase' '
  99        git reset --hard before-rebase &&
 100        git config branch.to-rebase.rebase 1 &&
 101        git pull . copy &&
 102        git config branch.to-rebase.rebase 0 &&
 103        test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
 104        test new = $(git show HEAD:file2)
 105'
 106
 107test_expect_success '--rebase with rebased upstream' '
 108
 109        git remote add -f me . &&
 110        git checkout copy &&
 111        git tag copy-orig &&
 112        git reset --hard HEAD^ &&
 113        echo conflicting modification > file &&
 114        git commit -m conflict file &&
 115        git checkout to-rebase &&
 116        echo file > file2 &&
 117        git commit -m to-rebase file2 &&
 118        git tag to-rebase-orig &&
 119        git pull --rebase me copy &&
 120        test "conflicting modification" = "$(cat file)" &&
 121        test file = $(cat file2)
 122
 123'
 124
 125test_expect_success '--rebase with rebased default upstream' '
 126
 127        git update-ref refs/remotes/me/copy copy-orig &&
 128        git checkout --track -b to-rebase2 me/copy &&
 129        git reset --hard to-rebase-orig &&
 130        git pull --rebase &&
 131        test "conflicting modification" = "$(cat file)" &&
 132        test file = $(cat file2)
 133
 134'
 135
 136test_expect_success 'rebased upstream + fetch + pull --rebase' '
 137
 138        git update-ref refs/remotes/me/copy copy-orig &&
 139        git reset --hard to-rebase-orig &&
 140        git checkout --track -b to-rebase3 me/copy &&
 141        git reset --hard to-rebase-orig &&
 142        git fetch &&
 143        git pull --rebase &&
 144        test "conflicting modification" = "$(cat file)" &&
 145        test file = "$(cat file2)"
 146
 147'
 148
 149test_expect_success 'pull --rebase dies early with dirty working directory' '
 150
 151        git checkout to-rebase &&
 152        git update-ref refs/remotes/me/copy copy^ &&
 153        COPY=$(git rev-parse --verify me/copy) &&
 154        git rebase --onto $COPY copy &&
 155        git config branch.to-rebase.remote me &&
 156        git config branch.to-rebase.merge refs/heads/copy &&
 157        git config branch.to-rebase.rebase true &&
 158        echo dirty >> file &&
 159        git add file &&
 160        test_must_fail git pull &&
 161        test $COPY = $(git rev-parse --verify me/copy) &&
 162        git checkout HEAD -- file &&
 163        git pull &&
 164        test $COPY != $(git rev-parse --verify me/copy)
 165
 166'
 167
 168test_expect_success 'pull --rebase works on branch yet to be born' '
 169        git rev-parse master >expect &&
 170        mkdir empty_repo &&
 171        (cd empty_repo &&
 172         git init &&
 173         git pull --rebase .. master &&
 174         git rev-parse HEAD >../actual
 175        ) &&
 176        test_cmp expect actual
 177'
 178
 179test_expect_success 'setup for detecting upstreamed changes' '
 180        mkdir src &&
 181        (cd src &&
 182         git init &&
 183         printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
 184         git add stuff &&
 185         git commit -m "Initial revision"
 186        ) &&
 187        git clone src dst &&
 188        (cd src &&
 189         modify s/5/43/ stuff &&
 190         git commit -a -m "5->43" &&
 191         modify s/6/42/ stuff &&
 192         git commit -a -m "Make it bigger"
 193        ) &&
 194        (cd dst &&
 195         modify s/5/43/ stuff &&
 196         git commit -a -m "Independent discovery of 5->43"
 197        )
 198'
 199
 200test_expect_success 'git pull --rebase detects upstreamed changes' '
 201        (cd dst &&
 202         git pull --rebase &&
 203         test -z "$(git ls-files -u)"
 204        )
 205'
 206
 207test_expect_success 'setup for avoiding reapplying old patches' '
 208        (cd dst &&
 209         test_might_fail git rebase --abort &&
 210         git reset --hard origin/master
 211        ) &&
 212        git clone --bare src src-replace.git &&
 213        rm -rf src &&
 214        mv src-replace.git src &&
 215        (cd dst &&
 216         modify s/2/22/ stuff &&
 217         git commit -a -m "Change 2" &&
 218         modify s/3/33/ stuff &&
 219         git commit -a -m "Change 3" &&
 220         modify s/4/44/ stuff &&
 221         git commit -a -m "Change 4" &&
 222         git push &&
 223
 224         modify s/44/55/ stuff &&
 225         git commit --amend -a -m "Modified Change 4"
 226        )
 227'
 228
 229test_expect_success 'git pull --rebase does not reapply old patches' '
 230        (cd dst &&
 231         test_must_fail git pull --rebase &&
 232         test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
 233        )
 234'
 235
 236test_expect_success 'git pull --rebase against local branch' '
 237        git checkout -b copy2 to-rebase-orig &&
 238        git pull --rebase . to-rebase &&
 239        test "conflicting modification" = "$(cat file)" &&
 240        test file = "$(cat file2)"
 241'
 242
 243test_done