t / t6040-tracking-info.shon commit t: use test_expect_code instead of hand-rolled comparison (c21fc9d)
   1#!/bin/sh
   2
   3test_description='remote tracking stats'
   4
   5. ./test-lib.sh
   6
   7advance () {
   8        echo "$1" >"$1" &&
   9        git add "$1" &&
  10        test_tick &&
  11        git commit -m "$1"
  12}
  13
  14test_expect_success setup '
  15        for i in a b c;
  16        do
  17                advance $i || break
  18        done &&
  19        git clone . test &&
  20        (
  21                cd test &&
  22                git checkout -b b1 origin &&
  23                git reset --hard HEAD^ &&
  24                advance d &&
  25                git checkout -b b2 origin &&
  26                git reset --hard b1 &&
  27                git checkout -b b3 origin &&
  28                git reset --hard HEAD^ &&
  29                git checkout -b b4 origin &&
  30                advance e &&
  31                advance f &&
  32                git checkout -b brokenbase origin &&
  33                git checkout -b b5 --track brokenbase &&
  34                advance g &&
  35                git branch -d brokenbase &&
  36                git checkout -b b6 origin
  37        ) &&
  38        git checkout -b follower --track master &&
  39        advance h
  40'
  41
  42script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p'
  43cat >expect <<\EOF
  44b1 [ahead 1, behind 1] d
  45b2 [ahead 1, behind 1] d
  46b3 [behind 1] b
  47b4 [ahead 2] f
  48b5 g
  49b6 c
  50EOF
  51
  52test_expect_success 'branch -v' '
  53        (
  54                cd test &&
  55                git branch -v
  56        ) |
  57        sed -n -e "$script" >actual &&
  58        test_i18ncmp expect actual
  59'
  60
  61cat >expect <<\EOF
  62b1 [origin/master: ahead 1, behind 1] d
  63b2 [origin/master: ahead 1, behind 1] d
  64b3 [origin/master: behind 1] b
  65b4 [origin/master: ahead 2] f
  66b5 [brokenbase: gone] g
  67b6 [origin/master] c
  68EOF
  69
  70test_expect_success 'branch -vv' '
  71        (
  72                cd test &&
  73                git branch -vv
  74        ) |
  75        sed -n -e "$script" >actual &&
  76        test_i18ncmp expect actual
  77'
  78
  79test_expect_success 'checkout (diverged from upstream)' '
  80        (
  81                cd test && git checkout b1
  82        ) >actual &&
  83        test_i18ngrep "have 1 and 1 different" actual
  84'
  85
  86test_expect_success 'checkout with local tracked branch' '
  87        git checkout master &&
  88        git checkout follower >actual &&
  89        test_i18ngrep "is ahead of" actual
  90'
  91
  92test_expect_success 'checkout (upstream is gone)' '
  93        (
  94                cd test &&
  95                git checkout b5
  96        ) >actual &&
  97        test_i18ngrep "is based on .*, but the upstream is gone." actual
  98'
  99
 100test_expect_success 'checkout (up-to-date with upstream)' '
 101        (
 102                cd test && git checkout b6
 103        ) >actual &&
 104        test_i18ngrep "Your branch is up-to-date with .origin/master" actual
 105'
 106
 107test_expect_success 'status (diverged from upstream)' '
 108        (
 109                cd test &&
 110                git checkout b1 >/dev/null &&
 111                # reports nothing to commit
 112                test_must_fail git commit --dry-run
 113        ) >actual &&
 114        test_i18ngrep "have 1 and 1 different" actual
 115'
 116
 117test_expect_success 'status (upstream is gone)' '
 118        (
 119                cd test &&
 120                git checkout b5 >/dev/null &&
 121                # reports nothing to commit
 122                test_must_fail git commit --dry-run
 123        ) >actual &&
 124        test_i18ngrep "is based on .*, but the upstream is gone." actual
 125'
 126
 127test_expect_success 'status (up-to-date with upstream)' '
 128        (
 129                cd test &&
 130                git checkout b6 >/dev/null &&
 131                # reports nothing to commit
 132                test_must_fail git commit --dry-run
 133        ) >actual &&
 134        test_i18ngrep "Your branch is up-to-date with .origin/master" actual
 135'
 136
 137cat >expect <<\EOF
 138## b1...origin/master [ahead 1, behind 1]
 139EOF
 140
 141test_expect_success 'status -s -b (diverged from upstream)' '
 142        (
 143                cd test &&
 144                git checkout b1 >/dev/null &&
 145                git status -s -b | head -1
 146        ) >actual &&
 147        test_i18ncmp expect actual
 148'
 149
 150cat >expect <<\EOF
 151## b5...brokenbase [gone]
 152EOF
 153
 154test_expect_success 'status -s -b (upstream is gone)' '
 155        (
 156                cd test &&
 157                git checkout b5 >/dev/null &&
 158                git status -s -b | head -1
 159        ) >actual &&
 160        test_i18ncmp expect actual
 161'
 162
 163cat >expect <<\EOF
 164## b6...origin/master
 165EOF
 166
 167test_expect_success 'status -s -b (up-to-date with upstream)' '
 168        (
 169                cd test &&
 170                git checkout b6 >/dev/null &&
 171                git status -s -b | head -1
 172        ) >actual &&
 173        test_i18ncmp expect actual
 174'
 175
 176test_expect_success 'fail to track lightweight tags' '
 177        git checkout master &&
 178        git tag light &&
 179        test_must_fail git branch --track lighttrack light >actual &&
 180        test_i18ngrep ! "set up to track" actual &&
 181        test_must_fail git checkout lighttrack
 182'
 183
 184test_expect_success 'fail to track annotated tags' '
 185        git checkout master &&
 186        git tag -m heavy heavy &&
 187        test_must_fail git branch --track heavytrack heavy >actual &&
 188        test_i18ngrep ! "set up to track" actual &&
 189        test_must_fail git checkout heavytrack
 190'
 191
 192test_expect_success 'setup tracking with branch --set-upstream on existing branch' '
 193        git branch from-master master &&
 194        test_must_fail git config branch.from-master.merge > actual &&
 195        git branch --set-upstream from-master master &&
 196        git config branch.from-master.merge > actual &&
 197        grep -q "^refs/heads/master$" actual
 198'
 199
 200test_expect_success '--set-upstream does not change branch' '
 201        git branch from-master2 master &&
 202        test_must_fail git config branch.from-master2.merge > actual &&
 203        git rev-list from-master2 &&
 204        git update-ref refs/heads/from-master2 from-master2^ &&
 205        git rev-parse from-master2 >expect2 &&
 206        git branch --set-upstream from-master2 master &&
 207        git config branch.from-master.merge > actual &&
 208        git rev-parse from-master2 >actual2 &&
 209        grep -q "^refs/heads/master$" actual &&
 210        cmp expect2 actual2
 211'
 212
 213test_expect_success '--set-upstream @{-1}' '
 214        git checkout from-master &&
 215        git checkout from-master2 &&
 216        git config branch.from-master2.merge > expect2 &&
 217        git branch --set-upstream @{-1} follower &&
 218        git config branch.from-master.merge > actual &&
 219        git config branch.from-master2.merge > actual2 &&
 220        git branch --set-upstream from-master follower &&
 221        git config branch.from-master.merge > expect &&
 222        test_cmp expect2 actual2 &&
 223        test_cmp expect actual
 224'
 225
 226test_done