t / t5505-remote.shon commit more tr portability test script fixes (e85fe4d)
   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        diff -u 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        diff -u 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        diff -u 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
 109EOF
 110
 111test_expect_success 'show' '
 112        (cd test &&
 113         git config --add remote.origin.fetch \
 114                refs/heads/master:refs/heads/upstream &&
 115         git fetch &&
 116         git branch -d -r origin/master &&
 117         (cd ../one &&
 118          echo 1 > file &&
 119          test_tick &&
 120          git commit -m update file) &&
 121         git remote show origin > output &&
 122         git diff expect output)
 123'
 124
 125test_expect_success 'prune' '
 126        (cd one &&
 127         git branch -m side side2) &&
 128        (cd test &&
 129         git fetch origin &&
 130         git remote prune origin &&
 131         git rev-parse refs/remotes/origin/side2 &&
 132         ! git rev-parse refs/remotes/origin/side)
 133'
 134
 135test_expect_success 'add --mirror && prune' '
 136        (mkdir mirror &&
 137         cd mirror &&
 138         git init &&
 139         git remote add --mirror -f origin ../one) &&
 140        (cd one &&
 141         git branch -m side2 side) &&
 142        (cd mirror &&
 143         git rev-parse --verify refs/heads/side2 &&
 144         ! git rev-parse --verify refs/heads/side &&
 145         git fetch origin &&
 146         git remote prune origin &&
 147         ! git rev-parse --verify refs/heads/side2 &&
 148         git rev-parse --verify refs/heads/side)
 149'
 150
 151cat > one/expect << EOF
 152  apis/master
 153  apis/side
 154  drosophila/another
 155  drosophila/master
 156  drosophila/side
 157EOF
 158
 159test_expect_success 'update' '
 160
 161        (cd one &&
 162         git remote add drosophila ../two &&
 163         git remote add apis ../mirror &&
 164         git remote update &&
 165         git branch -r > output &&
 166         git diff expect output)
 167
 168'
 169
 170cat > one/expect << EOF
 171  drosophila/another
 172  drosophila/master
 173  drosophila/side
 174  manduca/master
 175  manduca/side
 176  megaloprepus/master
 177  megaloprepus/side
 178EOF
 179
 180test_expect_success 'update with arguments' '
 181
 182        (cd one &&
 183         for b in $(git branch -r)
 184         do
 185                git branch -r -d $b || break
 186         done &&
 187         git remote add manduca ../mirror &&
 188         git remote add megaloprepus ../mirror &&
 189         git config remotes.phobaeticus "drosophila megaloprepus" &&
 190         git config remotes.titanus manduca &&
 191         git remote update phobaeticus titanus &&
 192         git branch -r > output &&
 193         git diff expect output)
 194
 195'
 196
 197cat > one/expect << EOF
 198  apis/master
 199  apis/side
 200  manduca/master
 201  manduca/side
 202  megaloprepus/master
 203  megaloprepus/side
 204EOF
 205
 206test_expect_success 'update default' '
 207
 208        (cd one &&
 209         for b in $(git branch -r)
 210         do
 211                git branch -r -d $b || break
 212         done &&
 213         git config remote.drosophila.skipDefaultUpdate true &&
 214         git remote update default &&
 215         git branch -r > output &&
 216         git diff expect output)
 217
 218'
 219
 220cat > one/expect << EOF
 221  drosophila/another
 222  drosophila/master
 223  drosophila/side
 224EOF
 225
 226test_expect_success 'update default (overridden, with funny whitespace)' '
 227
 228        (cd one &&
 229         for b in $(git branch -r)
 230         do
 231                git branch -r -d $b || break
 232         done &&
 233         git config remotes.default "$(printf "\t drosophila  \n")" &&
 234         git remote update default &&
 235         git branch -r > output &&
 236         git diff expect output)
 237
 238'
 239
 240test_done