# Teach git status to do "git diff --name-status HEAD"

6 messages from 2008-09-17 to 2008-09-17. Participants: Martin Langhoff, Michael J Gruber, Jakub Narebski, Jeff King.
Thread: https://gitlist.dev/t/15562

## Martin Langhoff, 2008-09-17 06:40

Subject: Teach git status to do "git diff --name-status HEAD"
Message-ID: <aba84270809162340n4ea3f5feqc71d01fa6e035b79@mail.gmail.com>
URL: https://gitlist.dev/e/aba84270809162340n4ea3f5feqc71d01fa6e035b79%40mail.gmail.com

```
I just did

$ git checkout -b mdl19-offlinetony
A       README.offline
M       lib/javascript.php
    (...)
A       lib/offline/offlinemoodle.user.js

I *like* this "brief status" style - takes me back to my cvs days :-).
Perusing the source I found show_local_changes() which in turn led me
to trying `git diff --name-status HEAD`. Now, including 'HEAD' in an
alias defined in git config is going to lead to trouble... :-/

I might still make an alias to `git diff --name-status`. This would be
a great thing to have as git status "--brief" IMHO... :-)

cheers,



m
-- 
 martin@laptop.org -- School Server Architect
 - ask interesting questions
 - don't get distracted with shiny stuff - working code first
 - http://wiki.laptop.org/go/User:Martinlanghoff

```

## Michael J Gruber, 2008-09-17 08:42

Subject: Re: Teach git status to do "git diff --name-status HEAD"
Message-ID: <48D0C2DF.7010308@drmicha.warpmail.net>
URL: https://gitlist.dev/e/48D0C2DF.7010308%40drmicha.warpmail.net
In-Reply-To: <aba84270809162340n4ea3f5feqc71d01fa6e035b79@mail.gmail.com>

```
Martin Langhoff venit, vidit, dixit 17.09.2008 08:40:
> I just did
> 
> $ git checkout -b mdl19-offlinetony
> A       README.offline
> M       lib/javascript.php
>     (...)
> A       lib/offline/offlinemoodle.user.js
> 
> I *like* this "brief status" style - takes me back to my cvs days :-).
> Perusing the source I found show_local_changes() which in turn led me
> to trying `git diff --name-status HEAD`. Now, including 'HEAD' in an
> alias defined in git config is going to lead to trouble... :-/

Nice!
HEAD is default, no need to stick your HEAD into the config ;)

> I might still make an alias to `git diff --name-status`. This would be
> a great thing to have as git status "--brief" IMHO... :-)

git status also shows untracked files. I don't know how to tell diff to
show untracked files as well. --diff-filter=X doesn't do it.

Michael

```

## Jakub Narebski, 2008-09-17 11:04

Subject: Re: Teach git status to do "git diff --name-status HEAD"
Message-ID: <m3ej3jm3ux.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3ej3jm3ux.fsf%40localhost.localdomain
In-Reply-To: <48D0C2DF.7010308@drmicha.warpmail.net>

```
Michael J Gruber <git@drmicha.warpmail.net> writes:

> Martin Langhoff venit, vidit, dixit 17.09.2008 08:40:
> > I just did
> > 
> > $ git checkout -b mdl19-offlinetony
> > A       README.offline
> > M       lib/javascript.php
> >     (...)
> > A       lib/offline/offlinemoodle.user.js
> > 
> > I *like* this "brief status" style - takes me back to my cvs days :-).
> > Perusing the source I found show_local_changes() which in turn led me
> > to trying `git diff --name-status HEAD`. Now, including 'HEAD' in an
> > alias defined in git config is going to lead to trouble... :-/
[...]
> > I might still make an alias to `git diff --name-status`. This would be
> > a great thing to have as git status "--brief" IMHO... :-)
> 
> git status also shows untracked files. I don't know how to tell diff to
> show untracked files as well. --diff-filter=X doesn't do it.

git-ls-files?

-- 
Jakub Narebski
Poland
ShadeHawk on #git

```

## Michael J Gruber, 2008-09-17 11:26

Subject: Re: Teach git status to do "git diff --name-status HEAD"
Message-ID: <48D0E960.1060402@drmicha.warpmail.net>
URL: https://gitlist.dev/e/48D0E960.1060402%40drmicha.warpmail.net
In-Reply-To: <m3ej3jm3ux.fsf@localhost.localdomain>

```
Jakub Narebski venit, vidit, dixit 17.09.2008 13:04:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
> 
>> Martin Langhoff venit, vidit, dixit 17.09.2008 08:40:
>>> I just did
>>>
>>> $ git checkout -b mdl19-offlinetony
>>> A       README.offline
>>> M       lib/javascript.php
>>>     (...)
>>> A       lib/offline/offlinemoodle.user.js
>>>
>>> I *like* this "brief status" style - takes me back to my cvs days :-).
>>> Perusing the source I found show_local_changes() which in turn led me
>>> to trying `git diff --name-status HEAD`. Now, including 'HEAD' in an
>>> alias defined in git config is going to lead to trouble... :-/
> [...]
>>> I might still make an alias to `git diff --name-status`. This would be
>>> a great thing to have as git status "--brief" IMHO... :-)
>> git status also shows untracked files. I don't know how to tell diff to
>> show untracked files as well. --diff-filter=X doesn't do it.
> 
> git-ls-files?

Yes, "git ls-files -t -d -m -o --directory" does something like
"otherscmyouknowwho status". But it's plumbing, and the most obvious
porcelain place for such functionality is "git status", followed by "git
diff".
I do understand that "git status" is mostly "git commit --dry-run". But
shouldn't we have something like Martin suggested readily available
(including, optionally, untracked or ignored files).

Michael

```

## Michael J Gruber, 2008-09-17 15:16

Subject: Mismatch between "git status" and "git ls-files" [was Re: Teach git status to do "git diff --name-status HEAD"]
Message-ID: <48D11F40.4000307@drmicha.warpmail.net>
URL: https://gitlist.dev/e/48D11F40.4000307%40drmicha.warpmail.net
In-Reply-To: <m3ej3jm3ux.fsf@localhost.localdomain>

```
Following up on the discussion about "git status" versus
"youknowwhichscm status" and suggestions to use "git diff --name-status"
or "git ls-files -d -m -o -t" I made a little test case, see the
attached script and output (git version 1.6.0.2.249.g97d7f). Observations:

- "git diff --name-status" and "git ls-files" use very similar form,
even the same status letters, but with completely different meaning for
C, M, R. That is highly confusing (this what I mean by mismatch).

- "git diff --name-status" has no way of showing ignored or untracked files

- "git status" has no way of showing ignored files

- "git ls-files -d -m -o -t" does not distinguish between ignored and
untracked (all is ?)

- "git ls-files" is plumbing, one should not need plumbing to get status
output.

I guess what's needed would be a porcelain that:

- shows state in concise form ("X filename" lines like --name-status or
ls-files -t)
- has options to show ignored and untracked file optionally

To me the most direct approach would be: If "git diff" compares with the
work-tree, teach it to include ignored resp. untracked files optionally.

I guess I wouldn't care about the mismatch then. Are there specific
reasons (other than evolution) for the conflicting status letters?

Michael


Initialized empty Git repository in /tmp/mjg/stats/.git/
Created initial commit 345adf7: files to be changed
 10 files changed, 10 insertions(+), 0 deletions(-)
 create mode 100644 copied
 create mode 100644 gitmoved
 create mode 100644 gitremoved
 create mode 100644 modified
 create mode 100644 modifiedadded
 create mode 100644 moved
 create mode 100644 removed
 create mode 100644 typechanged
 create mode 100644 typechangedadded
 create mode 100644 unchanged
rm 'gitremoved'
### git status ###
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	new file:   added
#	new file:   copiedadded
#	renamed:    gitmoved -> gitmoved2
#	deleted:    gitremoved
#	modified:   modifiedadded
#	modified:   typechangedadded
#
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#
#	modified:   modified
#	deleted:    moved
#	deleted:    removed
#	modified:   typechanged
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	copiedonly
#	moved2
#	untracked
### git diff ###
M	modified
D	moved
D	removed
M	typechanged
### git diff HEAD ###
A	added
C100	copied	copiedadded
R100	gitmoved	gitmoved2
D	gitremoved
M	modified
M	modifiedadded
D	moved
D	removed
M	typechanged
M	typechangedadded
### git diff --cached HEAD ###
A	added
C100	copied	copiedadded
R100	gitmoved	gitmoved2
D	gitremoved
M	modifiedadded
M	typechangedadded
### git ls-files
? copiedonly
? ignored
? moved2
? untracked
C modified
R moved
C moved
R removed
C removed
C typechanged

```

## Jeff King, 2008-09-17 17:31

Subject: Re: Mismatch between "git status" and "git ls-files" [was Re: Teach git status to do "git diff --name-status HEAD"]
Message-ID: <20080917173146.GA29374@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080917173146.GA29374%40coredump.intra.peff.net
In-Reply-To: <48D11F40.4000307@drmicha.warpmail.net>

```
On Wed, Sep 17, 2008 at 05:16:16PM +0200, Michael J Gruber wrote:

> Following up on the discussion about "git status" versus
> "youknowwhichscm status" and suggestions to use "git diff --name-status"
> or "git ls-files -d -m -o -t" I made a little test case, see the
> attached script and output (git version 1.6.0.2.249.g97d7f).
> Observations:

You could also do something like the patch below. It produces output
like this:

  $ git status --terse
  # On branch next
  # Your branch is ahead of 'origin/next' by 1 commit.
  #
  # Changes to be committed:
  M	wt-status.c
  # Changed but not updated:
  M	builtin-commit.c
  M	wt-status.c
  M	wt-status.h
  # Untracked files:
  ? untracked_file
  nothing added to commit but untracked files present (use "git add" to track)

Though there are a few gotchas that make this unsuitable for applying:

  - replacing the callbacks with DIFF_FORMAT_NAME_STATUS isn't quite
    right. You lose the custom colorization, and it fails to set the "we
    have stuff to commit" flag (note in my example that the "nothing
    added to commit" isn't correct). Instead, we would need to do our
    own NAME_STATUS output from the callback (possibly it could be
    factored from diff.c into a general function).

  - The format has lines that don't start with a '#', so it is not
    suitable for a commit message template. So "git commit --terse"
    should be disallowed.

  - There might be other lines that can be stripped.

I personally don't see any real advantage of this format over the
existing status format, so I won't push this patch any further. But if
somebody wants to pick it up and get it into shape, feel free.

---
diff --git a/builtin-commit.c b/builtin-commit.c
index 917f638..e75b508 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -52,6 +52,7 @@ static char *edit_message, *use_message;
 static char *author_name, *author_email, *author_date;
 static int all, edit_flag, also, interactive, only, amend, signoff;
 static int quiet, verbose, no_verify, allow_empty;
+static int terse_status;
 static char *untracked_files_arg;
 /*
  * The default commit message cleanup mode will remove the lines
@@ -107,6 +108,8 @@ static struct option builtin_commit_options[] = {
 	{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
 	OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
 	OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
+	OPT_BOOLEAN(0, "terse", &terse_status,
+			"use a more terse format to display status"),
 
 	OPT_END()
 };
@@ -348,6 +351,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
 		s.amend = 1;
 		s.reference = "HEAD^1";
 	}
+	s.terse = terse_status;
 	s.verbose = verbose;
 	s.untracked = (show_untracked_files == SHOW_ALL_UNTRACKED_FILES);
 	s.index_file = index_file;
diff --git a/wt-status.c b/wt-status.c
index 7cf890f..fd3c2d5 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -87,8 +87,10 @@ static void wt_status_print_untracked_header(struct wt_status *s)
 {
 	const char *c = color(WT_STATUS_HEADER);
 	color_fprintf_ln(s->fp, c, "# Untracked files:");
-	color_fprintf_ln(s->fp, c, "#   (use \"git add <file>...\" to include in what will be committed)");
-	color_fprintf_ln(s->fp, c, "#");
+	if (!s->terse) {
+		color_fprintf_ln(s->fp, c, "#   (use \"git add <file>...\" to include in what will be committed)");
+		color_fprintf_ln(s->fp, c, "#");
+	}
 }
 
 static void wt_status_print_trailer(struct wt_status *s)
@@ -213,9 +215,16 @@ static void wt_status_print_updated(struct wt_status *s)
 	struct rev_info rev;
 	init_revisions(&rev, NULL);
 	setup_revisions(0, NULL, &rev, s->reference);
-	rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
-	rev.diffopt.format_callback = wt_status_print_updated_cb;
-	rev.diffopt.format_callback_data = s;
+	if (s->terse) {
+		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER),
+				"# Changes to be committed:");
+		rev.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
+	}
+	else {
+		rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
+		rev.diffopt.format_callback = wt_status_print_updated_cb;
+		rev.diffopt.format_callback_data = s;
+	}
 	rev.diffopt.detect_rename = 1;
 	rev.diffopt.rename_limit = 200;
 	rev.diffopt.break_opt = 0;
@@ -227,9 +236,16 @@ static void wt_status_print_changed(struct wt_status *s)
 	struct rev_info rev;
 	init_revisions(&rev, "");
 	setup_revisions(0, NULL, &rev, NULL);
-	rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
-	rev.diffopt.format_callback = wt_status_print_changed_cb;
-	rev.diffopt.format_callback_data = s;
+	if (s->terse) {
+		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER),
+				"# Changed but not updated:");
+		rev.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
+	}
+	else {
+		rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
+		rev.diffopt.format_callback = wt_status_print_changed_cb;
+		rev.diffopt.format_callback_data = s;
+	}
 	run_diff_files(&rev, 0);
 }
 
@@ -300,7 +316,10 @@ static void wt_status_print_untracked(struct wt_status *s)
 			wt_status_print_untracked_header(s);
 			shown_header = 1;
 		}
-		color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
+		if (s->terse)
+			color_fprintf(s->fp, color(WT_STATUS_UNTRACKED), "? ");
+		else
+			color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
 		color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED), "%s",
 				quote_path(ent->name, ent->len,
 					&buf, s->prefix));
diff --git a/wt-status.h b/wt-status.h
index 78add09..40fd132 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -23,6 +23,7 @@ struct wt_status {
 	char *branch;
 	const char *reference;
 	int verbose;
+	int terse;
 	int amend;
 	int untracked;
 	int nowarn;

```
