wt-status: avoid building bogus branch name with detached HEAD
[gitweb.git] / wt-status.c
index 4631119e03a638adfdb650fa782e3d327f018c90..0e4a04e695f63b99d691ad38863e2a5e85a65e76 100644 (file)
@@ -584,6 +584,8 @@ static void wt_status_collect_untracked(struct wt_status *s)
                        DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
        if (s->show_ignored_files)
                dir.flags |= DIR_SHOW_IGNORED_TOO;
+       else
+               dir.untracked = the_index.untracked;
        setup_standard_excludes(&dir);
 
        fill_directory(&dir, &s->pathspec);
@@ -1519,43 +1521,36 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
                return;
        branch_name = s->branch;
 
+       if (s->is_initial)
+               color_fprintf(s->fp, header_color, _("Initial commit on "));
+
+       if (!strcmp(s->branch, "HEAD")) {
+               color_fprintf(s->fp, color(WT_STATUS_NOBRANCH, s), "%s",
+                             _("HEAD (no branch)"));
+               goto conclude;
+       }
+
        if (starts_with(branch_name, "refs/heads/"))
                branch_name += 11;
-       else if (!strcmp(branch_name, "HEAD")) {
-               branch_name = _("HEAD (no branch)");
-               branch_color_local = color(WT_STATUS_NOBRANCH, s);
-       }
 
        branch = branch_get(s->branch + 11);
-       if (s->is_initial)
-               color_fprintf(s->fp, header_color, _("Initial commit on "));
 
        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 */
+       if (stat_tracking_info(branch, &num_ours, &num_theirs, &base) < 0) {
+               if (!base)
+                       goto conclude;
+
                upstream_is_gone = 1;
-               break;
-       default:
-               /* with base */
-               break;
        }
 
-       base = branch->merge[0]->dst;
        base = shorten_unambiguous_ref(base, 0);
        color_fprintf(s->fp, header_color, "...");
        color_fprintf(s->fp, branch_color_remote, "%s", base);
        free((char *)base);
 
-       if (!upstream_is_gone && !num_ours && !num_theirs) {
-               fputc(s->null_termination ? '\0' : '\n', s->fp);
-               return;
-       }
+       if (!upstream_is_gone && !num_ours && !num_theirs)
+               goto conclude;
 
 #define LABEL(string) (s->no_gettext ? (string) : _(string))
 
@@ -1576,6 +1571,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
        }
 
        color_fprintf(s->fp, header_color, "]");
+ conclude:
        fputc(s->null_termination ? '\0' : '\n', s->fp);
 }