Skip to content

Commit 55bdfa0

Browse files
committed
Merge branch 'kn/ref-filter-branch-list' into maint
The rewrite of "git branch --list" using for-each-ref's internals that happened in v2.13 regressed its handling of color.branch.local; this has been fixed. * kn/ref-filter-branch-list: ref-filter.c: drop return from void function branch: set remote color in ref-filter branch immediately branch: use BRANCH_COLOR_LOCAL in ref-filter format branch: only perform HEAD check for local branches
2 parents ecab58c + 5b5c9c3 commit 55bdfa0

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

builtin/branch.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,11 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
334334
struct strbuf local = STRBUF_INIT;
335335
struct strbuf remote = STRBUF_INIT;
336336

337-
strbuf_addf(&fmt, "%%(if)%%(HEAD)%%(then)* %s%%(else) %%(end)",
338-
branch_get_color(BRANCH_COLOR_CURRENT));
337+
strbuf_addf(&local, "%%(if)%%(HEAD)%%(then)* %s%%(else) %s%%(end)",
338+
branch_get_color(BRANCH_COLOR_CURRENT),
339+
branch_get_color(BRANCH_COLOR_LOCAL));
340+
strbuf_addf(&remote, " %s",
341+
branch_get_color(BRANCH_COLOR_REMOTE));
339342

340343
if (filter->verbose) {
341344
struct strbuf obname = STRBUF_INIT;
@@ -358,17 +361,17 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
358361
else
359362
strbuf_addf(&local, "%%(if)%%(upstream:track)%%(then)%%(upstream:track) %%(end)%%(contents:subject)");
360363

361-
strbuf_addf(&remote, "%s%%(align:%d,left)%s%%(refname:lstrip=2)%%(end)%s"
364+
strbuf_addf(&remote, "%%(align:%d,left)%s%%(refname:lstrip=2)%%(end)%s"
362365
"%%(if)%%(symref)%%(then) -> %%(symref:short)"
363366
"%%(else) %s %%(contents:subject)%%(end)",
364-
branch_get_color(BRANCH_COLOR_REMOTE), maxwidth, quote_literal_for_format(remote_prefix),
367+
maxwidth, quote_literal_for_format(remote_prefix),
365368
branch_get_color(BRANCH_COLOR_RESET), obname.buf);
366369
strbuf_release(&obname);
367370
} else {
368371
strbuf_addf(&local, "%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
369372
branch_get_color(BRANCH_COLOR_RESET));
370-
strbuf_addf(&remote, "%s%s%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
371-
branch_get_color(BRANCH_COLOR_REMOTE), quote_literal_for_format(remote_prefix),
373+
strbuf_addf(&remote, "%s%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
374+
quote_literal_for_format(remote_prefix),
372375
branch_get_color(BRANCH_COLOR_RESET));
373376
}
374377

ref-filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static void objectname_atom_parser(struct used_atom *atom, const char *arg)
221221

222222
static void refname_atom_parser(struct used_atom *atom, const char *arg)
223223
{
224-
return refname_atom_parser_internal(&atom->u.refname, arg, atom->name);
224+
refname_atom_parser_internal(&atom->u.refname, arg, atom->name);
225225
}
226226

227227
static align_type parse_align_position(const char *s)

t/t3205-branch-color.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
3+
test_description='basic branch output coloring'
4+
. ./test-lib.sh
5+
6+
test_expect_success 'set up some sample branches' '
7+
test_commit foo &&
8+
git update-ref refs/remotes/origin/master HEAD &&
9+
git update-ref refs/heads/other HEAD
10+
'
11+
12+
# choose non-default colors to make sure config
13+
# is taking effect
14+
test_expect_success 'set up some color config' '
15+
git config color.branch always &&
16+
git config color.branch.local blue &&
17+
git config color.branch.remote yellow &&
18+
git config color.branch.current cyan
19+
'
20+
21+
test_expect_success 'regular output shows colors' '
22+
cat >expect <<-\EOF &&
23+
* <CYAN>master<RESET>
24+
<BLUE>other<RESET>
25+
<YELLOW>remotes/origin/master<RESET>
26+
EOF
27+
git branch -a >actual.raw &&
28+
test_decode_color <actual.raw >actual &&
29+
test_cmp expect actual
30+
'
31+
32+
test_expect_success 'verbose output shows colors' '
33+
oid=$(git rev-parse --short HEAD) &&
34+
cat >expect <<-EOF &&
35+
* <CYAN>master <RESET> $oid foo
36+
<BLUE>other <RESET> $oid foo
37+
<YELLOW>remotes/origin/master<RESET> $oid foo
38+
EOF
39+
git branch -v -a >actual.raw &&
40+
test_decode_color <actual.raw >actual &&
41+
test_cmp expect actual
42+
'
43+
44+
test_done

0 commit comments

Comments
 (0)