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 &&
36 git branch -p origin/master &&
37 git checkout -b b7 origin &&
38 git branch -p origin/master &&
41 git checkout -b follower --track master &&
45 script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p'
52 b6 [origin/master, origin/master] c
53 b7 [origin/master, origin/master *] h
56 test_expect_success 'branch -v' '
61 sed -n -e "$script" >actual &&
62 test_i18ncmp expect actual
66 b1 [origin/master: ahead 1, behind 1] d
67 b2 [origin/master: ahead 1, behind 1] d
68 b3 [origin/master: behind 1] b
69 b4 [origin/master: ahead 2] f
70 b5 [brokenbase: gone] g
71 b6 [origin/master, origin/master] c
72 b7 [origin/master, origin/master *: ahead 1] h
75 test_expect_success 'branch -vv' '
80 sed -n -e "$script" >actual &&
81 test_i18ncmp expect actual
84 test_expect_success 'checkout (diverged from upstream)' '
86 cd test && git checkout b1
88 test_i18ngrep "have 1 and 1 different" actual
91 test_expect_success 'checkout with local tracked branch' '
92 git checkout master &&
93 git checkout follower >actual &&
94 test_i18ngrep "is ahead of" actual
97 test_expect_success 'checkout (upstream is gone)' '
102 test_i18ngrep "is based on .*, but the upstream is gone." actual
105 test_expect_success 'checkout (up-to-date with upstream)' '
107 cd test && git checkout b6
109 test_i18ngrep "Your branch is up-to-date with .origin/master" actual
112 test_expect_success 'status (diverged from upstream)' '
115 git checkout b1 >/dev/null &&
116 # reports nothing to commit
117 test_must_fail git commit --dry-run
119 test_i18ngrep "have 1 and 1 different" actual
122 test_expect_success 'status (upstream is gone)' '
125 git checkout b5 >/dev/null &&
126 # reports nothing to commit
127 test_must_fail git commit --dry-run
129 test_i18ngrep "is based on .*, but the upstream is gone." actual
132 test_expect_success 'status (up-to-date with upstream)' '
135 git checkout b6 >/dev/null &&
136 # reports nothing to commit
137 test_must_fail git commit --dry-run
139 test_i18ngrep "Your branch is up-to-date with .origin/master" actual
143 ## b1...origin/master [ahead 1, behind 1]
146 test_expect_success 'status -s -b (diverged from upstream)' '
149 git checkout b1 >/dev/null &&
150 git status -s -b | head -1
152 test_i18ncmp expect actual
156 ## b5...brokenbase [gone]
159 test_expect_success 'status -s -b (upstream is gone)' '
162 git checkout b5 >/dev/null &&
163 git status -s -b | head -1
165 test_i18ncmp expect actual
169 ## b6...origin/master
172 test_expect_success 'status -s -b (up-to-date with upstream)' '
175 git checkout b6 >/dev/null &&
176 git status -s -b | head -1
178 test_i18ncmp expect actual
181 test_expect_success 'fail to track lightweight tags' '
182 git checkout master &&
184 test_must_fail git branch --track lighttrack light >actual &&
185 test_i18ngrep ! "set up to track" actual &&
186 test_must_fail git checkout lighttrack
189 test_expect_success 'fail to track annotated tags' '
190 git checkout master &&
191 git tag -m heavy heavy &&
192 test_must_fail git branch --track heavytrack heavy >actual &&
193 test_i18ngrep ! "set up to track" actual &&
194 test_must_fail git checkout heavytrack
197 test_expect_success 'setup tracking with branch --set-upstream on existing branch' '
198 git branch from-master master &&
199 test_must_fail git config branch.from-master.merge > actual &&
200 git branch --set-upstream from-master master &&
201 git config branch.from-master.merge > actual &&
202 grep -q "^refs/heads/master$" actual
205 test_expect_success '--set-upstream does not change branch' '
206 git branch from-master2 master &&
207 test_must_fail git config branch.from-master2.merge > actual &&
208 git rev-list from-master2 &&
209 git update-ref refs/heads/from-master2 from-master2^ &&
210 git rev-parse from-master2 >expect2 &&
211 git branch --set-upstream from-master2 master &&
212 git config branch.from-master.merge > actual &&
213 git rev-parse from-master2 >actual2 &&
214 grep -q "^refs/heads/master$" actual &&
218 test_expect_success '--set-upstream @{-1}' '
219 git checkout from-master &&
220 git checkout from-master2 &&
221 git config branch.from-master2.merge > expect2 &&
222 git branch --set-upstream @{-1} follower &&
223 git config branch.from-master.merge > actual &&
224 git config branch.from-master2.merge > actual2 &&
225 git branch --set-upstream from-master follower &&
226 git config branch.from-master.merge > expect &&
227 test_cmp expect2 actual2 &&
228 test_cmp expect actual