[PATCH] status: fix verbose status coloring inconsistency

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Lance Ward <ljward10@xxxxxxxxx>

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@xxxxxxxxx>
---
    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@xxxxxxxxx

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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux