threads / patch / 7986

patchMake --color available to git-status

Subject: [PATCH] Make --color available to git-status

## tl;dr

4 messages between May 5, 2007 and May 6, 2007. Diffs are folded; open one to read it.

replies: 3people: 3as markdown or json

Matthieu Moy· May 5, 2007, 17:37 UTC · lore
Git has a nice colored output for status, using
$ git runstatus --color

However, this --color is not made available to git-status itself. In my understanding, runstatus is plumbing, while status is porcelain, which the average user wants to use.

This patch makes --color available to git-status itself, and documents it.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 Documentation/git-commit.txt |    4 ++++
 Documentation/git-status.txt |    5 ++++-
 git-commit.sh                |   10 ++++++++--
 3 files changed, 16 insertions(+), 3 deletions(-)
Show changes to 3 files +16 −3

Documentation/git-commit.txt, Documentation/git-status.txt, git-commit.sh

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 53a7bb0..2895225 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -118,6 +118,10 @@ but can be used to amend a merge commit.
 -q|--quiet::
 	Suppress commit summary message.
 
+--color::
+	Ignored by git-commit, but present for compatibility with
+	gitlink:git-status[1]. Show colored output for git-status.
+
 \--::
 	Do not interpret any more arguments as options.
 
diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index e9e193f..1d6a240 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -23,9 +23,12 @@ If there is no path that is different between the index file and
 the current HEAD commit, the command exits with non-zero
 status.
 
+
+OPTIONS
+-------
 The command takes the same set of options as `git-commit`; it
 shows what would be committed if the same options are given to
-`git-commit`.
+`git-commit`.  If --color is used, show a colored output.
 
 
 OUTPUT
diff --git a/git-commit.sh b/git-commit.sh
index f28fc24..47f006f 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -3,7 +3,7 @@
 # Copyright (c) 2005 Linus Torvalds
 # Copyright (c) 2006 Junio C Hamano
 
-USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [[-i | -o] <path>...]'
+USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [--color] [[-i | -o] <path>...]'
 SUBDIRECTORY_OK=Yes
 . git-sh-setup
 require_work_tree
@@ -50,7 +50,7 @@ run_status () {
 	fi
 
 	case "$status_only" in
-	t) color= ;;
+	t) ;;
 	*) color=--nocolor ;;
 	esac
 	git-runstatus ${color} \
@@ -87,6 +87,8 @@ signoff=
 force_author=
 only_include_assumed=
 untracked_files=
+color=
+
 while case "$#" in 0) break;; esac
 do
 	case "$1" in
@@ -262,6 +264,10 @@ $1"
 		untracked_files=t
 		shift
 		;;
+	--c|--co|--col|--colo|--color)
+                color=--color
+                shift
+                ;;
 	--)
 		shift
 		break
-- 
1.5.1.3
Johannes Schindelin· May 5, 2007, 17:58 UTC · re: Matthieu Moy · lore

Re: [PATCH] Make --color available to git-status

Hi,
On Sat, 5 May 2007, Matthieu Moy wrote:
Show 5 quoted lines
> Git has a nice colored output for status, using
> 
> $ git runstatus --color
> 
> However, this --color is not made available to git-status itself.

AFAIR there have been attempts to enable this by default, when git-status is run interactively (i.e. its output is not piped). However, this proved to be remarkably complex, given that the output of runstatus _is_ piped.

IMHO the proper solution would be to go the full nine yards, and teach runstatus about the remaining parts of git-status. Then, automatic color works automatically.

Ciao, Dscho

Matthieu Moy· May 6, 2007, 13:58 UTC · re: Johannes Schindelin · lore

Re: [PATCH] Make --color available to git-status

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 13 quoted lines
> Hi,
>
> On Sat, 5 May 2007, Matthieu Moy wrote:
>
>> Git has a nice colored output for status, using
>> 
>> $ git runstatus --color
>> 
>> However, this --color is not made available to git-status itself.
>
> AFAIR there have been attempts to enable this by default, when git-status 
> is run interactively (i.e. its output is not piped). However, this proved 
> to be remarkably complex, given that the output of runstatus _is_ piped.

It would definitely be cool to have it enabled by default, but just having the option (which means in particular that users can use it in an alias) should be the minimum.

I don't have enough experience with git hacking to do all the way you suggest, so I'm starting with easy things ;-).

-- 
Matthieu
Jeff King· May 6, 2007, 20:53 UTC · re: Johannes Schindelin · lore

Re: [PATCH] Make --color available to git-status

On Sat, May 05, 2007 at 07:58:45PM +0200, Johannes Schindelin wrote:
> AFAIR there have been attempts to enable this by default, when git-status 
> is run interactively (i.e. its output is not piped). However, this proved 
> to be remarkably complex, given that the output of runstatus _is_ piped.

I have been running with "status.color" set to "auto" for months, and it works fine. git-status sends the output of runstatus to stdout; only git-commit saves it in a file. However, that is irrelevant here since git-commit explicitly turns off color anyway. The reason for this is that the result ends up in the user's editor and in the commit object. In the editor, it is more elegant to do syntax highlighting at that level (otherwise you have to edit around the escape codes). For the commit object, we would have to put in code to strip the colorization.

My biggest complaint is that git-commit shows the runstatus output to the user if there is nothing to commit, but it isn't colorized (because we created it with the intent of running the editor on it). This could be fixed at the expense of slightly more CPU by simply re-running runstatus instead of using the saved copy.

> IMHO the proper solution would be to go the full nine yards, and teach 
> runstatus about the remaining parts of git-status. Then, automatic color 
> works automatically.

When I rewrote runstatus in C, it was always my intent that it just be a first step in turning git-status into a C builtin (with the ultimate goal of improving the output by parallel walking the HEAD, index, and working tree). Unfortunately, I don't seem to have gotten around to it...

-Peff

← back to recent threads