@matheusbsbs / matheus-bagliano / commits / 950ce2e22d
Fork 0

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>

Chris Parsons committed May 22, 2008 at 08:50 UTC 950ce2e22db4a3c1ff9ad598b46ccb22c517a336
3 files changed +13 -5
Documentation/config.txt
+4 -2
@@ -523,8 +523,10 @@ color.status.<slot>::
523 one of `header` (the header text of the status message),
524 `added` or `updated` (files which are added but not committed),
525 `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>.
530
531 commit.template::
532 Specify a file to use as the template for new commit messages.
wt-status.c
+8 -3
@@ -18,6 +18,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
18 "\033[32m", /* WT_STATUS_UPDATED: green */
19 "\033[31m", /* WT_STATUS_CHANGED: red */
20 "\033[31m", /* WT_STATUS_UNTRACKED: red */
21 + "\033[31m", /* WT_STATUS_NOBRANCH: red */
22 };
23
24 static const char use_add_msg[] =
@@ -38,6 +39,8 @@ static int parse_status_slot(const char *var, int offset)
39 return WT_STATUS_CHANGED;
40 if (!strcasecmp(var+offset, "untracked"))
41 return WT_STATUS_UNTRACKED;
42 + if (!strcasecmp(var+offset, "nobranch"))
43 + return WT_STATUS_NOBRANCH;
44 die("bad config variable '%s'", var);
45 }
46
@@ -314,8 +317,9 @@ static void wt_status_print_verbose(struct wt_status *s)
317 void wt_status_print(struct wt_status *s)
318 {
319 unsigned char sha1[20];
317 - s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
320 + const char *branch_color = color(WT_STATUS_HEADER);
321
322 + s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
323 if (s->branch) {
324 const char *on_what = "On branch ";
325 const char *branch_name = s->branch;
@@ -323,10 +327,11 @@ void wt_status_print(struct wt_status *s)
327 branch_name += 11;
328 else if (!strcmp(branch_name, "HEAD")) {
329 branch_name = "";
330 + branch_color = color(WT_STATUS_NOBRANCH);
331 on_what = "Not currently on any branch.";
332 }
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);
335 }
336
337 if (s->is_initial) {
wt-status.h
+1
@@ -8,6 +8,7 @@ enum color_wt_status {
8 WT_STATUS_UPDATED,
9 WT_STATUS_CHANGED,
10 WT_STATUS_UNTRACKED,
11 + WT_STATUS_NOBRANCH,
12 };
13
14 struct wt_status {