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

Re: Fwd: Unexpected behavior of ls-files command when using --others --exclude-from, and a .gitignore file which resides in a subdirectory

From
Jeff King <peff@peff.net>
Date
Jan 22, 2024, 21:34 UTC
Message-ID
<20240122213410.GA811766@coredump.intra.peff.net>
In-Reply-To
<CAGF1KhWiYX=3R01Odj2yCNgvx=f5+HRCjRJogWf5eBikuATCcg@mail.gmail.com>
On Mon, Jan 22, 2024 at 09:45:46PM +0100, Raúl Núñez de Arenas Coronado wrote:
Show 11 quoted lines
> But when using 'git ls-files --others --exclude-from=<file>', when
> <file> is one of those .gitignore files present in a subdir, makes the
> command use the patterns in that .gitgnore (in this case, the "*")
> against ALL files that would otherwise be listed by using '--others'.
>
> In short: using 'git ls-files --others
> --exclude-from=subdir/.gitignore' results in an empty listing if
> subdir/.gitignore contains '*". IMHO that pattern should be applied to
> the subdir contents and not to the contents of the current directory.
> That would be consistent with how git uses .gitignore files in
> subfolders.

I think Junio covered this with his example, and everything is behaving as intended (my mental model is that "--exclude-from" is something like .git/info/exclude or the core.excludesFile option).

But...
> The obvious solution is to use --exclude-per-directory but it is
> deprecated in favor of --exclude-standard and --exclude-standard shows
> the same behaviour of --exclude-from=subdir/.gitignore!!!

...I'm not sure what's going on here. I would think that both --exclude-standard and --exclude-per-directory would do what you want.

For example, I get:
  [setup]
  $ git init
  $ mkdir subdir
  $ echo '*' >subdir/.gitignore
  $ git add -f subdir/.gitignore && git commit -m "add gitignore"
  $ touch subdir/file file
  [no exclusions]
  $ git ls-files -o
  file
  subdir/file
  [use .gitignore]
  $ git ls-files --exclude-per-directory=.gitignore -o
  file
  [using standard excludes]
  $ git ls-files --exclude-standard -o
  file

Do you get different results from that toy repo? If not, then what is different about your main repo? Do you perhaps have a stray "*" match somewhere in .git/info/exclude, etc? Or are you still providing --exclude-from in addition to --exclude-standard?

-Peff
PS I hadn't realized that --exclude-per-directory had been marked as
   deprecated. I do agree with e750951e74 (ls-files: guide folks to
   --exclude-standard over other --exclude* options, 2023-01-13) in its
   goal of guiding people to the easiest option, but I don't know that
   there has been any discussion about removing the other ones.
Previous: Raúl Núñez de Arenas CoronadoNext: Junio C Hamano
Message 6 of 14 in “Fwd: Unexpected behavior of ls-files command when using --others --exclude-from, and a .gitignore file which resides in a subdirectory”
  1. Raúl Núñez de Arenas CoronadoJan 22, 2024
  2. Junio C HamanoJan 22, 2024
  3. Raúl Núñez de Arenas CoronadoJan 22, 2024
  4. Junio C HamanoJan 22, 2024
  5. Raúl Núñez de Arenas CoronadoJan 23, 2024
  6. Jeff KingJan 22, 2024
  7. Junio C HamanoJan 22, 2024
  8. Jeff KingJan 22, 2024
  9. Elijah NewrenJan 24, 2024
  10. Junio C HamanoJan 24, 2024
  11. Jeff KingJan 24, 2024
  12. Raúl Núñez de Arenas CoronadoJan 23, 2024
  13. Jeff KingJan 24, 2024
  14. Raúl Núñez de Arenas CoronadoJan 24, 2024

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.