summaryrefslogtreecommitdiff
path: root/wt-status.c
diff options
context:
space:
mode:
authorJiang Xin <worldhello.net@gmail.com>2013-08-26 15:02:48 +0800
committerJunio C Hamano <gitster@pobox.com>2013-08-26 09:05:22 -0700
commitf2e087395b78d5828af400072c1b621e1a373be4 (patch)
treea9d657efa55e3c856fa4abb549b3066f5cc82f3c /wt-status.c
parent425df881e08bed7a8fcc9a23f452cff792f9ec6c (diff)
downloadgit-f2e087395b78d5828af400072c1b621e1a373be4.tar.gz
branch: report invalid tracking branch as gone
Command "git branch -vv" will report tracking branches, but invalid tracking branches are also reported. This is because the function stat_tracking_info() can not distinguish invalid tracking branch from other cases which it would not like to report, such as there is no upstream settings at all, or nothing is changed between one branch and its upstream. Junio suggested missing upstream should be reported [1] like: $ git branch -v -v master e67ac84 initial * topic 3fc0f2a [topicbase: gone] topic $ git status # On branch topic # Your branch is based on 'topicbase', but the upstream is gone. # (use "git branch --unset-upstream" to fixup) ... $ git status -b -s ## topic...topicbase [gone] ... In order to do like that, we need to distinguish these three cases (i.e. no tracking, with configured but no longer valid tracking, and with tracking) in function stat_tracking_info(). So the refactored function stat_tracking_info() has three return values: -1 (with "gone" base), 0 (no base), and 1 (with base). If the caller does not like to report tracking info when nothing changed between the branch and its upstream, simply checks if num_theirs and num_ours are both 0. [1]: http://thread.gmane.org/gmane.comp.version-control.git/231830/focus=232288 Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jiang Xin <worldhello.net@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wt-status.c')
-rw-r--r--wt-status.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/wt-status.c b/wt-status.c
index cb24f1fa9b..4b1713efb8 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1365,6 +1365,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
const char *base;
const char *branch_name;
int num_ours, num_theirs;
+ int upstream_is_gone = 0;
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## ");
@@ -1382,20 +1383,37 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
branch = branch_get(s->branch + 11);
if (s->is_initial)
color_fprintf(s->fp, header_color, _("Initial commit on "));
- if (!stat_tracking_info(branch, &num_ours, &num_theirs)) {
- color_fprintf(s->fp, branch_color_local, "%s", branch_name);
+
+ color_fprintf(s->fp, branch_color_local, "%s", branch_name);
+
+ switch (stat_tracking_info(branch, &num_ours, &num_theirs)) {
+ case 0:
+ /* no base */
fputc(s->null_termination ? '\0' : '\n', s->fp);
return;
+ case -1:
+ /* with "gone" base */
+ upstream_is_gone = 1;
+ break;
+ default:
+ /* Stop reporting if neither side has changes. */
+ if (!num_ours && !num_theirs) {
+ fputc(s->null_termination ? '\0' : '\n', s->fp);
+ return;
+ }
+ /* with base */
+ break;
}
base = branch->merge[0]->dst;
base = shorten_unambiguous_ref(base, 0);
- color_fprintf(s->fp, branch_color_local, "%s", branch_name);
color_fprintf(s->fp, header_color, "...");
color_fprintf(s->fp, branch_color_remote, "%s", base);
color_fprintf(s->fp, header_color, " [");
- if (!num_ours) {
+ if (upstream_is_gone) {
+ color_fprintf(s->fp, header_color, _("gone"));
+ } else if (!num_ours) {
color_fprintf(s->fp, header_color, _("behind "));
color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
} else if (!num_theirs) {