t / t5505-remote.shon commit Documentation/git-checkout: Update summary to reflect current abilities (76ce946)
   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 'remove remote' '
  81(
  82        cd test &&
  83        git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master &&
  84        git remote rm second
  85)
  86'
  87
  88test_expect_success 'remove remote' '
  89(
  90        cd test &&
  91        tokens_match origin "$(git remote)" &&
  92        check_remote_track origin master side &&
  93        git for-each-ref "--format=%(refname)" refs/remotes |
  94        sed -e "/^refs\/remotes\/origin\//d" >actual &&
  95        >expect &&
  96        test_cmp expect actual
  97)
  98'
  99
 100cat > test/expect << EOF
 101* remote origin
 102  URL: $(pwd)/one/.git
 103  Remote branch merged with 'git pull' while on branch master
 104    master
 105  New remote branch (next fetch will store in remotes/origin)
 106    master
 107  Tracked remote branches
 108    side master
 109  Local branches pushed with 'git push'
 110    master:upstream +refs/tags/lastbackup
 111EOF
 112
 113test_expect_success 'show' '
 114        (cd test &&
 115         git config --add remote.origin.fetch \
 116                refs/heads/master:refs/heads/upstream &&
 117         git fetch &&
 118         git branch -d -r origin/master &&
 119         (cd ../one &&
 120          echo 1 > file &&
 121          test_tick &&
 122          git commit -m update file) &&
 123         git config remote.origin.push \
 124                refs/heads/master:refs/heads/upstream &&
 125         git config --add remote.origin.push \
 126                +refs/tags/lastbackup &&
 127         git remote show origin > output &&
 128         git diff expect output)
 129'
 130
 131test_expect_success 'prune' '
 132        (cd one &&
 133         git branch -m side side2) &&
 134        (cd test &&
 135         git fetch origin &&
 136         git remote prune origin &&
 137         git rev-parse refs/remotes/origin/side2 &&
 138         ! git rev-parse refs/remotes/origin/side)
 139'
 140
 141test_expect_success 'add --mirror && prune' '
 142        (mkdir mirror &&
 143         cd mirror &&
 144         git init &&
 145         git remote add --mirror -f origin ../one) &&
 146        (cd one &&
 147         git branch -m side2 side) &&
 148        (cd mirror &&
 149         git rev-parse --verify refs/heads/side2 &&
 150         ! git rev-parse --verify refs/heads/side &&
 151         git fetch origin &&
 152         git remote prune origin &&
 153         ! git rev-parse --verify refs/heads/side2 &&
 154         git rev-parse --verify refs/heads/side)
 155'
 156
 157cat > one/expect << EOF
 158  apis/master
 159  apis/side
 160  drosophila/another
 161  drosophila/master
 162  drosophila/side
 163EOF
 164
 165test_expect_success 'update' '
 166
 167        (cd one &&
 168         git remote add drosophila ../two &&
 169         git remote add apis ../mirror &&
 170         git remote update &&
 171         git branch -r > output &&
 172         git diff expect output)
 173
 174'
 175
 176cat > one/expect << EOF
 177  drosophila/another
 178  drosophila/master
 179  drosophila/side
 180  manduca/master
 181  manduca/side
 182  megaloprepus/master
 183  megaloprepus/side
 184EOF
 185
 186test_expect_success 'update with arguments' '
 187
 188        (cd one &&
 189         for b in $(git branch -r)
 190         do
 191                git branch -r -d $b || break
 192         done &&
 193         git remote add manduca ../mirror &&
 194         git remote add megaloprepus ../mirror &&
 195         git config remotes.phobaeticus "drosophila megaloprepus" &&
 196         git config remotes.titanus manduca &&
 197         git remote update phobaeticus titanus &&
 198         git branch -r > output &&
 199         git diff expect output)
 200
 201'
 202
 203cat > one/expect << EOF
 204  apis/master
 205  apis/side
 206  manduca/master
 207  manduca/side
 208  megaloprepus/master
 209  megaloprepus/side
 210EOF
 211
 212test_expect_success 'update default' '
 213
 214        (cd one &&
 215         for b in $(git branch -r)
 216         do
 217                git branch -r -d $b || break
 218         done &&
 219         git config remote.drosophila.skipDefaultUpdate true &&
 220         git remote update default &&
 221         git branch -r > output &&
 222         git diff expect output)
 223
 224'
 225
 226cat > one/expect << EOF
 227  drosophila/another
 228  drosophila/master
 229  drosophila/side
 230EOF
 231
 232test_expect_success 'update default (overridden, with funny whitespace)' '
 233
 234        (cd one &&
 235         for b in $(git branch -r)
 236         do
 237                git branch -r -d $b || break
 238         done &&
 239         git config remotes.default "$(printf "\t drosophila  \n")" &&
 240         git remote update default &&
 241         git branch -r > output &&
 242         git diff expect output)
 243
 244'
 245
 246test_expect_success '"remote show" does not show symbolic refs' '
 247
 248        git clone one three &&
 249        (cd three &&
 250         git remote show origin > output &&
 251         ! grep HEAD < output &&
 252         ! grep -i stale < output)
 253
 254'
 255
 256test_done