Skip to content

Commit 950ce2e

Browse files
edendevelopmentgitster
authored andcommitted
Updated status to show 'Not currently on any branch' in red
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>
1 parent f9189cf commit 950ce2e

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Documentation/config.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,10 @@ color.status.<slot>::
523523
one of `header` (the header text of the status message),
524524
`added` or `updated` (files which are added but not committed),
525525
`changed` (files which are changed but not added in the index),
526-
or `untracked` (files which are not tracked by git). The values of
527-
these variables may be specified as in color.branch.<slot>.
526+
`untracked` (files which are not tracked by git), or
527+
`nobranch` (the color the 'no branch' warning is shown in, defaulting
528+
to red). The values of these variables may be specified as in
529+
color.branch.<slot>.
528530

529531
commit.template::
530532
Specify a file to use as the template for new commit messages.

wt-status.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
1818
"\033[32m", /* WT_STATUS_UPDATED: green */
1919
"\033[31m", /* WT_STATUS_CHANGED: red */
2020
"\033[31m", /* WT_STATUS_UNTRACKED: red */
21+
"\033[31m", /* WT_STATUS_NOBRANCH: red */
2122
};
2223

2324
static const char use_add_msg[] =
@@ -38,6 +39,8 @@ static int parse_status_slot(const char *var, int offset)
3839
return WT_STATUS_CHANGED;
3940
if (!strcasecmp(var+offset, "untracked"))
4041
return WT_STATUS_UNTRACKED;
42+
if (!strcasecmp(var+offset, "nobranch"))
43+
return WT_STATUS_NOBRANCH;
4144
die("bad config variable '%s'", var);
4245
}
4346

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

322+
s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
319323
if (s->branch) {
320324
const char *on_what = "On branch ";
321325
const char *branch_name = s->branch;
322326
if (!prefixcmp(branch_name, "refs/heads/"))
323327
branch_name += 11;
324328
else if (!strcmp(branch_name, "HEAD")) {
325329
branch_name = "";
330+
branch_color = color(WT_STATUS_NOBRANCH);
326331
on_what = "Not currently on any branch.";
327332
}
328-
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER),
329-
"# %s%s", on_what, branch_name);
333+
color_fprintf(s->fp, color(WT_STATUS_HEADER), "# ");
334+
color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name);
330335
}
331336

332337
if (s->is_initial) {

wt-status.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum color_wt_status {
88
WT_STATUS_UPDATED,
99
WT_STATUS_CHANGED,
1010
WT_STATUS_UNTRACKED,
11+
WT_STATUS_NOBRANCH,
1112
};
1213

1314
struct wt_status {

0 commit comments

Comments
 (0)