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

Re: Odd .gitignore behaviour

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 15, 2007, 22:13 UTC
Message-ID
<7vabpf40ow.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<7vir4341ok.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 12 quoted lines
> Bruce Stephens <bruce.stephens@isode.com> writes:
>
>> So I think the output from git-ls-files is as expected (as I interpret
>> the manpage and your explanation).  So is git-add just using some
>> different code?
>
> No, you found one of the longstanding bugs in dir.c:read_directory().
>
> The funny thing is that I just sent out a message pointing out
> bogus handling of per-directory exclude files in ls-files last
> night.  Somehow people have a tendency to encounter the bugs in
> the same vicinity independently.
By the way, about the problem I described briefly last night.

I never understood the intended use of -i option to ls-files, but in your test repository (the one that has subsubdir), you can do:

	$ git ls-files -i --exclude='a*'

to see "What paths have I already _staged_ that would have been ignored if the exclude pattern were 'a*'". You can abuse this to list all the staged header files with:

	$ git ls-files -i --exclude='*.h'
but
	$ git ls-files -- '*.h'
is much simpler for that ;-).

In any case, it appears to me that the codepath used for that "feature", and also the codepath used for -d (show deleted files) and -m (show modified files) makes calls to excluded() function to consult the exclusion mechanism without setting it up properly, and I do not think

	$ git ls-files -i --exclude-per-directory=.gitignore
does what we would want.

The codepath for -o (show others) do use read_directory() which sets up the exclusion mechanism with push/pop per-directory exclude API, so that option should work. But I suspect even it did not work from a subdirectory because of the problem the message I am responding to addresses.

Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 8 in “Odd .gitignore behaviour”
  1. Bruce StephensNov 15, 2007
  2. Linus TorvaldsNov 15, 2007
  3. Bruce StephensNov 15, 2007
  4. Junio C HamanoNov 15, 2007
  5. Junio C HamanoNov 15, 2007
  6. Fix per-directory exclude handing for "git add"Junio C Hamano, Nov 16, 2007
  7. Bruce StephensNov 16, 2007
  8. Bruce StephensNov 16, 2007

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.