Skip to content

Commit 768d0fe

Browse files
committed
Merge branch 'kn/ref-filter-branch-list'
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 536c1ec + 5b5c9c3 commit 768d0fe

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
@@ -335,8 +335,11 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
335335
struct strbuf local = STRBUF_INIT;
336336
struct strbuf remote = STRBUF_INIT;
337337

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

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

362-
strbuf_addf(&remote, "%s%%(align:%d,left)%s%%(refname:lstrip=2)%%(end)%s"
365+
strbuf_addf(&remote, "%%(align:%d,left)%s%%(refname:lstrip=2)%%(end)%s"
363366
"%%(if)%%(symref)%%(then) -> %%(symref:short)"
364367
"%%(else) %s %%(contents:subject)%%(end)",
365-
branch_get_color(BRANCH_COLOR_REMOTE), maxwidth, quote_literal_for_format(remote_prefix),
368+
maxwidth, quote_literal_for_format(remote_prefix),
366369
branch_get_color(BRANCH_COLOR_RESET), obname.buf);
367370
strbuf_release(&obname);
368371
} else {
369372
strbuf_addf(&local, "%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
370373
branch_get_color(BRANCH_COLOR_RESET));
371-
strbuf_addf(&remote, "%s%s%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
372-
branch_get_color(BRANCH_COLOR_REMOTE), quote_literal_for_format(remote_prefix),
374+
strbuf_addf(&remote, "%s%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
375+
quote_literal_for_format(remote_prefix),
373376
branch_get_color(BRANCH_COLOR_RESET));
374377
}
375378

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)