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 <worldhello.net@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jiang Xin committed Aug 26, 2013 at 15:02 UTC f223459bec106bbe211a01321e48c050a9cad25e
3 files changed +42 -9
remote.c
+4 -3
@@ -1788,9 +1788,6 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
1788 upstream_is_gone = 1;
1789 break;
1790 default:
1791 - /* Nothing to report if neither side has changes. */
1792 - if (!ours && !theirs)
1793 - return 0;
1791 /* with base */
1792 break;
1793 }
@@ -1804,6 +1801,10 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
1801 if (advice_status_hints)
1802 strbuf_addf(sb,
1803 _(" (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);
1808 } else if (!theirs) {
1809 strbuf_addf(sb,
1810 Q_("Your branch is ahead of '%s' by %d commit.\n",
t/t6040-tracking-info.sh
+33 -1
@@ -32,7 +32,8 @@ test_expect_success setup '
32 git checkout -b brokenbase origin &&
33 git checkout -b b5 --track brokenbase &&
34 advance g &&
35 - git branch -d brokenbase
35 + git branch -d brokenbase &&
36 + git checkout -b b6 origin
37 ) &&
38 git checkout -b follower --track master &&
39 advance h
@@ -61,6 +62,7 @@ b2 origin/master: ahead 1, behind 1
62 b3 origin/master: behind 1
63 b4 origin/master: ahead 2
64 b5 brokenbase: gone
65 +b6 origin/master
66 EOF
67
68 test_expect_success 'branch -vv' '
@@ -93,6 +95,13 @@ test_expect_success 'checkout (upstream is gone)' '
95 test_i18ngrep "is based on .*, but the upstream is gone." actual
96 '
97
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 +
105 test_expect_success 'status (diverged from upstream)' '
106 (
107 cd test &&
@@ -113,6 +122,16 @@ test_expect_success 'status (upstream is gone)' '
122 test_i18ngrep "is based on .*, but the upstream is gone." actual
123 '
124
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 +
135 cat >expect <<\EOF
136 ## b1...origin/master [ahead 1, behind 1]
137 EOF
@@ -139,6 +158,19 @@ test_expect_success 'status -s -b (upstream is gone)' '
158 test_i18ncmp expect actual
159 '
160
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 +
174 test_expect_success 'fail to track lightweight tags' '
175 git checkout master &&
176 git tag light &&
wt-status.c
+5 -5
@@ -1396,11 +1396,6 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1396 upstream_is_gone = 1;
1397 break;
1398 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 - }
1399 /* with base */
1400 break;
1401 }
@@ -1410,6 +1405,11 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1405 color_fprintf(s->fp, header_color, "...");
1406 color_fprintf(s->fp, branch_color_remote, "%s", base);
1407
1408 + if (!upstream_is_gone && !num_ours && !num_theirs) {
1409 + fputc(s->null_termination ? '\0' : '\n', s->fp);
1410 + return;
1411 + }
1412 +
1413 color_fprintf(s->fp, header_color, " [");
1414 if (upstream_is_gone) {
1415 color_fprintf(s->fp, header_color, _("gone"));