3 test_description='remote tracking stats'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
17 test_expect_success setup '
24 git checkout -b b1 origin &&
25 git reset --hard HEAD^ &&
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 &&
34 git checkout -b brokenbase origin &&
35 git checkout -b b5 --track brokenbase &&
37 git branch -d brokenbase &&
38 git checkout -b b6 origin
40 git checkout -b follower --track main &&
44 t6040_script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p'
46 b1 [ahead 1, behind 1] d
47 b2 [ahead 1, behind 1] d
54 test_expect_success 'branch -v' '
59 sed -n -e "$t6040_script" >actual &&
60 test_cmp expect actual
64 b1 [origin/main: ahead 1, behind 1] d
65 b2 [origin/main: ahead 1, behind 1] d
66 b3 [origin/main: behind 1] b
67 b4 [origin/main: ahead 2] f
68 b5 [brokenbase: gone] g
72 test_expect_success 'branch -vv' '
77 sed -n -e "$t6040_script" >actual &&
78 test_cmp expect actual
81 test_expect_success 'checkout (diverged from upstream)' '
83 cd test && git checkout b1
85 test_i18ngrep "have 1 and 1 different" actual
88 test_expect_success 'checkout with local tracked branch' '
90 git checkout follower >actual &&
91 test_i18ngrep "is ahead of" actual
94 test_expect_success 'checkout (upstream is gone)' '
99 test_i18ngrep "is based on .*, but the upstream is gone." actual
102 test_expect_success 'checkout (up-to-date with upstream)' '
104 cd test && git checkout b6
106 test_i18ngrep "Your branch is up to date with .origin/main" actual
109 test_expect_success 'status (diverged from upstream)' '
112 git checkout b1 >/dev/null &&
113 # reports nothing to commit
114 test_must_fail git commit --dry-run
116 test_i18ngrep "have 1 and 1 different" actual
119 test_expect_success 'status (upstream is gone)' '
122 git checkout b5 >/dev/null &&
123 # reports nothing to commit
124 test_must_fail git commit --dry-run
126 test_i18ngrep "is based on .*, but the upstream is gone." actual
129 test_expect_success 'status (up-to-date with upstream)' '
132 git checkout b6 >/dev/null &&
133 # reports nothing to commit
134 test_must_fail git commit --dry-run
136 test_i18ngrep "Your branch is up to date with .origin/main" actual
140 ## b1...origin/main [ahead 1, behind 1]
143 test_expect_success 'status -s -b (diverged from upstream)' '
146 git checkout b1 >/dev/null &&
147 git status -s -b | head -1
149 test_cmp expect actual
153 ## b1...origin/main [different]
156 test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '
159 git checkout b1 >/dev/null &&
160 git status -s -b --no-ahead-behind | head -1
162 test_cmp expect actual
166 ## b1...origin/main [different]
169 test_expect_success 'status.aheadbehind=false status -s -b (diverged from upstream)' '
172 git checkout b1 >/dev/null &&
173 git -c status.aheadbehind=false status -s -b | head -1
175 test_cmp expect actual
180 Your branch and 'origin/main' have diverged,
181 and have 1 and 1 different commits each, respectively.
184 test_expect_success 'status --long --branch' '
187 git checkout b1 >/dev/null &&
188 git status --long -b | head -3
190 test_cmp expect actual
193 test_expect_success 'status --long --branch' '
196 git checkout b1 >/dev/null &&
197 git -c status.aheadbehind=true status --long -b | head -3
199 test_cmp expect actual
204 Your branch and 'origin/main' refer to different commits.
207 test_expect_success 'status --long --branch --no-ahead-behind' '
210 git checkout b1 >/dev/null &&
211 git status --long -b --no-ahead-behind | head -2
213 test_cmp expect actual
216 test_expect_success 'status.aheadbehind=false status --long --branch' '
219 git checkout b1 >/dev/null &&
220 git -c status.aheadbehind=false status --long -b | head -2
222 test_cmp expect actual
226 ## b5...brokenbase [gone]
229 test_expect_success 'status -s -b (upstream is gone)' '
232 git checkout b5 >/dev/null &&
233 git status -s -b | head -1
235 test_cmp expect actual
242 test_expect_success 'status -s -b (up-to-date with upstream)' '
245 git checkout b6 >/dev/null &&
246 git status -s -b | head -1
248 test_cmp expect actual
251 test_expect_success 'fail to track lightweight tags' '
254 test_must_fail git branch --track lighttrack light >actual &&
255 test_i18ngrep ! "set up to track" actual &&
256 test_must_fail git checkout lighttrack
259 test_expect_success 'fail to track annotated tags' '
261 git tag -m heavy heavy &&
262 test_must_fail git branch --track heavytrack heavy >actual &&
263 test_i18ngrep ! "set up to track" actual &&
264 test_must_fail git checkout heavytrack
267 test_expect_success '--set-upstream-to does not change branch' '
268 git branch from-main main &&
269 git branch --set-upstream-to main from-main &&
270 git branch from-topic_2 main &&
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 main from-topic_2 &&
276 git config branch.from-main.merge > actual &&
277 git rev-parse from-topic_2 >actual2 &&
278 grep -q "^refs/heads/main$" actual &&
282 test_expect_success '--set-upstream-to @{-1}' '
283 git checkout follower &&
284 git checkout from-topic_2 &&
285 git config branch.from-topic_2.merge > expect2 &&
286 git branch --set-upstream-to @{-1} from-main &&
287 git config branch.from-main.merge > actual &&
288 git config branch.from-topic_2.merge > actual2 &&
289 git branch --set-upstream-to follower from-main &&
290 git config branch.from-main.merge > expect &&
291 test_cmp expect2 actual2 &&
292 test_cmp expect actual