status: show branchname with a configurable color
You can tell "git status" to paint the name of the current branch in its output (the line that says "On branch ...") by setting the configuration variable color.status.branch; it is by default turned off. Signed-off-by: Aleksi Aalto <aga@iki.fi> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Aleksi Aalto committed
Nov 18, 2010 at 01:40 UTC
1d282327d7354dd3a1caefa4af06562aa816710d
5 files changed
+17
-8
Documentation/config.txt
+2
-1
@@ -774,7 +774,8 @@ color.status.<slot>::
774
one of `header` (the header text of the status message),
775
`added` or `updated` (files which are added but not committed),
776
`changed` (files which are changed but not added in the index),
777
- `untracked` (files which are not tracked by git), or
777
+ `untracked` (files which are not tracked by git),
778
+ `branch` (the current branch), or
779
`nobranch` (the color the 'no branch' warning is shown in, defaulting
780
to red). The values of these variables may be specified as in
781
color.branch.<slot>.
builtin/commit.c
+2
@@ -984,6 +984,8 @@ static int parse_status_slot(const char *var, int offset)
984
{
985
if (!strcasecmp(var+offset, "header"))
986
return WT_STATUS_HEADER;
987
+ if (!strcasecmp(var+offset, "branch"))
988
+ return WT_STATUS_ONBRANCH;
989
if (!strcasecmp(var+offset, "updated")
990
|| !strcasecmp(var+offset, "added"))
991
return WT_STATUS_UPDATED;
t/t7508-status.sh
+3
-2
@@ -381,12 +381,13 @@ test_expect_success 'status --porcelain ignores relative paths setting' '
381
382
test_expect_success 'setup unique colors' '
383
384
- git config status.color.untracked blue
384
+ git config status.color.untracked blue &&
385
+ git config status.color.branch green
386
387
'
388
389
cat >expect <<\EOF
389
-# On branch master
390
+# On branch <GREEN>master<RESET>
391
# Changes to be committed:
392
# (use "git reset HEAD <file>..." to unstage)
393
#
wt-status.c
+6
-3
@@ -21,6 +21,7 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
21
GIT_COLOR_RED, /* WT_STATUS_UNMERGED */
22
GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */
23
GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */
24
+ GIT_COLOR_NORMAL, /* WT_STATUS_ONBRANCH */
25
};
26
27
static const char *color(int slot, struct wt_status *s)
@@ -625,7 +626,8 @@ static void wt_status_print_tracking(struct wt_status *s)
626
627
void wt_status_print(struct wt_status *s)
628
{
628
- const char *branch_color = color(WT_STATUS_HEADER, s);
629
+ const char *branch_color = color(WT_STATUS_ONBRANCH, s);
630
+ const char *branch_status_color = color(WT_STATUS_HEADER, s);
631
632
if (s->branch) {
633
const char *on_what = "On branch ";
@@ -634,11 +636,12 @@ void wt_status_print(struct wt_status *s)
636
branch_name += 11;
637
else if (!strcmp(branch_name, "HEAD")) {
638
branch_name = "";
637
- branch_color = color(WT_STATUS_NOBRANCH, s);
639
+ branch_status_color = color(WT_STATUS_NOBRANCH, s);
640
on_what = "Not currently on any branch.";
641
}
642
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# ");
641
- color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name);
643
+ color_fprintf(s->fp, branch_status_color, "%s", on_what);
644
+ color_fprintf_ln(s->fp, branch_color, "%s", branch_name);
645
if (!s->is_initial)
646
wt_status_print_tracking(s);
647
}
wt-status.h
+4
-2
@@ -13,7 +13,9 @@ enum color_wt_status {
13
WT_STATUS_NOBRANCH,
14
WT_STATUS_UNMERGED,
15
WT_STATUS_LOCAL_BRANCH,
16
- WT_STATUS_REMOTE_BRANCH
16
+ WT_STATUS_REMOTE_BRANCH,
17
+ WT_STATUS_ONBRANCH,
18
+ WT_STATUS_MAXSLOT
19
};
20
21
enum untracked_status_type {
@@ -46,7 +48,7 @@ struct wt_status {
48
int show_ignored_files;
49
enum untracked_status_type show_untracked_files;
50
const char *ignore_submodule_arg;
49
- char color_palette[WT_STATUS_REMOTE_BRANCH+1][COLOR_MAXLEN];
51
+ char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
52
53
/* These are computed during processing of the individual sections */
54
int commitable;