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