Skip to content

Commit 1d28232

Browse files
Aga303gitster
authored andcommitted
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>
1 parent 7d43de9 commit 1d28232

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

Documentation/config.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,8 @@ color.status.<slot>::
774774
one of `header` (the header text of the status message),
775775
`added` or `updated` (files which are added but not committed),
776776
`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
778779
`nobranch` (the color the 'no branch' warning is shown in, defaulting
779780
to red). The values of these variables may be specified as in
780781
color.branch.<slot>.

builtin/commit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,8 @@ static int parse_status_slot(const char *var, int offset)
984984
{
985985
if (!strcasecmp(var+offset, "header"))
986986
return WT_STATUS_HEADER;
987+
if (!strcasecmp(var+offset, "branch"))
988+
return WT_STATUS_ONBRANCH;
987989
if (!strcasecmp(var+offset, "updated")
988990
|| !strcasecmp(var+offset, "added"))
989991
return WT_STATUS_UPDATED;

t/t7508-status.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,13 @@ test_expect_success 'status --porcelain ignores relative paths setting' '
381381

382382
test_expect_success 'setup unique colors' '
383383
384-
git config status.color.untracked blue
384+
git config status.color.untracked blue &&
385+
git config status.color.branch green
385386
386387
'
387388

388389
cat >expect <<\EOF
389-
# On branch master
390+
# On branch <GREEN>master<RESET>
390391
# Changes to be committed:
391392
# (use "git reset HEAD <file>..." to unstage)
392393
#

wt-status.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
2121
GIT_COLOR_RED, /* WT_STATUS_UNMERGED */
2222
GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */
2323
GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */
24+
GIT_COLOR_NORMAL, /* WT_STATUS_ONBRANCH */
2425
};
2526

2627
static const char *color(int slot, struct wt_status *s)
@@ -625,7 +626,8 @@ static void wt_status_print_tracking(struct wt_status *s)
625626

626627
void wt_status_print(struct wt_status *s)
627628
{
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);
629631

630632
if (s->branch) {
631633
const char *on_what = "On branch ";
@@ -634,11 +636,12 @@ void wt_status_print(struct wt_status *s)
634636
branch_name += 11;
635637
else if (!strcmp(branch_name, "HEAD")) {
636638
branch_name = "";
637-
branch_color = color(WT_STATUS_NOBRANCH, s);
639+
branch_status_color = color(WT_STATUS_NOBRANCH, s);
638640
on_what = "Not currently on any branch.";
639641
}
640642
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);
642645
if (!s->is_initial)
643646
wt_status_print_tracking(s);
644647
}

wt-status.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ enum color_wt_status {
1313
WT_STATUS_NOBRANCH,
1414
WT_STATUS_UNMERGED,
1515
WT_STATUS_LOCAL_BRANCH,
16-
WT_STATUS_REMOTE_BRANCH
16+
WT_STATUS_REMOTE_BRANCH,
17+
WT_STATUS_ONBRANCH,
18+
WT_STATUS_MAXSLOT
1719
};
1820

1921
enum untracked_status_type {
@@ -46,7 +48,7 @@ struct wt_status {
4648
int show_ignored_files;
4749
enum untracked_status_type show_untracked_files;
4850
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];
5052

5153
/* These are computed during processing of the individual sections */
5254
int commitable;

0 commit comments

Comments
 (0)