]> git.neil.brown.name Git - git.git/commitdiff
Merge branch 'kn/ref-filter-branch-list' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 12 Jul 2017 22:23:09 +0000 (15:23 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Jul 2017 22:23:09 +0000 (15:23 -0700)
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

builtin/branch.c
ref-filter.c
t/t3205-branch-color.sh [new file with mode: 0755]

index 48a513a84dbf6cf2516a10cbcced267369bc747c..a3bd2262b33672d7277553d77a0ac0e1830395d5 100644 (file)
@@ -334,8 +334,11 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
        struct strbuf local = STRBUF_INIT;
        struct strbuf remote = STRBUF_INIT;
 
-       strbuf_addf(&fmt, "%%(if)%%(HEAD)%%(then)* %s%%(else)  %%(end)",
-                   branch_get_color(BRANCH_COLOR_CURRENT));
+       strbuf_addf(&local, "%%(if)%%(HEAD)%%(then)* %s%%(else)  %s%%(end)",
+                   branch_get_color(BRANCH_COLOR_CURRENT),
+                   branch_get_color(BRANCH_COLOR_LOCAL));
+       strbuf_addf(&remote, "  %s",
+                   branch_get_color(BRANCH_COLOR_REMOTE));
 
        if (filter->verbose) {
                struct strbuf obname = STRBUF_INIT;
@@ -358,17 +361,17 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
                else
                        strbuf_addf(&local, "%%(if)%%(upstream:track)%%(then)%%(upstream:track) %%(end)%%(contents:subject)");
 
-               strbuf_addf(&remote, "%s%%(align:%d,left)%s%%(refname:lstrip=2)%%(end)%s"
+               strbuf_addf(&remote, "%%(align:%d,left)%s%%(refname:lstrip=2)%%(end)%s"
                            "%%(if)%%(symref)%%(then) -> %%(symref:short)"
                            "%%(else) %s %%(contents:subject)%%(end)",
-                           branch_get_color(BRANCH_COLOR_REMOTE), maxwidth, quote_literal_for_format(remote_prefix),
+                           maxwidth, quote_literal_for_format(remote_prefix),
                            branch_get_color(BRANCH_COLOR_RESET), obname.buf);
                strbuf_release(&obname);
        } else {
                strbuf_addf(&local, "%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
                            branch_get_color(BRANCH_COLOR_RESET));
-               strbuf_addf(&remote, "%s%s%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
-                           branch_get_color(BRANCH_COLOR_REMOTE), quote_literal_for_format(remote_prefix),
+               strbuf_addf(&remote, "%s%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
+                           quote_literal_for_format(remote_prefix),
                            branch_get_color(BRANCH_COLOR_RESET));
        }
 
index 2cc7b01277ca8565302eb1648c065ecbb1a25f47..467c0279c9b6370b57080b5f1fcf20bdfd7e451e 100644 (file)
@@ -221,7 +221,7 @@ static void objectname_atom_parser(struct used_atom *atom, const char *arg)
 
 static void refname_atom_parser(struct used_atom *atom, const char *arg)
 {
-       return refname_atom_parser_internal(&atom->u.refname, arg, atom->name);
+       refname_atom_parser_internal(&atom->u.refname, arg, atom->name);
 }
 
 static align_type parse_align_position(const char *s)
diff --git a/t/t3205-branch-color.sh b/t/t3205-branch-color.sh
new file mode 100755 (executable)
index 0000000..9343550
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+test_description='basic branch output coloring'
+. ./test-lib.sh
+
+test_expect_success 'set up some sample branches' '
+       test_commit foo &&
+       git update-ref refs/remotes/origin/master HEAD &&
+       git update-ref refs/heads/other HEAD
+'
+
+# choose non-default colors to make sure config
+# is taking effect
+test_expect_success 'set up some color config' '
+       git config color.branch always &&
+       git config color.branch.local blue &&
+       git config color.branch.remote yellow &&
+       git config color.branch.current cyan
+'
+
+test_expect_success 'regular output shows colors' '
+       cat >expect <<-\EOF &&
+       * <CYAN>master<RESET>
+         <BLUE>other<RESET>
+         <YELLOW>remotes/origin/master<RESET>
+       EOF
+       git branch -a >actual.raw &&
+       test_decode_color <actual.raw >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'verbose output shows colors' '
+       oid=$(git rev-parse --short HEAD) &&
+       cat >expect <<-EOF &&
+       * <CYAN>master               <RESET> $oid foo
+         <BLUE>other                <RESET> $oid foo
+         <YELLOW>remotes/origin/master<RESET> $oid foo
+       EOF
+       git branch -v -a >actual.raw &&
+       test_decode_color <actual.raw >actual &&
+       test_cmp expect actual
+'
+
+test_done