3 test_description='remote tracking stats'
14 test_expect_success setup '
22 git checkout -b b1 origin &&
23 git reset --hard HEAD^ &&
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 &&
32 git checkout -b brokenbase origin &&
33 git checkout -b b5 --track brokenbase &&
35 git branch -d brokenbase &&
36 git checkout -b b6 origin &&
37 git branch --set-publish origin/master b6
39 git checkout -b follower --track master &&
43 script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p'
50 b6 [origin/master, origin/master] c
53 test_expect_success 'branch -v' '
58 sed -n -e "$script" >actual &&
59 test_i18ncmp expect actual
63 b1 [origin/master: ahead 1, behind 1] d
64 b2 [origin/master: ahead 1, behind 1] d
65 b3 [origin/master: behind 1] b
66 b4 [origin/master: ahead 2] f
67 b5 [brokenbase: gone] g
68 b6 [origin/master, origin/master] c
71 test_expect_success 'branch -vv' '
76 sed -n -e "$script" >actual &&
77 test_i18ncmp expect actual
80 test_expect_success 'checkout (diverged from upstream)' '
82 cd test && git checkout b1
84 test_i18ngrep "have 1 and 1 different" actual
87 test_expect_success 'checkout with local tracked branch' '
88 git checkout master &&
89 git checkout follower >actual &&
90 test_i18ngrep "is ahead of" actual
93 test_expect_success 'checkout (upstream is gone)' '
98 test_i18ngrep "is based on .*, but the upstream is gone." actual
101 test_expect_success 'checkout (up-to-date with upstream)' '
103 cd test && git checkout b6
105 test_i18ngrep "Your branch is up-to-date with .origin/master" actual
108 test_expect_success 'status (diverged from upstream)' '
111 git checkout b1 >/dev/null &&
112 # reports nothing to commit
113 test_must_fail git commit --dry-run
115 test_i18ngrep "have 1 and 1 different" actual
118 test_expect_success 'status (upstream is gone)' '
121 git checkout b5 >/dev/null &&
122 # reports nothing to commit
123 test_must_fail git commit --dry-run
125 test_i18ngrep "is based on .*, but the upstream is gone." actual
128 test_expect_success 'status (up-to-date with upstream)' '
131 git checkout b6 >/dev/null &&
132 # reports nothing to commit
133 test_must_fail git commit --dry-run
135 test_i18ngrep "Your branch is up-to-date with .origin/master" actual
139 ## b1...origin/master [ahead 1, behind 1]
142 test_expect_success 'status -s -b (diverged from upstream)' '
145 git checkout b1 >/dev/null &&
146 git status -s -b | head -1
148 test_i18ncmp expect actual
152 ## b5...brokenbase [gone]
155 test_expect_success 'status -s -b (upstream is gone)' '
158 git checkout b5 >/dev/null &&
159 git status -s -b | head -1
161 test_i18ncmp expect actual
165 ## b6...origin/master
168 test_expect_success 'status -s -b (up-to-date with upstream)' '
171 git checkout b6 >/dev/null &&
172 git status -s -b | head -1
174 test_i18ncmp expect actual
177 test_expect_success 'fail to track lightweight tags' '
178 git checkout master &&
180 test_must_fail git branch --track lighttrack light >actual &&
181 test_i18ngrep ! "set up to track" actual &&
182 test_must_fail git checkout lighttrack
185 test_expect_success 'fail to track annotated tags' '
186 git checkout master &&
187 git tag -m heavy heavy &&
188 test_must_fail git branch --track heavytrack heavy >actual &&
189 test_i18ngrep ! "set up to track" actual &&
190 test_must_fail git checkout heavytrack
193 test_expect_success 'setup tracking with branch --set-upstream on existing branch' '
194 git branch from-master master &&
195 test_must_fail git config branch.from-master.merge > actual &&
196 git branch --set-upstream from-master master &&
197 git config branch.from-master.merge > actual &&
198 grep -q "^refs/heads/master$" actual
201 test_expect_success '--set-upstream does not change branch' '
202 git branch from-master2 master &&
203 test_must_fail git config branch.from-master2.merge > actual &&
204 git rev-list from-master2 &&
205 git update-ref refs/heads/from-master2 from-master2^ &&
206 git rev-parse from-master2 >expect2 &&
207 git branch --set-upstream from-master2 master &&
208 git config branch.from-master.merge > actual &&
209 git rev-parse from-master2 >actual2 &&
210 grep -q "^refs/heads/master$" actual &&
214 test_expect_success '--set-upstream @{-1}' '
215 git checkout from-master &&
216 git checkout from-master2 &&
217 git config branch.from-master2.merge > expect2 &&
218 git branch --set-upstream @{-1} follower &&
219 git config branch.from-master.merge > actual &&
220 git config branch.from-master2.merge > actual2 &&
221 git branch --set-upstream from-master follower &&
222 git config branch.from-master.merge > expect &&
223 test_cmp expect2 actual2 &&
224 test_cmp expect actual