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 -p origin/master &&
38 git checkout -b b7 origin &&
39 git branch -p origin/master &&
42 git checkout -b follower --track master &&
46 script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p'
53 b6 [origin/master, origin/master] c
54 b7 [origin/master, origin/master *] h
57 test_expect_success 'branch -v' '
62 sed -n -e "$script" >actual &&
63 test_i18ncmp expect actual
67 b1 [origin/master: ahead 1, behind 1] d
68 b2 [origin/master: ahead 1, behind 1] d
69 b3 [origin/master: behind 1] b
70 b4 [origin/master: ahead 2] f
71 b5 [brokenbase: gone] g
72 b6 [origin/master, origin/master] c
73 b7 [origin/master, origin/master *: ahead 1] h
76 test_expect_success 'branch -vv' '
81 sed -n -e "$script" >actual &&
82 test_i18ncmp expect actual
85 test_expect_success 'checkout (diverged from upstream)' '
87 cd test && git checkout b1
89 test_i18ngrep "have 1 and 1 different" actual
92 test_expect_success 'checkout with local tracked branch' '
93 git checkout master &&
94 git checkout follower >actual &&
95 test_i18ngrep "is ahead of" actual
98 test_expect_success 'checkout (upstream is gone)' '
103 test_i18ngrep "is based on .*, but the upstream is gone." actual
106 test_expect_success 'checkout (up-to-date with upstream)' '
108 cd test && git checkout b6
110 test_i18ngrep "Your branch is up-to-date with .origin/master" actual
113 test_expect_success 'status (diverged from upstream)' '
116 git checkout b1 >/dev/null &&
117 # reports nothing to commit
118 test_must_fail git commit --dry-run
120 test_i18ngrep "have 1 and 1 different" actual
123 test_expect_success 'status (upstream is gone)' '
126 git checkout b5 >/dev/null &&
127 # reports nothing to commit
128 test_must_fail git commit --dry-run
130 test_i18ngrep "is based on .*, but the upstream is gone." actual
133 test_expect_success 'status (up-to-date with upstream)' '
136 git checkout b6 >/dev/null &&
137 # reports nothing to commit
138 test_must_fail git commit --dry-run
140 test_i18ngrep "Your branch is up-to-date with .origin/master" actual
144 ## b1...origin/master [ahead 1, behind 1]
147 test_expect_success 'status -s -b (diverged from upstream)' '
150 git checkout b1 >/dev/null &&
151 git status -s -b | head -1
153 test_i18ncmp expect actual
157 ## b5...brokenbase [gone]
160 test_expect_success 'status -s -b (upstream is gone)' '
163 git checkout b5 >/dev/null &&
164 git status -s -b | head -1
166 test_i18ncmp expect actual
170 ## b6...origin/master
173 test_expect_success 'status -s -b (up-to-date with upstream)' '
176 git checkout b6 >/dev/null &&
177 git status -s -b | head -1
179 test_i18ncmp expect actual
182 test_expect_success 'fail to track lightweight tags' '
183 git checkout master &&
185 test_must_fail git branch --track lighttrack light >actual &&
186 test_i18ngrep ! "set up to track" actual &&
187 test_must_fail git checkout lighttrack
190 test_expect_success 'fail to track annotated tags' '
191 git checkout master &&
192 git tag -m heavy heavy &&
193 test_must_fail git branch --track heavytrack heavy >actual &&
194 test_i18ngrep ! "set up to track" actual &&
195 test_must_fail git checkout heavytrack
198 test_expect_success 'setup tracking with branch --set-upstream on existing branch' '
199 git branch from-master master &&
200 test_must_fail git config branch.from-master.merge > actual &&
201 git branch --set-upstream from-master master &&
202 git config branch.from-master.merge > actual &&
203 grep -q "^refs/heads/master$" actual
206 test_expect_success '--set-upstream does not change branch' '
207 git branch from-master2 master &&
208 test_must_fail git config branch.from-master2.merge > actual &&
209 git rev-list from-master2 &&
210 git update-ref refs/heads/from-master2 from-master2^ &&
211 git rev-parse from-master2 >expect2 &&
212 git branch --set-upstream from-master2 master &&
213 git config branch.from-master.merge > actual &&
214 git rev-parse from-master2 >actual2 &&
215 grep -q "^refs/heads/master$" actual &&
219 test_expect_success '--set-upstream @{-1}' '
220 git checkout from-master &&
221 git checkout from-master2 &&
222 git config branch.from-master2.merge > expect2 &&
223 git branch --set-upstream @{-1} follower &&
224 git config branch.from-master.merge > actual &&
225 git config branch.from-master2.merge > actual2 &&
226 git branch --set-upstream from-master follower &&
227 git config branch.from-master.merge > expect &&
228 test_cmp expect2 actual2 &&
229 test_cmp expect actual