Re: [RFC] Detached-HEAD reminder on commit?
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:17
Jakub Narebski [off-list ref] writes:
Perhaps instead of poposed patch we should simply put empty lines
to emphasize that we are on no branch:
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Not currently on any branch.
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)That sounds sensible, easy and safe enough. wt-status.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
diff --git i/wt-status.c w/wt-status.c
index 889e50f..97076e8 100644
--- i/wt-status.c
+++ w/wt-status.c@@ -342,17 +342,17 @@ void wt_status_print(struct wt_status *s) s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0; if (s->branch) { - const char *on_what = "On branch "; - const char *branch_name = s->branch; - if (!prefixcmp(branch_name, "refs/heads/")) - branch_name += 11; - else if (!strcmp(branch_name, "HEAD")) { - branch_name = ""; - branch_color = color(WT_STATUS_NOBRANCH); - on_what = "Not currently on any branch."; + if (!prefixcmp(s->branch, "refs/heads/")) { + color_fprintf(s->fp, color(WT_STATUS_HEADER), "# "); + color_fprintf_ln(s->fp, branch_color, + "On branch %s", s->branch + 11); + } else if (!strcmp(s->branch, "HEAD")) { + color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); + color_fprintf(s->fp, color(WT_STATUS_HEADER), "# "); + color_fprintf_ln(s->fp, color(WT_STATUS_NOBRANCH), + "Not currently on any branch."); + color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); } - color_fprintf(s->fp, color(WT_STATUS_HEADER), "# "); - color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name); if (!s->is_initial) wt_status_print_tracking(s); }