]>
Commit | Line | Data |
---|---|---|
c0234b2e JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='remote tracking stats' | |
4 | ||
334afbc7 JS |
5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | |
7 | ||
c0234b2e JH |
8 | . ./test-lib.sh |
9 | ||
10 | advance () { | |
11 | echo "$1" >"$1" && | |
12 | git add "$1" && | |
13 | test_tick && | |
14 | git commit -m "$1" | |
15 | } | |
16 | ||
17 | test_expect_success setup ' | |
e6821d09 JK |
18 | advance a && |
19 | advance b && | |
20 | advance c && | |
c0234b2e JH |
21 | git clone . test && |
22 | ( | |
23 | cd test && | |
24 | git checkout -b b1 origin && | |
25 | git reset --hard HEAD^ && | |
26 | advance d && | |
27 | git checkout -b b2 origin && | |
28 | git reset --hard b1 && | |
29 | git checkout -b b3 origin && | |
30 | git reset --hard HEAD^ && | |
31 | git checkout -b b4 origin && | |
32 | advance e && | |
f2e08739 JX |
33 | advance f && |
34 | git checkout -b brokenbase origin && | |
35 | git checkout -b b5 --track brokenbase && | |
36 | advance g && | |
f223459b JX |
37 | git branch -d brokenbase && |
38 | git checkout -b b6 origin | |
57dac0bf MG |
39 | ) && |
40 | git checkout -b follower --track master && | |
f2e08739 | 41 | advance h |
c0234b2e JH |
42 | ' |
43 | ||
e3d5e4bd | 44 | t6040_script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p' |
c0234b2e | 45 | cat >expect <<\EOF |
6b364d48 TH |
46 | b1 [ahead 1, behind 1] d |
47 | b2 [ahead 1, behind 1] d | |
48 | b3 [behind 1] b | |
49 | b4 [ahead 2] f | |
949af068 | 50 | b5 [gone] g |
6b364d48 | 51 | b6 c |
c0234b2e JH |
52 | EOF |
53 | ||
b3e1900a | 54 | test_expect_success 'branch -v' ' |
c0234b2e JH |
55 | ( |
56 | cd test && | |
57 | git branch -v | |
58 | ) | | |
e3d5e4bd | 59 | sed -n -e "$t6040_script" >actual && |
b3e1900a | 60 | test_i18ncmp expect actual |
c0234b2e JH |
61 | ' |
62 | ||
afc1692f | 63 | cat >expect <<\EOF |
6b364d48 TH |
64 | b1 [origin/master: ahead 1, behind 1] d |
65 | b2 [origin/master: ahead 1, behind 1] d | |
66 | b3 [origin/master: behind 1] b | |
67 | b4 [origin/master: ahead 2] f | |
68 | b5 [brokenbase: gone] g | |
69 | b6 [origin/master] c | |
afc1692f MG |
70 | EOF |
71 | ||
72 | test_expect_success 'branch -vv' ' | |
73 | ( | |
74 | cd test && | |
75 | git branch -vv | |
76 | ) | | |
e3d5e4bd | 77 | sed -n -e "$t6040_script" >actual && |
afc1692f MG |
78 | test_i18ncmp expect actual |
79 | ' | |
80 | ||
f2e08739 | 81 | test_expect_success 'checkout (diverged from upstream)' ' |
c0234b2e JH |
82 | ( |
83 | cd test && git checkout b1 | |
84 | ) >actual && | |
76642cce | 85 | test_i18ngrep "have 1 and 1 different" actual |
c0234b2e JH |
86 | ' |
87 | ||
5e6e2b48 | 88 | test_expect_success 'checkout with local tracked branch' ' |
57dac0bf | 89 | git checkout master && |
a48fcd83 | 90 | git checkout follower >actual && |
76642cce | 91 | test_i18ngrep "is ahead of" actual |
57dac0bf MG |
92 | ' |
93 | ||
f2e08739 JX |
94 | test_expect_success 'checkout (upstream is gone)' ' |
95 | ( | |
96 | cd test && | |
97 | git checkout b5 | |
98 | ) >actual && | |
99 | test_i18ngrep "is based on .*, but the upstream is gone." actual | |
100 | ' | |
101 | ||
f223459b JX |
102 | test_expect_success 'checkout (up-to-date with upstream)' ' |
103 | ( | |
104 | cd test && git checkout b6 | |
105 | ) >actual && | |
7560f547 | 106 | test_i18ngrep "Your branch is up to date with .origin/master" actual |
f223459b JX |
107 | ' |
108 | ||
f2e08739 | 109 | test_expect_success 'status (diverged from upstream)' ' |
c0234b2e JH |
110 | ( |
111 | cd test && | |
112 | git checkout b1 >/dev/null && | |
113 | # reports nothing to commit | |
9e4b7ab6 | 114 | test_must_fail git commit --dry-run |
c0234b2e | 115 | ) >actual && |
76642cce | 116 | test_i18ngrep "have 1 and 1 different" actual |
c0234b2e JH |
117 | ' |
118 | ||
f2e08739 JX |
119 | test_expect_success 'status (upstream is gone)' ' |
120 | ( | |
121 | cd test && | |
122 | git checkout b5 >/dev/null && | |
123 | # reports nothing to commit | |
124 | test_must_fail git commit --dry-run | |
125 | ) >actual && | |
126 | test_i18ngrep "is based on .*, but the upstream is gone." actual | |
127 | ' | |
128 | ||
f223459b JX |
129 | test_expect_success 'status (up-to-date with upstream)' ' |
130 | ( | |
131 | cd test && | |
132 | git checkout b6 >/dev/null && | |
133 | # reports nothing to commit | |
134 | test_must_fail git commit --dry-run | |
135 | ) >actual && | |
7560f547 | 136 | test_i18ngrep "Your branch is up to date with .origin/master" actual |
f223459b JX |
137 | ' |
138 | ||
f2e08739 JX |
139 | cat >expect <<\EOF |
140 | ## b1...origin/master [ahead 1, behind 1] | |
141 | EOF | |
142 | ||
143 | test_expect_success 'status -s -b (diverged from upstream)' ' | |
144 | ( | |
145 | cd test && | |
146 | git checkout b1 >/dev/null && | |
147 | git status -s -b | head -1 | |
148 | ) >actual && | |
149 | test_i18ncmp expect actual | |
3ca1897c JH |
150 | ' |
151 | ||
152 | cat >expect <<\EOF | |
153 | ## b1...origin/master [different] | |
154 | EOF | |
155 | ||
156 | test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' ' | |
157 | ( | |
158 | cd test && | |
159 | git checkout b1 >/dev/null && | |
160 | git status -s -b --no-ahead-behind | head -1 | |
161 | ) >actual && | |
162 | test_i18ncmp expect actual | |
f39a757d JH |
163 | ' |
164 | ||
06b324c1 JH |
165 | cat >expect <<\EOF |
166 | ## b1...origin/master [different] | |
167 | EOF | |
168 | ||
169 | test_expect_success 'status.aheadbehind=false status -s -b (diverged from upstream)' ' | |
170 | ( | |
171 | cd test && | |
172 | git checkout b1 >/dev/null && | |
173 | git -c status.aheadbehind=false status -s -b | head -1 | |
174 | ) >actual && | |
175 | test_i18ncmp expect actual | |
176 | ' | |
177 | ||
f39a757d JH |
178 | cat >expect <<\EOF |
179 | On branch b1 | |
180 | Your branch and 'origin/master' have diverged, | |
181 | and have 1 and 1 different commits each, respectively. | |
182 | EOF | |
183 | ||
184 | test_expect_success 'status --long --branch' ' | |
185 | ( | |
186 | cd test && | |
187 | git checkout b1 >/dev/null && | |
188 | git status --long -b | head -3 | |
189 | ) >actual && | |
190 | test_i18ncmp expect actual | |
191 | ' | |
192 | ||
06b324c1 JH |
193 | test_expect_success 'status --long --branch' ' |
194 | ( | |
195 | cd test && | |
196 | git checkout b1 >/dev/null && | |
197 | git -c status.aheadbehind=true status --long -b | head -3 | |
198 | ) >actual && | |
199 | test_i18ncmp expect actual | |
200 | ' | |
201 | ||
f39a757d JH |
202 | cat >expect <<\EOF |
203 | On branch b1 | |
204 | Your branch and 'origin/master' refer to different commits. | |
205 | EOF | |
206 | ||
207 | test_expect_success 'status --long --branch --no-ahead-behind' ' | |
208 | ( | |
209 | cd test && | |
210 | git checkout b1 >/dev/null && | |
211 | git status --long -b --no-ahead-behind | head -2 | |
212 | ) >actual && | |
213 | test_i18ncmp expect actual | |
06b324c1 JH |
214 | ' |
215 | ||
216 | test_expect_success 'status.aheadbehind=false status --long --branch' ' | |
217 | ( | |
218 | cd test && | |
219 | git checkout b1 >/dev/null && | |
220 | git -c status.aheadbehind=false status --long -b | head -2 | |
221 | ) >actual && | |
222 | test_i18ncmp expect actual | |
f2e08739 JX |
223 | ' |
224 | ||
225 | cat >expect <<\EOF | |
226 | ## b5...brokenbase [gone] | |
227 | EOF | |
228 | ||
229 | test_expect_success 'status -s -b (upstream is gone)' ' | |
230 | ( | |
231 | cd test && | |
232 | git checkout b5 >/dev/null && | |
233 | git status -s -b | head -1 | |
234 | ) >actual && | |
235 | test_i18ncmp expect actual | |
236 | ' | |
237 | ||
f223459b JX |
238 | cat >expect <<\EOF |
239 | ## b6...origin/master | |
240 | EOF | |
241 | ||
242 | test_expect_success 'status -s -b (up-to-date with upstream)' ' | |
243 | ( | |
244 | cd test && | |
245 | git checkout b6 >/dev/null && | |
246 | git status -s -b | head -1 | |
247 | ) >actual && | |
248 | test_i18ncmp expect actual | |
249 | ' | |
250 | ||
21b5b1e8 | 251 | test_expect_success 'fail to track lightweight tags' ' |
1be570f4 MG |
252 | git checkout master && |
253 | git tag light && | |
21b5b1e8 | 254 | test_must_fail git branch --track lighttrack light >actual && |
76642cce | 255 | test_i18ngrep ! "set up to track" actual && |
21b5b1e8 | 256 | test_must_fail git checkout lighttrack |
1be570f4 | 257 | ' |
c0234b2e | 258 | |
21b5b1e8 | 259 | test_expect_success 'fail to track annotated tags' ' |
1be570f4 MG |
260 | git checkout master && |
261 | git tag -m heavy heavy && | |
21b5b1e8 | 262 | test_must_fail git branch --track heavytrack heavy >actual && |
76642cce | 263 | test_i18ngrep ! "set up to track" actual && |
21b5b1e8 | 264 | test_must_fail git checkout heavytrack |
1be570f4 | 265 | ' |
4fc50066 | 266 | |
52668846 | 267 | test_expect_success '--set-upstream-to does not change branch' ' |
4fc50066 | 268 | git branch from-master master && |
52668846 | 269 | git branch --set-upstream-to master from-master && |
b6211b89 JS |
270 | git branch from-topic_2 master && |
271 | test_must_fail git config branch.from-topic_2.merge > actual && | |
272 | git rev-list from-topic_2 && | |
273 | git update-ref refs/heads/from-topic_2 from-topic_2^ && | |
274 | git rev-parse from-topic_2 >expect2 && | |
275 | git branch --set-upstream-to master from-topic_2 && | |
4fc50066 | 276 | git config branch.from-master.merge > actual && |
b6211b89 | 277 | git rev-parse from-topic_2 >actual2 && |
4fc50066 IL |
278 | grep -q "^refs/heads/master$" actual && |
279 | cmp expect2 actual2 | |
280 | ' | |
e9d4f740 | 281 | |
52668846 KS |
282 | test_expect_success '--set-upstream-to @{-1}' ' |
283 | git checkout follower && | |
b6211b89 JS |
284 | git checkout from-topic_2 && |
285 | git config branch.from-topic_2.merge > expect2 && | |
52668846 | 286 | git branch --set-upstream-to @{-1} from-master && |
e9d4f740 | 287 | git config branch.from-master.merge > actual && |
b6211b89 | 288 | git config branch.from-topic_2.merge > actual2 && |
52668846 | 289 | git branch --set-upstream-to follower from-master && |
e9d4f740 MG |
290 | git config branch.from-master.merge > expect && |
291 | test_cmp expect2 actual2 && | |
292 | test_cmp expect actual | |
293 | ' | |
294 | ||
c0234b2e | 295 | test_done |