threads / discuss / 27531

git status --ignored

Subject: git status --ignored

## tl;dr

7 messages between Jun 2, 2011 and Jun 2, 2011.

replies: 6people: 3as markdown or json

Andrew Spiers· Jun 2, 2011, 04:34 UTC · lore
This looks like a bug in git 1.7.4.1.

git status --ignored does not show my ignored files and directories. git status -h suggests it should. git status --ignored -h does show my ignored files and directories.

Also, git help status does not mention the --ignored switch.
Junio C Hamano· Jun 2, 2011, 05:13 UTC · re: Andrew Spiers · lore

Re: git status --ignored

Andrew Spiers <aspiers@vpac.org> writes:
Show 5 quoted lines
> This looks like a bug in git 1.7.4.1.
>
> git status --ignored does not show my ignored files and
> directories. git status -h suggests it should.
> git status --ignored -h does show my ignored files and directories.

Does not reproduce for me. With --ignored (with or without -s), I see all the dot-o files that are ignored by .gitignore rules that are usually omitted from status output without --ignored.

  $ make >/dev/null 2>&1
  $ rungit v1.7.3 status | grep -F git.o
  $ rungit v1.7.3 status --ignored | grep -F git.o
  #       git.o
  $ rungit v1.7.3 status -s --ignored | grep -F git.o
  !! git.o

The same for v1.7.4.5 or more recent versions. I am not inclined to build and install v1.7.4.1 to test, as I do not think it is likely that the particular version is bad. It is more likely that there is something wrong with your particular setting or expectation. E.g. already tracking a path that would match .gitignore rule, and expecting that such a path is shown, even though it is not "ignored".

> Also, git help status does not mention the --ignored switch.
That may be true; patches welcome.
Jeff King· Jun 2, 2011, 05:54 UTC · re: Junio C Hamano · lore

Re: git status --ignored

On Wed, Jun 01, 2011 at 10:13:55PM -0700, Junio C Hamano wrote:
Show 18 quoted lines
> Andrew Spiers <aspiers@vpac.org> writes:
> 
> > This looks like a bug in git 1.7.4.1.
> >
> > git status --ignored does not show my ignored files and
> > directories. git status -h suggests it should.
> > git status --ignored -h does show my ignored files and directories.
> 
> Does not reproduce for me. With --ignored (with or without -s), I see all
> the dot-o files that are ignored by .gitignore rules that are usually
> omitted from status output without --ignored.
> 
>   $ make >/dev/null 2>&1
>   $ rungit v1.7.3 status | grep -F git.o
>   $ rungit v1.7.3 status --ignored | grep -F git.o
>   #       git.o
>   $ rungit v1.7.3 status -s --ignored | grep -F git.o
>   !! git.o

I can reproduce here. The faulty logic means the bug only shows when you actually have no real untracked files. You should keep your git directory cleaner. ;)

-- >8 --
Subject: [PATCH] status: fix bug with missing --ignore files

Commit 1b908b6 (wt-status: rename and restructure status-print-untracked, 2010-04-10) converted the wt_status_print_untracked function into wt_status_print_other, taking a string_list of either untracked or ignored items to print. However, the "nothing to show" early return still checked the wt_status->untracked list instead of the passed-in list.

That meant that if we had ignored items to show, but no untracked items, we would erroneously exit early and fail to show the ignored items.

Signed-off-by: Jeff King <peff@peff.net>
---
 wt-status.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index 9f4e0ba..0237772 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -642,7 +642,7 @@ static void wt_status_print_other(struct wt_status *s,
 	int i;
 	struct strbuf buf = STRBUF_INIT;
 
-	if (!s->untracked.nr)
+	if (!l->nr)
 		return;
 
 	wt_status_print_other_header(s, what, how);
-- 
1.7.6.rc0.34.gc8c48c.dirty
Jeff King· Jun 2, 2011, 05:57 UTC · re: Jeff King · lore

Re: git status --ignored

On Thu, Jun 02, 2011 at 01:54:49AM -0400, Jeff King wrote:
> That meant that if we had ignored items to show, but no
> untracked items, we would erroneously exit early and fail to
> show the ignored items.

BTW, we could probably use some tests for "status --ignore". I'll leave that to you as penance for your bug, if you want them. :)

-Peff
Junio C Hamano· Jun 2, 2011, 16:08 UTC · re: Jeff King · lore

Re: git status --ignored

Jeff King <peff@peff.net> writes:
> I can reproduce here. The faulty logic means the bug only shows when you
> actually have no real untracked files. You should keep your git
> directory cleaner. ;)
Ok.
-- >8 --
Subject: [PATCH] git status --ignored: tests and docs
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/git-status.txt |    6 ++++
 t/t7508-status.sh            |   64 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index 1cab91b..b663e51 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -49,6 +49,9 @@ See linkgit:git-config[1] for configuration variable
 used to change the default for when the option is not
 specified.
 
+--ignored::
+	Show ignored files as well.
+
 -z::
 	Terminate entries with NUL, instead of LF.  This implies
 	the `--porcelain` output format if no other format is given.
@@ -80,6 +83,8 @@ shows the status of stage #3 (i.e. theirs).
 For entries that do not have conflicts, `X` shows the status of the index,
 and `Y` shows the status of the work tree.  For untracked paths, `XY` are
 `??`.
+For ignored paths, `XY` are `!!`; they are shown only when the `--ignored`
+option is in effect.
 
     X          Y     Meaning
     -------------------------------------------------
@@ -102,6 +107,7 @@ and `Y` shows the status of the work tree.  For untracked paths, `XY` are
     U           U    unmerged, both modified
     -------------------------------------------------
     ?           ?    untracked
+    !           !    ignored
     -------------------------------------------------
 
 
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 556d0fa..b47aad8 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -86,6 +86,70 @@ test_expect_success 'status -s (2)' '
 
 '
 
+test_expect_success 'status with gitignore' '
+	{
+		echo ".gitignore" &&
+		echo "expect" &&
+		echo "output" &&
+		echo "untracked"
+	} >.gitignore &&
+
+	cat >expect <<-\EOF &&
+	 M dir1/modified
+	A  dir2/added
+	?? dir2/modified
+	EOF
+	git status -s >output &&
+	test_cmp expect output &&
+
+	cat >expect <<-\EOF &&
+	 M dir1/modified
+	A  dir2/added
+	?? dir2/modified
+	!! .gitignore
+	!! dir1/untracked
+	!! dir2/untracked
+	!! expect
+	!! output
+	!! untracked
+	EOF
+	git status -s --ignored >output &&
+	test_cmp expect output
+'
+
+test_expect_success 'status with gitignore' '
+	{
+		echo ".gitignore" &&
+		echo "expect" &&
+		echo "dir2/modified" &&
+		echo "output" &&
+		echo "untracked"
+	} >.gitignore &&
+
+	cat >expect <<-\EOF &&
+	 M dir1/modified
+	A  dir2/added
+	EOF
+	git status -s >output &&
+	test_cmp expect output &&
+
+	cat >expect <<-\EOF &&
+	 M dir1/modified
+	A  dir2/added
+	!! .gitignore
+	!! dir1/untracked
+	!! dir2/modified
+	!! dir2/untracked
+	!! expect
+	!! output
+	!! untracked
+	EOF
+	git status -s --ignored >output &&
+	test_cmp expect output
+'
+
+rm -f .gitignore
+
 cat >expect <<EOF
 # On branch master
 # Changes to be committed:
-- 
1.7.6.rc0.98.gc12085
Jeff King· Jun 2, 2011, 17:20 UTC · re: Junio C Hamano · lore

Re: git status --ignored

On Thu, Jun 02, 2011 at 09:08:18AM -0700, Junio C Hamano wrote:
Show 13 quoted lines
> +	cat >expect <<-\EOF &&
> +	 M dir1/modified
> +	A  dir2/added
> +	?? dir2/modified
> +	!! .gitignore
> +	!! dir1/untracked
> +	!! dir2/untracked
> +	!! expect
> +	!! output
> +	!! untracked
> +	EOF
> +	git status -s --ignored >output &&
> +	test_cmp expect output

Unfortunately this does not actually show the bug, as the short format takes a different code path that was not broken.

I have mixed feelings about putting the whole long format in a test vector, as all of the human-readable bits are supposed to be allowed to change. And I know that tests are only partially about demonstrating a particular bug, and more about codifying the behavior we want so future changes don't break it. But it is nice to exercise that code path, and it doesn't change all that much, so maybe it is worth doing. Squashable patch below. Throw it out if you don't agree.

> +test_expect_success 'status with gitignore' '

It took me a minute to figure out what was different between the two tests with the same title. Maybe calling them "status with gitignore (untracked files present)" and "status with gitignore (no untracked files)" would help future readers.

---
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index b47aad8..957c1e3 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -115,6 +115,36 @@ test_expect_success 'status with gitignore' '
 	EOF
 	git status -s --ignored >output &&
 	test_cmp expect output
+
+	cat >expect <<-\EOF &&
+	# On branch master
+	# Changes to be committed:
+	#   (use "git reset HEAD <file>..." to unstage)
+	#
+	#	new file:   dir2/added
+	#
+	# Changed but not updated:
+	#   (use "git add <file>..." to update what will be committed)
+	#   (use "git checkout -- <file>..." to discard changes in working directory)
+	#
+	#	modified:   dir1/modified
+	#
+	# Untracked files:
+	#   (use "git add <file>..." to include in what will be committed)
+	#
+	#	dir2/modified
+	# Ignored files:
+	#   (use "git add -f <file>..." to include in what will be committed)
+	#
+	#	.gitignore
+	#	dir1/untracked
+	#	dir2/untracked
+	#	expect
+	#	output
+	#	untracked
+	EOF
+	git status --ignored >output &&
+	test_cmp expect output
 '
 
 test_expect_success 'status with gitignore' '
@@ -146,6 +176,33 @@ test_expect_success 'status with gitignore' '
 	EOF
 	git status -s --ignored >output &&
 	test_cmp expect output
+
+	cat >expect <<-\EOF &&
+	# On branch master
+	# Changes to be committed:
+	#   (use "git reset HEAD <file>..." to unstage)
+	#
+	#	new file:   dir2/added
+	#
+	# Changed but not updated:
+	#   (use "git add <file>..." to update what will be committed)
+	#   (use "git checkout -- <file>..." to discard changes in working directory)
+	#
+	#	modified:   dir1/modified
+	#
+	# Ignored files:
+	#   (use "git add -f <file>..." to include in what will be committed)
+	#
+	#	.gitignore
+	#	dir1/untracked
+	#	dir2/modified
+	#	dir2/untracked
+	#	expect
+	#	output
+	#	untracked
+	EOF
+	git status --ignored >output &&
+	test_cmp expect output
 '
 
 rm -f .gitignore

← back to recent threads