Skip to content

Commit

Permalink
Updated status to show 'Not currently on any branch' in red
Browse files Browse the repository at this point in the history
This provides additional warning to users when attempting to
commit to a detached HEAD. It is configurable in color.status.nobranch.

Signed-off-by: Chris Parsons <chris@edendevelopment.co.uk>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Chris Parsons authored and Junio C Hamano committed May 23, 2008
1 parent f9189cf commit 950ce2e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,10 @@ color.status.<slot>::
one of `header` (the header text of the status message),
`added` or `updated` (files which are added but not committed),
`changed` (files which are changed but not added in the index),
or `untracked` (files which are not tracked by git). The values of
these variables may be specified as in color.branch.<slot>.
`untracked` (files which are not tracked by git), or
`nobranch` (the color the 'no branch' warning is shown in, defaulting
to red). The values of these variables may be specified as in
color.branch.<slot>.

commit.template::
Specify a file to use as the template for new commit messages.
Expand Down
11 changes: 8 additions & 3 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
"\033[32m", /* WT_STATUS_UPDATED: green */
"\033[31m", /* WT_STATUS_CHANGED: red */
"\033[31m", /* WT_STATUS_UNTRACKED: red */
"\033[31m", /* WT_STATUS_NOBRANCH: red */
};

static const char use_add_msg[] =
Expand All @@ -38,6 +39,8 @@ static int parse_status_slot(const char *var, int offset)
return WT_STATUS_CHANGED;
if (!strcasecmp(var+offset, "untracked"))
return WT_STATUS_UNTRACKED;
if (!strcasecmp(var+offset, "nobranch"))
return WT_STATUS_NOBRANCH;
die("bad config variable '%s'", var);
}

Expand Down Expand Up @@ -314,19 +317,21 @@ static void wt_status_print_verbose(struct wt_status *s)
void wt_status_print(struct wt_status *s)
{
unsigned char sha1[20];
s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
const char *branch_color = color(WT_STATUS_HEADER);

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.";
}
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER),
"# %s%s", on_what, branch_name);
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) {
Expand Down
1 change: 1 addition & 0 deletions wt-status.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum color_wt_status {
WT_STATUS_UPDATED,
WT_STATUS_CHANGED,
WT_STATUS_UNTRACKED,
WT_STATUS_NOBRANCH,
};

struct wt_status {
Expand Down

0 comments on commit 950ce2e

Please sign in to comment.