3 test_description='remote tracking stats'
14 test_expect_success setup '
21 git checkout -b b1 origin &&
22 git reset --hard HEAD^ &&
24 git checkout -b b2 origin &&
25 git reset --hard b1 &&
26 git checkout -b b3 origin &&
27 git reset --hard HEAD^ &&
28 git checkout -b b4 origin &&
31 git checkout -b brokenbase origin &&
32 git checkout -b b5 --track brokenbase &&
34 git branch -d brokenbase &&
35 git checkout -b b6 origin
37 git checkout -b follower --track master &&
41 t6040_script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p'
43 b1 [ahead 1, behind 1] d
44 b2 [ahead 1, behind 1] d
51 test_expect_success 'branch -v' '
56 sed -n -e "$t6040_script" >actual &&
57 test_i18ncmp expect actual
61 b1 [origin/master: ahead 1, behind 1] d
62 b2 [origin/master: ahead 1, behind 1] d
63 b3 [origin/master: behind 1] b
64 b4 [origin/master: ahead 2] f
65 b5 [brokenbase: gone] g
69 test_expect_success 'branch -vv' '
74 sed -n -e "$t6040_script" >actual &&
75 test_i18ncmp expect actual
78 test_expect_success 'checkout (diverged from upstream)' '
80 cd test && git checkout b1
82 test_i18ngrep "have 1 and 1 different" actual
85 test_expect_success 'checkout with local tracked branch' '
86 git checkout master &&
87 git checkout follower >actual &&
88 test_i18ngrep "is ahead of" actual
91 test_expect_success 'checkout (upstream is gone)' '
96 test_i18ngrep "is based on .*, but the upstream is gone." actual
99 test_expect_success 'checkout (up-to-date with upstream)' '
101 cd test && git checkout b6
103 test_i18ngrep "Your branch is up to date with .origin/master" actual
106 test_expect_success 'status (diverged from upstream)' '
109 git checkout b1 >/dev/null &&
110 # reports nothing to commit
111 test_must_fail git commit --dry-run
113 test_i18ngrep "have 1 and 1 different" actual
116 test_expect_success 'status (upstream is gone)' '
119 git checkout b5 >/dev/null &&
120 # reports nothing to commit
121 test_must_fail git commit --dry-run
123 test_i18ngrep "is based on .*, but the upstream is gone." actual
126 test_expect_success 'status (up-to-date with upstream)' '
129 git checkout b6 >/dev/null &&
130 # reports nothing to commit
131 test_must_fail git commit --dry-run
133 test_i18ngrep "Your branch is up to date with .origin/master" actual
137 ## b1...origin/master [ahead 1, behind 1]
140 test_expect_success 'status -s -b (diverged from upstream)' '
143 git checkout b1 >/dev/null &&
144 git status -s -b | head -1
146 test_i18ncmp expect actual
150 ## b1...origin/master [different]
153 test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '
156 git checkout b1 >/dev/null &&
157 git status -s -b --no-ahead-behind | head -1
159 test_i18ncmp expect actual
163 ## b1...origin/master [different]
166 test_expect_success 'status.aheadbehind=false status -s -b (diverged from upstream)' '
169 git checkout b1 >/dev/null &&
170 git -c status.aheadbehind=false status -s -b | head -1
172 test_i18ncmp expect actual
177 Your branch and 'origin/master' have diverged,
178 and have 1 and 1 different commits each, respectively.
181 test_expect_success 'status --long --branch' '
184 git checkout b1 >/dev/null &&
185 git status --long -b | head -3
187 test_i18ncmp expect actual
190 test_expect_success 'status --long --branch' '
193 git checkout b1 >/dev/null &&
194 git -c status.aheadbehind=true status --long -b | head -3
196 test_i18ncmp expect actual
201 Your branch and 'origin/master' refer to different commits.
204 test_expect_success 'status --long --branch --no-ahead-behind' '
207 git checkout b1 >/dev/null &&
208 git status --long -b --no-ahead-behind | head -2
210 test_i18ncmp expect actual
213 test_expect_success 'status.aheadbehind=false status --long --branch' '
216 git checkout b1 >/dev/null &&
217 git -c status.aheadbehind=false status --long -b | head -2
219 test_i18ncmp expect actual
223 ## b5...brokenbase [gone]
226 test_expect_success 'status -s -b (upstream is gone)' '
229 git checkout b5 >/dev/null &&
230 git status -s -b | head -1
232 test_i18ncmp expect actual
236 ## b6...origin/master
239 test_expect_success 'status -s -b (up-to-date with upstream)' '
242 git checkout b6 >/dev/null &&
243 git status -s -b | head -1
245 test_i18ncmp expect actual
248 test_expect_success 'fail to track lightweight tags' '
249 git checkout master &&
251 test_must_fail git branch --track lighttrack light >actual &&
252 test_i18ngrep ! "set up to track" actual &&
253 test_must_fail git checkout lighttrack
256 test_expect_success 'fail to track annotated tags' '
257 git checkout master &&
258 git tag -m heavy heavy &&
259 test_must_fail git branch --track heavytrack heavy >actual &&
260 test_i18ngrep ! "set up to track" actual &&
261 test_must_fail git checkout heavytrack
264 test_expect_success '--set-upstream-to does not change branch' '
265 git branch from-master master &&
266 git branch --set-upstream-to master from-master &&
267 git branch from-topic_2 master &&
268 test_must_fail git config branch.from-topic_2.merge > actual &&
269 git rev-list from-topic_2 &&
270 git update-ref refs/heads/from-topic_2 from-topic_2^ &&
271 git rev-parse from-topic_2 >expect2 &&
272 git branch --set-upstream-to master from-topic_2 &&
273 git config branch.from-master.merge > actual &&
274 git rev-parse from-topic_2 >actual2 &&
275 grep -q "^refs/heads/master$" actual &&
279 test_expect_success '--set-upstream-to @{-1}' '
280 git checkout follower &&
281 git checkout from-topic_2 &&
282 git config branch.from-topic_2.merge > expect2 &&
283 git branch --set-upstream-to @{-1} from-master &&
284 git config branch.from-master.merge > actual &&
285 git config branch.from-topic_2.merge > actual2 &&
286 git branch --set-upstream-to follower from-master &&
287 git config branch.from-master.merge > expect &&
288 test_cmp expect2 actual2 &&
289 test_cmp expect actual