git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Leo Razoumov <slonik.az@gmail.com>
Cc: Karthik Nayak <karthik.188@gmail.com>,
	Git Mailing List <git@vger.kernel.org>
Subject: [PATCH 2/3] branch: use BRANCH_COLOR_LOCAL in ref-filter format
Date: Sun, 9 Jul 2017 05:59:33 -0400	[thread overview]
Message-ID: <20170709095932.rkmvtmojn3jrw3o5@sigill.intra.peff.net> (raw)
In-Reply-To: <20170709095708.moymrozmqdv2oixx@sigill.intra.peff.net>

Since 949af0684 (branch: use ref-filter printing APIs,
2017-01-10), git-branch's output is generated by passing a
custom format to the ref-filter code. This format forgot to
pass BRANCH_COLOR_LOCAL, meaning that local branches
(besides the current one) were never colored at all.

We can add it in the %(if) block where we decide whether the
branch is "current" or merely "local".  Note that this means
the current/local coloring is either/or. You can't set:

  [color "branch"]
  local = blue
  current = bold

and expect the current branch to be "bold blue". This
matches the pre-949af0684 behavior.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/branch.c        |  5 +++--
 t/t3205-branch-color.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100755 t/t3205-branch-color.sh

diff --git a/builtin/branch.c b/builtin/branch.c
index a849373b7..ee4e93c3a 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -335,8 +335,9 @@ 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(&local, "%%(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, "  ");
 
 	if (filter->verbose) {
diff --git a/t/t3205-branch-color.sh b/t/t3205-branch-color.sh
new file mode 100755
index 000000000..9343550f5
--- /dev/null
+++ b/t/t3205-branch-color.sh
@@ -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
-- 
2.13.2.1066.gabaed60bd


  parent reply	other threads:[~2017-07-09  9:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-08 19:13 git-2.13.2: color.branch.local problem Leo Razoumov
2017-07-09  9:28 ` Jeff King
2017-07-09  9:57   ` Jeff King
2017-07-09  9:58     ` [PATCH 1/3] branch: only perform HEAD check for local branches Jeff King
2017-07-09  9:59     ` Jeff King [this message]
2017-07-09 10:00     ` [PATCH 3/3] branch: set remote color in ref-filter branch immediately Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170709095932.rkmvtmojn3jrw3o5@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    --cc=slonik.az@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).