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

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

From
Raúl Núñez de Arenas Coronado <raulnac@gmail.com>
Date
Jan 22, 2024, 20:45 UTC
Message-ID
<CAGF1KhWiYX=3R01Odj2yCNgvx=f5+HRCjRJogWf5eBikuATCcg@mail.gmail.com>
In-Reply-To
<CAGF1KhWNaO_TUuCPo2L_HzNnR+FnB1Q4H6_xQ2owoH+SnynzEg@mail.gmail.com>
Hi there!

I'm not subscribed to the list, sorry, so I would be more than grateful if I'm CC'd, but I'll check the mailing list archive from time to time for replies. Thanks in advance.

It is a common practice for Python virtual environments, pytest and other tools (not always Python related) to add a '.gitignore' file in directories these tools create on a repository that should NOT be committed or tracked. By adding a .gitignore file containing a single "*", the entire directory is ignored by git. So far, so good.

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.

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!!!

Is there any way, not using --exclude-per-directory, of listing all untracked files in the current repository, but ignoring those matching .gitignore files with the patterns matching the corresponding subdirectory?

Is this a bug or intended behaviour?
Thanks a lot in advance :)
-- 
Raúl Núñez de Arenas Coronado
.
Next: Junio C Hamano
Message 1 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.