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