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