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

Re: 'git add' regression in git-1.7?

From
Jeff King <peff@peff.net>
Date
Feb 19, 2010, 08:24 UTC
Message-ID
<20100219082445.GB13691@coredump.intra.peff.net>
In-Reply-To
<20100219060249.GD22645@coredump.intra.peff.net>
On Fri, Feb 19, 2010 at 01:02:49AM -0500, Jeff King wrote:
Show 30 quoted lines
> But this is a little disturbing still:
> 
>   $ git init
>   $ mkdir dir
>   $ touch dir/sub
>   $ touch root
>   $ echo dir >.gitignore
>   $ echo root >>.gitignore
> 
>   $ git add root
>   The following paths are ignored by one of your .gitignore files:
>   root
>   Use -f if you really want to add them.
>   fatal: no files added
>   $ echo $?
>   128
> 
>   $ git add dir
>   The following paths are ignored by one of your .gitignore files:
>   dir
>   Use -f if you really want to add them.
>   fatal: no files added
>   $ echo $?
>   128
> 
>   $ git add dir/sub
>   $ echo $?
>   0
> 
> but we didn't actually add the file.
Junio,
This seems to be caused by dir.c:treat_one_path. In the first few lines:
        int exclude = excluded(dir, path, &dtype);
        if (exclude && (dir->flags & DIR_COLLECT_IGNORED)
            && in_pathspec(path, *len, simplify))
                dir_add_ignored(dir, path, *len);

we see that the prefix "dir" is excluded, but it is not in our pathspec ("dir/sub"), so we do not add it to the ignored list.

This is related to your recent 48ffef9 (ls-files: fix overeager pathspec optimization, 2010-01-08), as before then we actually didn't consider "dir/sub" to be ignored at all. The in_pathspec check did not originate there; it's from my e96980e (builtin-add: simplify (and increase accuracy of) exclude handling, 2007-06-12). But it is definitely still necessary.

I'm not sure of the right way to fix this. We can drop further down into the directory hierarchy when doing COLLECT_IGNORED and look for actual files, but that may have a negative performance impact. Perhaps we can go further only if we are a prefix of a pathspec. Or maybe there is some way to be more clever.

I dunno. I'm out of ideas for the evening, and since you looked at this not too long ago, I thought you might have some insight.

-Peff
Previous: Jeff KingNext: Junio C Hamano
Message 7 of 17 in “'git add' regression in git-1.7?”
  1. SungHyun NamFeb 19, 2010
  2. Avery PennarunFeb 19, 2010
  3. SungHyun NamFeb 19, 2010
  4. Avery PennarunFeb 19, 2010
  5. Jeff KingFeb 19, 2010
  6. Jeff KingFeb 19, 2010
  7. Jeff KingFeb 19, 2010
  8. Junio C HamanoMar 1, 2010
  9. add: fail "git add ignored-dir/file" without -fJunio C Hamano, Mar 1, 2010
  10. 1/3 t0050: mark non-working test as suchJunio C Hamano, Mar 1, 2010
  11. Jeff KingMar 9, 2010
  12. Jeff KingMar 9, 2010
  13. Junio C HamanoMar 10, 2010
  14. Jeff KingMar 11, 2010
  15. Junio C HamanoMar 14, 2010
  16. Jeff KingMar 14, 2010
  17. Junio C HamanoMar 15, 2010

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.