t / t5505-remote.shon commit Merge branch 'lt/core-optim' (dccb3a6)
   1#!/bin/sh
   2
   3test_description='git remote porcelain-ish'
   4
   5. ./test-lib.sh
   6
   7setup_repository () {
   8        mkdir "$1" && (
   9        cd "$1" &&
  10        git init &&
  11        >file &&
  12        git add file &&
  13        test_tick &&
  14        git commit -m "Initial" &&
  15        git checkout -b side &&
  16        >elif &&
  17        git add elif &&
  18        test_tick &&
  19        git commit -m "Second" &&
  20        git checkout master
  21        )
  22}
  23
  24tokens_match () {
  25        echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect &&
  26        echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual &&
  27        test_cmp expect actual
  28}
  29
  30check_remote_track () {
  31        actual=$(git remote show "$1" | sed -n -e '$p') &&
  32        shift &&
  33        tokens_match "$*" "$actual"
  34}
  35
  36check_tracking_branch () {
  37        f="" &&
  38        r=$(git for-each-ref "--format=%(refname)" |
  39                sed -ne "s|^refs/remotes/$1/||p") &&
  40        shift &&
  41        tokens_match "$*" "$r"
  42}
  43
  44test_expect_success setup '
  45
  46        setup_repository one &&
  47        setup_repository two &&
  48        (
  49                cd two && git branch another
  50        ) &&
  51        git clone one test
  52
  53'
  54
  55test_expect_success 'remote information for the origin' '
  56(
  57        cd test &&
  58        tokens_match origin "$(git remote)" &&
  59        check_remote_track origin master side &&
  60        check_tracking_branch origin HEAD master side
  61)
  62'
  63
  64test_expect_success 'add another remote' '
  65(
  66        cd test &&
  67        git remote add -f second ../two &&
  68        tokens_match "origin second" "$(git remote)" &&
  69        check_remote_track origin master side &&
  70        check_remote_track second master side another &&
  71        check_tracking_branch second master side another &&
  72        git for-each-ref "--format=%(refname)" refs/remotes |
  73        sed -e "/^refs\/remotes\/origin\//d" \
  74            -e "/^refs\/remotes\/second\//d" >actual &&
  75        >expect &&
  76        test_cmp expect actual
  77)
  78'
  79
  80test_expect_success 'remote forces tracking branches' '
  81(
  82        cd test &&
  83        case `git config remote.second.fetch` in
  84        +*) true ;;
  85         *) false ;;
  86        esac
  87)
  88'
  89
  90test_expect_success 'remove remote' '
  91(
  92        cd test &&
  93        git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master &&
  94        git remote rm second
  95)
  96'
  97
  98test_expect_success 'remove remote' '
  99(
 100        cd test &&
 101        tokens_match origin "$(git remote)" &&
 102        check_remote_track origin master side &&
 103        git for-each-ref "--format=%(refname)" refs/remotes |
 104        sed -e "/^refs\/remotes\/origin\//d" >actual &&
 105        >expect &&
 106        test_cmp expect actual
 107)
 108'
 109
 110cat > test/expect << EOF
 111* remote origin
 112  URL: $(pwd)/one/.git
 113  Remote branch merged with 'git pull' while on branch master
 114    master
 115  New remote branch (next fetch will store in remotes/origin)
 116    master
 117  Tracked remote branches
 118    side master
 119  Local branches pushed with 'git push'
 120    master:upstream +refs/tags/lastbackup
 121EOF
 122
 123test_expect_success 'show' '
 124        (cd test &&
 125         git config --add remote.origin.fetch \
 126                refs/heads/master:refs/heads/upstream &&
 127         git fetch &&
 128         git branch -d -r origin/master &&
 129         (cd ../one &&
 130          echo 1 > file &&
 131          test_tick &&
 132          git commit -m update file) &&
 133         git config remote.origin.push \
 134                refs/heads/master:refs/heads/upstream &&
 135         git config --add remote.origin.push \
 136                +refs/tags/lastbackup &&
 137         git remote show origin > output &&
 138         git diff expect output)
 139'
 140
 141test_expect_success 'prune' '
 142        (cd one &&
 143         git branch -m side side2) &&
 144        (cd test &&
 145         git fetch origin &&
 146         git remote prune origin &&
 147         git rev-parse refs/remotes/origin/side2 &&
 148         ! git rev-parse refs/remotes/origin/side)
 149'
 150
 151test_expect_success 'add --mirror && prune' '
 152        (mkdir mirror &&
 153         cd mirror &&
 154         git init &&
 155         git remote add --mirror -f origin ../one) &&
 156        (cd one &&
 157         git branch -m side2 side) &&
 158        (cd mirror &&
 159         git rev-parse --verify refs/heads/side2 &&
 160         ! git rev-parse --verify refs/heads/side &&
 161         git fetch origin &&
 162         git remote prune origin &&
 163         ! git rev-parse --verify refs/heads/side2 &&
 164         git rev-parse --verify refs/heads/side)
 165'
 166
 167cat > one/expect << EOF
 168  apis/master
 169  apis/side
 170  drosophila/another
 171  drosophila/master
 172  drosophila/side
 173EOF
 174
 175test_expect_success 'update' '
 176
 177        (cd one &&
 178         git remote add drosophila ../two &&
 179         git remote add apis ../mirror &&
 180         git remote update &&
 181         git branch -r > output &&
 182         git diff expect output)
 183
 184'
 185
 186cat > one/expect << EOF
 187  drosophila/another
 188  drosophila/master
 189  drosophila/side
 190  manduca/master
 191  manduca/side
 192  megaloprepus/master
 193  megaloprepus/side
 194EOF
 195
 196test_expect_success 'update with arguments' '
 197
 198        (cd one &&
 199         for b in $(git branch -r)
 200         do
 201                git branch -r -d $b || break
 202         done &&
 203         git remote add manduca ../mirror &&
 204         git remote add megaloprepus ../mirror &&
 205         git config remotes.phobaeticus "drosophila megaloprepus" &&
 206         git config remotes.titanus manduca &&
 207         git remote update phobaeticus titanus &&
 208         git branch -r > output &&
 209         git diff expect output)
 210
 211'
 212
 213cat > one/expect << EOF
 214  apis/master
 215  apis/side
 216  manduca/master
 217  manduca/side
 218  megaloprepus/master
 219  megaloprepus/side
 220EOF
 221
 222test_expect_success 'update default' '
 223
 224        (cd one &&
 225         for b in $(git branch -r)
 226         do
 227                git branch -r -d $b || break
 228         done &&
 229         git config remote.drosophila.skipDefaultUpdate true &&
 230         git remote update default &&
 231         git branch -r > output &&
 232         git diff expect output)
 233
 234'
 235
 236cat > one/expect << EOF
 237  drosophila/another
 238  drosophila/master
 239  drosophila/side
 240EOF
 241
 242test_expect_success 'update default (overridden, with funny whitespace)' '
 243
 244        (cd one &&
 245         for b in $(git branch -r)
 246         do
 247                git branch -r -d $b || break
 248         done &&
 249         git config remotes.default "$(printf "\t drosophila  \n")" &&
 250         git remote update default &&
 251         git branch -r > output &&
 252         git diff expect output)
 253
 254'
 255
 256test_expect_success '"remote show" does not show symbolic refs' '
 257
 258        git clone one three &&
 259        (cd three &&
 260         git remote show origin > output &&
 261         ! grep HEAD < output &&
 262         ! grep -i stale < output)
 263
 264'
 265
 266test_expect_success 'reject adding remote with an invalid name' '
 267
 268        ! git remote add some:url desired-name
 269
 270'
 271
 272test_done