git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] status: fix verbose status coloring inconsistency

From
LGLance Ward via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 3, 2021, 21:34 UTC
Message-ID
<pull.954.git.git.1612388043875.gitgitgadget@gmail.com>
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
Next: Junio C Hamano
Message 1 of 5 in “status: fix verbose status coloring inconsistency”
  1. status: fix verbose status coloring inconsistencyLance Ward via GitGitGadget, Feb 3, 2021
  2. Junio C HamanoFeb 3, 2021
  3. Lance WardFeb 4, 2021
  4. Eric SunshineFeb 5, 2021
  5. Eric SunshineFeb 5, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.