Merge branch 'aa/status-hilite-branch'
* aa/status-hilite-branch: default color.status.branch to "same as header" status: show branchname with a configurable color
This commit is contained in:
commit
f68b780b25
@ -790,7 +790,8 @@ 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),
|
||||
`untracked` (files which are not tracked by git), or
|
||||
`untracked` (files which are not tracked by git),
|
||||
`branch` (the current branch), 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>.
|
||||
|
@ -1011,6 +1011,8 @@ static int parse_status_slot(const char *var, int offset)
|
||||
{
|
||||
if (!strcasecmp(var+offset, "header"))
|
||||
return WT_STATUS_HEADER;
|
||||
if (!strcasecmp(var+offset, "branch"))
|
||||
return WT_STATUS_ONBRANCH;
|
||||
if (!strcasecmp(var+offset, "updated")
|
||||
|| !strcasecmp(var+offset, "added"))
|
||||
return WT_STATUS_UPDATED;
|
||||
|
5
color.c
5
color.c
@ -211,3 +211,8 @@ int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...)
|
||||
va_end(args);
|
||||
return r;
|
||||
}
|
||||
|
||||
int color_is_nil(const char *c)
|
||||
{
|
||||
return !strcmp(c, "NIL");
|
||||
}
|
||||
|
5
color.h
5
color.h
@ -43,6 +43,9 @@
|
||||
#define GIT_COLOR_BG_MAGENTA "\033[45m"
|
||||
#define GIT_COLOR_BG_CYAN "\033[46m"
|
||||
|
||||
/* A special value meaning "no color selected" */
|
||||
#define GIT_COLOR_NIL "NIL"
|
||||
|
||||
/*
|
||||
* This variable stores the value of color.ui
|
||||
*/
|
||||
@ -62,4 +65,6 @@ int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
|
||||
__attribute__((format (printf, 3, 4)))
|
||||
int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
|
||||
|
||||
int color_is_nil(const char *color);
|
||||
|
||||
#endif /* COLOR_H */
|
||||
|
@ -405,12 +405,13 @@ test_expect_success 'status --porcelain ignores relative paths setting' '
|
||||
|
||||
test_expect_success 'setup unique colors' '
|
||||
|
||||
git config status.color.untracked blue
|
||||
git config status.color.untracked blue &&
|
||||
git config status.color.branch green
|
||||
|
||||
'
|
||||
|
||||
cat >expect <<\EOF
|
||||
# On branch master
|
||||
# On branch <GREEN>master<RESET>
|
||||
# Changes to be committed:
|
||||
# (use "git reset HEAD <file>..." to unstage)
|
||||
#
|
||||
|
14
wt-status.c
14
wt-status.c
@ -21,11 +21,15 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
|
||||
GIT_COLOR_RED, /* WT_STATUS_UNMERGED */
|
||||
GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */
|
||||
GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */
|
||||
GIT_COLOR_NIL, /* WT_STATUS_ONBRANCH */
|
||||
};
|
||||
|
||||
static const char *color(int slot, struct wt_status *s)
|
||||
{
|
||||
return s->use_color > 0 ? s->color_palette[slot] : "";
|
||||
const char *c = s->use_color > 0 ? s->color_palette[slot] : "";
|
||||
if (slot == WT_STATUS_ONBRANCH && color_is_nil(c))
|
||||
c = s->color_palette[WT_STATUS_HEADER];
|
||||
return c;
|
||||
}
|
||||
|
||||
void wt_status_prepare(struct wt_status *s)
|
||||
@ -625,7 +629,8 @@ static void wt_status_print_tracking(struct wt_status *s)
|
||||
|
||||
void wt_status_print(struct wt_status *s)
|
||||
{
|
||||
const char *branch_color = color(WT_STATUS_HEADER, s);
|
||||
const char *branch_color = color(WT_STATUS_ONBRANCH, s);
|
||||
const char *branch_status_color = color(WT_STATUS_HEADER, s);
|
||||
|
||||
if (s->branch) {
|
||||
const char *on_what = "On branch ";
|
||||
@ -634,11 +639,12 @@ void wt_status_print(struct wt_status *s)
|
||||
branch_name += 11;
|
||||
else if (!strcmp(branch_name, "HEAD")) {
|
||||
branch_name = "";
|
||||
branch_color = color(WT_STATUS_NOBRANCH, s);
|
||||
branch_status_color = color(WT_STATUS_NOBRANCH, s);
|
||||
on_what = "Not currently on any branch.";
|
||||
}
|
||||
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# ");
|
||||
color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name);
|
||||
color_fprintf(s->fp, branch_status_color, "%s", on_what);
|
||||
color_fprintf_ln(s->fp, branch_color, "%s", branch_name);
|
||||
if (!s->is_initial)
|
||||
wt_status_print_tracking(s);
|
||||
}
|
||||
|
@ -13,7 +13,9 @@ enum color_wt_status {
|
||||
WT_STATUS_NOBRANCH,
|
||||
WT_STATUS_UNMERGED,
|
||||
WT_STATUS_LOCAL_BRANCH,
|
||||
WT_STATUS_REMOTE_BRANCH
|
||||
WT_STATUS_REMOTE_BRANCH,
|
||||
WT_STATUS_ONBRANCH,
|
||||
WT_STATUS_MAXSLOT
|
||||
};
|
||||
|
||||
enum untracked_status_type {
|
||||
@ -46,7 +48,7 @@ struct wt_status {
|
||||
int show_ignored_files;
|
||||
enum untracked_status_type show_untracked_files;
|
||||
const char *ignore_submodule_arg;
|
||||
char color_palette[WT_STATUS_REMOTE_BRANCH+1][COLOR_MAXLEN];
|
||||
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
|
||||
|
||||
/* These are computed during processing of the individual sections */
|
||||
int commitable;
|
||||
|
Loading…
Reference in New Issue
Block a user