git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Lance Ward via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Lance Ward <ljward10@gmail.com>, Lance Ward <ljward10@gmail.com>
Subject: [PATCH] status: fix verbose status coloring inconsistency
Date: Wed, 03 Feb 2021 21:34:03 +0000	[thread overview]
Message-ID: <pull.954.git.git.1612388043875.gitgitgadget@gmail.com> (raw)

From: Lance Ward <ljward10@gmail.com>

Currently setting color.status=always results in a colored diff when
going stdout, but an uncolored diff when going to other files or piping
to other commands such as less or more.  This patch fixes this and now
color.status=always implies color.diff=always regardless of the output
location.

Signed-off-by: Lance Ward <ljward10@gmail.com>
---
    status: fix verbose status coloring inconsistency
    
    Currently setting color.status=always results in a colored diff when
    going stdout, but an uncolored diff when going to other files or piping
    to other commands such as less or more. This patch fixes this and now
    color.status=always implies color.diff=always regardless of the output
    location.
    
    Signed-off-by: Lance Ward ljward10@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-954%2Fljward10%2Flw-fix-status-coloring-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-954/ljward10/lw-fix-status-coloring-v1
Pull-Request: https://github.com/git/git/pull/954

 t/t7527-status-color-pipe.sh | 55 ++++++++++++++++++++++++++++++++++++
 wt-status.c                  |  2 ++
 2 files changed, 57 insertions(+)
 create mode 100755 t/t7527-status-color-pipe.sh

diff --git a/t/t7527-status-color-pipe.sh b/t/t7527-status-color-pipe.sh
new file mode 100755
index 00000000000..88df03ae066
--- /dev/null
+++ b/t/t7527-status-color-pipe.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+test_description='git status color option'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+	echo 1 >original &&
+	git add .
+'
+
+# Normal git status does not pipe colors
+test_expect_success 'git status' '
+	git status >raw &&
+	test_decode_color <raw >out &&
+	grep "original$" out
+'
+
+# Test color.status=never (expect same as above)
+test_expect_success 'git -c color.status=never status' '
+	git -c color.status=never status >raw &&
+	test_decode_color <raw >out &&
+	grep "original$" out
+'
+
+# Test color.status=always
+test_expect_success 'git -c color.status=always status' '
+	git -c color.status=always status >raw &&
+	test_decode_color <raw >out &&
+	grep "original<RESET>$" out
+'
+
+# Test verbose (default)
+test_expect_success 'git status -v' '
+	git status -v >raw &&
+	test_decode_color <raw >out &&
+	grep "+1" out
+'
+
+# Test verbose color.status=never
+test_expect_success 'git -c color.status=never status -v' '
+	git -c color.status=never status -v >raw &&
+	test_decode_color <raw >out &&
+	grep "+1" out
+'
+
+# Test verbose color.status=always
+test_expect_success 'git -c color.status=always status -v' '
+	git -c color.status=always status -v >raw &&
+	test_decode_color <raw >out &&
+	grep "<CYAN>@@ -0,0 +1 @@<RESET>" out &&
+	grep "GREEN>+<RESET><GREEN>1<RESET>" out
+'
+
+test_done
diff --git a/wt-status.c b/wt-status.c
index 0c8287a023e..1e9c899a7b2 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1064,6 +1064,8 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
 	if (s->fp != stdout) {
 		rev.diffopt.use_color = 0;
 		wt_status_add_cut_line(s->fp);
+	} else {
+		rev.diffopt.use_color = s->use_color;
 	}
 	if (s->verbose > 1 && s->committable) {
 		/* print_updated() printed a header, so do we */

base-commit: e6362826a0409539642a5738db61827e5978e2e4
-- 
gitgitgadget

             reply	other threads:[~2021-02-03 21:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 21:34 Lance Ward via GitGitGadget [this message]
2021-02-03 22:51 ` [PATCH] status: fix verbose status coloring inconsistency Junio C Hamano
2021-02-04  0:44   ` Lance Ward
2021-02-05  7:06     ` Eric Sunshine
2021-02-05  7:17   ` Eric Sunshine

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=pull.954.git.git.1612388043875.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=ljward10@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).