1#!/bin/sh
23
test_description='remote tracking stats'
45
. ./test-lib.sh
67
advance () {
8echo "$1" >"$1" &&
9git add "$1" &&
10test_tick &&
11git commit -m "$1"
12}
1314
test_expect_success setup '
15for i in a b c;
16do
17advance $i || break
18done &&
19git clone . test &&
20(
21cd test &&
22git checkout -b b1 origin &&
23git reset --hard HEAD^ &&
24advance d &&
25git checkout -b b2 origin &&
26git reset --hard b1 &&
27git checkout -b b3 origin &&
28git reset --hard HEAD^ &&
29git checkout -b b4 origin &&
30advance e &&
31advance f
32) &&
33git checkout -b follower --track master &&
34advance g
35'
3637
script='s/^..\(b.\)[ 0-9a-f]*\[\([^]]*\)\].*/\1 \2/p'
38cat >expect <<\EOF
39b1 ahead 1, behind 1
40b2 ahead 1, behind 1
41b3 behind 1
42b4 ahead 2
43EOF
4445
test_expect_success 'branch -v' '
46(
47cd test &&
48git branch -v
49) |
50sed -n -e "$script" >actual &&
51test_i18ncmp expect actual
52'
5354
cat >expect <<\EOF
55b1 origin/master: ahead 1, behind 1
56b2 origin/master: ahead 1, behind 1
57b3 origin/master: behind 1
58b4 origin/master: ahead 2
59EOF
6061
test_expect_success 'branch -vv' '
62(
63cd test &&
64git branch -vv
65) |
66sed -n -e "$script" >actual &&
67test_i18ncmp expect actual
68'
6970
test_expect_success 'checkout' '
71(
72cd test && git checkout b1
73) >actual &&
74test_i18ngrep "have 1 and 1 different" actual
75'
7677
test_expect_success 'checkout with local tracked branch' '
78git checkout master &&
79git checkout follower >actual &&
80test_i18ngrep "is ahead of" actual
81'
8283
test_expect_success 'status' '
84(
85cd test &&
86git checkout b1 >/dev/null &&
87# reports nothing to commit
88test_must_fail git commit --dry-run
89) >actual &&
90test_i18ngrep "have 1 and 1 different" actual
91'
9293
test_expect_success 'fail to track lightweight tags' '
94git checkout master &&
95git tag light &&
96test_must_fail git branch --track lighttrack light >actual &&
97test_i18ngrep ! "set up to track" actual &&
98test_must_fail git checkout lighttrack
99'
100101
test_expect_success 'fail to track annotated tags' '
102git checkout master &&
103git tag -m heavy heavy &&
104test_must_fail git branch --track heavytrack heavy >actual &&
105test_i18ngrep ! "set up to track" actual &&
106test_must_fail git checkout heavytrack
107'
108109
test_expect_success 'setup tracking with branch --set-upstream on existing branch' '
110git branch from-master master &&
111test_must_fail git config branch.from-master.merge > actual &&
112git branch --set-upstream from-master master &&
113git config branch.from-master.merge > actual &&
114grep -q "^refs/heads/master$" actual
115'
116117
test_expect_success '--set-upstream does not change branch' '
118git branch from-master2 master &&
119test_must_fail git config branch.from-master2.merge > actual &&
120git rev-list from-master2 &&
121git update-ref refs/heads/from-master2 from-master2^ &&
122git rev-parse from-master2 >expect2 &&
123git branch --set-upstream from-master2 master &&
124git config branch.from-master.merge > actual &&
125git rev-parse from-master2 >actual2 &&
126grep -q "^refs/heads/master$" actual &&
127cmp expect2 actual2
128'
129130
test_expect_success '--set-upstream @{-1}' '
131git checkout from-master &&
132git checkout from-master2 &&
133git config branch.from-master2.merge > expect2 &&
134git branch --set-upstream @{-1} follower &&
135git config branch.from-master.merge > actual &&
136git config branch.from-master2.merge > actual2 &&
137git branch --set-upstream from-master follower &&
138git config branch.from-master.merge > expect &&
139test_cmp expect2 actual2 &&
140test_cmp expect actual
141'
142143
test_done