public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
* Expected behavior of "git check-ignore"...
@ 2017-07-20 10:37 John Szakmeister
  2017-07-23 16:33 ` Philip Oakley
  0 siblings, 1 reply; 7+ messages in thread
From: John Szakmeister @ 2017-07-20 10:37 UTC (permalink / raw)
  To: git

A StackOverflow user posted a question about how to reliably check
whether a file would be ignored by "git add" and expected "git
check-ignore" to return results that matched git add's behavior.  It
turns out that it doesn't.  If there is a negation rule, we end up
returning that exclude and printing it and exiting with 0 (there are
some ignored files) even though the file has been marked to not be
ignored.

Is the expected behavior of "git check-ignore" to return 0 even if the
file is not ignore when a negation is present?

>>>>
git init .
echo 'foo/*' > .gitignore
echo '!foo/bar' > .gitignore
mkdir foo
touch foo/bar
git check-ignore foo/bar
<<<<

I expect the last command to return 1 (no files are ignored), but it
doesn't.  The StackOverflow user had the same expectation, and imagine
others do as well.  OTOH, it looks like the command is really meant to
be a debugging tool--to show me the line in a .gitignore associated
with this file, if there is one.  In which case, the behavior is
correct but the return code description is a bit misleading (0 means
the file is ignored, which isn't true here).

Thoughts?  It seems like this question was asked before several years
ago but didn't get a response.

Thanks!

-John

PS The SO question is here:
https://stackoverflow.com/questions/45210790/how-to-reliably-check-whether-a-file-is-ignored-by-git

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-07-30 15:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-20 10:37 Expected behavior of "git check-ignore" John Szakmeister
2017-07-23 16:33 ` Philip Oakley
2017-07-24  9:33   ` John Szakmeister
2017-07-24 19:23     ` Junio C Hamano
2017-07-27 11:20       ` John Szakmeister
2017-07-27 17:05         ` Junio C Hamano
2017-07-30 15:57           ` Philip Oakley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox