3 test_description
='remote tracking stats'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
18 test_expect_success setup
'
25 git checkout -b b1 origin &&
26 git reset --hard HEAD^ &&
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 &&
35 git checkout -b brokenbase origin &&
36 git checkout -b b5 --track brokenbase &&
38 git branch -d brokenbase &&
39 git checkout -b b6 origin
41 git checkout -b follower --track main &&
45 t6040_script
='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p'
47 b1
[ahead
1, behind
1] d
48 b2
[ahead
1, behind
1] d
55 test_expect_success
'branch -v' '
60 sed -n -e "$t6040_script" >actual &&
61 test_cmp expect actual
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
69 b5
[brokenbase
: gone
] g
73 test_expect_success
'branch -vv' '
78 sed -n -e "$t6040_script" >actual &&
79 test_cmp expect actual
82 test_expect_success
'checkout (diverged from upstream)' '
84 cd test && git checkout b1
86 test_i18ngrep "have 1 and 1 different" actual
89 test_expect_success
'checkout with local tracked branch' '
91 git checkout follower >actual &&
92 test_i18ngrep "is ahead of" actual
95 test_expect_success
'checkout (upstream is gone)' '
100 test_i18ngrep "is based on .*, but the upstream is gone." actual
103 test_expect_success
'checkout (up-to-date with upstream)' '
105 cd test && git checkout b6
107 test_i18ngrep "Your branch is up to date with .origin/main" actual
110 test_expect_success
'status (diverged from upstream)' '
113 git checkout b1 >/dev/null &&
114 # reports nothing to commit
115 test_must_fail git commit --dry-run
117 test_i18ngrep "have 1 and 1 different" actual
120 test_expect_success
'status (upstream is gone)' '
123 git checkout b5 >/dev/null &&
124 # reports nothing to commit
125 test_must_fail git commit --dry-run
127 test_i18ngrep "is based on .*, but the upstream is gone." actual
130 test_expect_success
'status (up-to-date with upstream)' '
133 git checkout b6 >/dev/null &&
134 # reports nothing to commit
135 test_must_fail git commit --dry-run
137 test_i18ngrep "Your branch is up to date with .origin/main" actual
141 ## b1...origin/main [ahead 1, behind 1]
144 test_expect_success
'status -s -b (diverged from upstream)' '
147 git checkout b1 >/dev/null &&
148 git status -s -b | head -1
150 test_cmp expect actual
154 ## b1...origin/main [different]
157 test_expect_success
'status -s -b --no-ahead-behind (diverged from upstream)' '
160 git checkout b1 >/dev/null &&
161 git status -s -b --no-ahead-behind | head -1
163 test_cmp expect actual
167 ## b1...origin/main [different]
170 test_expect_success
'status.aheadbehind=false status -s -b (diverged from upstream)' '
173 git checkout b1 >/dev/null &&
174 git -c status.aheadbehind=false status -s -b | head -1
176 test_cmp expect actual
181 Your branch and
'origin/main' have diverged
,
182 and have
1 and
1 different commits each
, respectively.
185 test_expect_success
'status --long --branch' '
188 git checkout b1 >/dev/null &&
189 git status --long -b | head -3
191 test_cmp expect actual
194 test_expect_success
'status --long --branch' '
197 git checkout b1 >/dev/null &&
198 git -c status.aheadbehind=true status --long -b | head -3
200 test_cmp expect actual
205 Your branch and
'origin/main' refer to different commits.
208 test_expect_success
'status --long --branch --no-ahead-behind' '
211 git checkout b1 >/dev/null &&
212 git status --long -b --no-ahead-behind | head -2
214 test_cmp expect actual
217 test_expect_success
'status.aheadbehind=false status --long --branch' '
220 git checkout b1 >/dev/null &&
221 git -c status.aheadbehind=false status --long -b | head -2
223 test_cmp expect actual
227 ## b5...brokenbase [gone]
230 test_expect_success
'status -s -b (upstream is gone)' '
233 git checkout b5 >/dev/null &&
234 git status -s -b | head -1
236 test_cmp expect actual
243 test_expect_success
'status -s -b (up-to-date with upstream)' '
246 git checkout b6 >/dev/null &&
247 git status -s -b | head -1
249 test_cmp expect actual
252 test_expect_success
'fail to track lightweight tags' '
255 test_must_fail git branch --track lighttrack light >actual &&
256 test_i18ngrep ! "set up to track" actual &&
257 test_must_fail git checkout lighttrack
260 test_expect_success
'fail to track annotated tags' '
262 git tag -m heavy heavy &&
263 test_must_fail git branch --track heavytrack heavy >actual &&
264 test_i18ngrep ! "set up to track" actual &&
265 test_must_fail git checkout heavytrack
268 test_expect_success
'--set-upstream-to does not change branch' '
269 git branch from-main main &&
270 git branch --set-upstream-to main from-main &&
271 git branch from-topic_2 main &&
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 &&
276 git branch --set-upstream-to main from-topic_2 &&
277 git config branch.from-main.merge > actual &&
278 git rev-parse from-topic_2 >actual2 &&
279 grep -q "^refs/heads/main$" actual &&
283 test_expect_success
'--set-upstream-to @{-1}' '
284 git checkout follower &&
285 git checkout from-topic_2 &&
286 git config branch.from-topic_2.merge > expect2 &&
287 git branch --set-upstream-to @{-1} from-main &&
288 git config branch.from-main.merge > actual &&
289 git config branch.from-topic_2.merge > actual2 &&
290 git branch --set-upstream-to follower from-main &&
291 git config branch.from-main.merge > expect &&
292 test_cmp expect2 actual2 &&
293 test_cmp expect actual