Skip to content

Commit f223459

Browse files
jiangxingitster
authored andcommitted
status: always show tracking branch even no change
In order to see what the current branch is tracking, one way is using "git branch -v -v", but branches other than the current are also reported. Another way is using "git status", such as: $ git status # On branch master # Your branch is ahead of 'origin/master' by 1 commit. ... But this will not work if there is no change between the current branch and its upstream. Always report upstream tracking info even if there is no difference, so that "git status" is consistent for checking tracking info for current branch. E.g. $ git status # On branch feature1 # Your branch is up-to-date with 'github/feature1'. ... $ git status -bs ## feature1...github/feature1 ... $ git checkout feature1 Already on 'feature1' Your branch is up-to-date with 'github/feature1'. ... Also add some test cases in t6040. Signed-off-by: Jiang Xin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f2e0873 commit f223459

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

remote.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,9 +1788,6 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
17881788
upstream_is_gone = 1;
17891789
break;
17901790
default:
1791-
/* Nothing to report if neither side has changes. */
1792-
if (!ours && !theirs)
1793-
return 0;
17941791
/* with base */
17951792
break;
17961793
}
@@ -1804,6 +1801,10 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
18041801
if (advice_status_hints)
18051802
strbuf_addf(sb,
18061803
_(" (use \"git branch --unset-upstream\" to fixup)\n"));
1804+
} else if (!ours && !theirs) {
1805+
strbuf_addf(sb,
1806+
_("Your branch is up-to-date with '%s'.\n"),
1807+
base);
18071808
} else if (!theirs) {
18081809
strbuf_addf(sb,
18091810
Q_("Your branch is ahead of '%s' by %d commit.\n",

t/t6040-tracking-info.sh

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ test_expect_success setup '
3232
git checkout -b brokenbase origin &&
3333
git checkout -b b5 --track brokenbase &&
3434
advance g &&
35-
git branch -d brokenbase
35+
git branch -d brokenbase &&
36+
git checkout -b b6 origin
3637
) &&
3738
git checkout -b follower --track master &&
3839
advance h
@@ -61,6 +62,7 @@ b2 origin/master: ahead 1, behind 1
6162
b3 origin/master: behind 1
6263
b4 origin/master: ahead 2
6364
b5 brokenbase: gone
65+
b6 origin/master
6466
EOF
6567

6668
test_expect_success 'branch -vv' '
@@ -93,6 +95,13 @@ test_expect_success 'checkout (upstream is gone)' '
9395
test_i18ngrep "is based on .*, but the upstream is gone." actual
9496
'
9597

98+
test_expect_success 'checkout (up-to-date with upstream)' '
99+
(
100+
cd test && git checkout b6
101+
) >actual &&
102+
test_i18ngrep "Your branch is up-to-date with .origin/master" actual
103+
'
104+
96105
test_expect_success 'status (diverged from upstream)' '
97106
(
98107
cd test &&
@@ -113,6 +122,16 @@ test_expect_success 'status (upstream is gone)' '
113122
test_i18ngrep "is based on .*, but the upstream is gone." actual
114123
'
115124

125+
test_expect_success 'status (up-to-date with upstream)' '
126+
(
127+
cd test &&
128+
git checkout b6 >/dev/null &&
129+
# reports nothing to commit
130+
test_must_fail git commit --dry-run
131+
) >actual &&
132+
test_i18ngrep "Your branch is up-to-date with .origin/master" actual
133+
'
134+
116135
cat >expect <<\EOF
117136
## b1...origin/master [ahead 1, behind 1]
118137
EOF
@@ -139,6 +158,19 @@ test_expect_success 'status -s -b (upstream is gone)' '
139158
test_i18ncmp expect actual
140159
'
141160

161+
cat >expect <<\EOF
162+
## b6...origin/master
163+
EOF
164+
165+
test_expect_success 'status -s -b (up-to-date with upstream)' '
166+
(
167+
cd test &&
168+
git checkout b6 >/dev/null &&
169+
git status -s -b | head -1
170+
) >actual &&
171+
test_i18ncmp expect actual
172+
'
173+
142174
test_expect_success 'fail to track lightweight tags' '
143175
git checkout master &&
144176
git tag light &&

wt-status.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,11 +1396,6 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
13961396
upstream_is_gone = 1;
13971397
break;
13981398
default:
1399-
/* Stop reporting if neither side has changes. */
1400-
if (!num_ours && !num_theirs) {
1401-
fputc(s->null_termination ? '\0' : '\n', s->fp);
1402-
return;
1403-
}
14041399
/* with base */
14051400
break;
14061401
}
@@ -1410,6 +1405,11 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
14101405
color_fprintf(s->fp, header_color, "...");
14111406
color_fprintf(s->fp, branch_color_remote, "%s", base);
14121407

1408+
if (!upstream_is_gone && !num_ours && !num_theirs) {
1409+
fputc(s->null_termination ? '\0' : '\n', s->fp);
1410+
return;
1411+
}
1412+
14131413
color_fprintf(s->fp, header_color, " [");
14141414
if (upstream_is_gone) {
14151415
color_fprintf(s->fp, header_color, _("gone"));

0 commit comments

Comments
 (0)