git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] status: fix verbose status coloring inconsistency
@ 2021-02-03 21:34 Lance Ward via GitGitGadget
  2021-02-03 22:51 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Lance Ward via GitGitGadget @ 2021-02-03 21:34 UTC (permalink / raw)
  To: git; +Cc: Lance Ward, Lance Ward

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-05  7:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03 21:34 [PATCH] status: fix verbose status coloring inconsistency Lance Ward via GitGitGadget
2021-02-03 22:51 ` Junio C Hamano
2021-02-04  0:44   ` Lance Ward
2021-02-05  7:06     ` Eric Sunshine
2021-02-05  7:17   ` Eric Sunshine

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 NNTP newsgroup(s).