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

Re: [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory

From
Greg Brockman <gdb@mit.edu>
Date
Aug 19, 2010, 07:52 UTC
Message-ID
<AANLkTi=u2jA5MOKwyYO_pwcZaK=A1D2g+gueFGF2L+5U@mail.gmail.com>
In-Reply-To
<vpq8w44mer6.fsf@bauges.imag.fr>
Show 7 quoted lines
>> +     mkdir ignored-dir &&
>> +     echo ignored-dir >> .gitignore &&
>> +     touch ignored-dir/file &&
>
> I think >ignored-dir/file is more portable than touch, and is
> recommanded in the testsuite. But a quick grep shows that touch is
> already used.
Ok, sure.  I'll switch over to >ignored-dir/file.
Show 7 quoted lines
>> +     test_must_fail git add ignored-dir/file >actual 2>&1 &&
>> +     test_cmp actual expect &&
>> +     git add -f ignored-dir/file &&
>> +     git add ignored-dir/file &&
>
> (so, this is the first thing you're fixing, shouldn't be
> controversial)
Hopefully not :).
Show 10 quoted lines
>> +test_expect_success 'git add with ignored directory using git globs' "
>> +     mkdir ignored-dir2 && echo ignored-dir2 >> .gitignore && touch ignored-dir2/file &&
>> +     git add 'ignored-dir2/*' >actual 2>&1 &&
>> +     echo \"fatal: pathspec 'ignored-dir2/*' did not match any files\" | test_cmp - actual
>
> Currently, "git add 'dir/*'" will add the files under dir/ if dir/
> isn't ignored, and require -f if dir is ignored.
>
> I don't think you want to complain with "did not match any files"
> here.

Well, I copied the behavior of 'git add "*"' here, where every file in . is ignored. E.g. """ $ echo >ignore-file $ echo .gitignore >>.gitignore $ echo ignore-file >>.gitignore $ git add '*' fatal: pathspec '*' did not match any files """ One could reasonably choose to instead say "The following paths are ignored by one of your .gitignore files: ...". When I chose the "did not match any files", I had been assuming that globbing works roughly analogously to shell globbing, meaning the error one gets from a '*' should be the same as that one gets from a 'dir/*' or '*/*'. I realized today that git globbing seems to act differently depending on where the wildcard appears. E.g.: """ $ mkdir a && echo >a/b $ git add '*/*' # complains, doesn't stage any files fatal: pathspec '*/*' did not match any files $ git add 'a/*' $ echo change >a/b $ git add '*/*' # doesn't complain, but doesn't stage changes $ git ls-files -m a/b """ Is this a bug? I looked for some docs on the globbing functionality, but I didn't come across anything that specified it in detail. Anyway, either way I still think consistency is ideal, and hence would still vote for "did not match any files". Thoughts?

Show 5 quoted lines
>> +     git add -f ignored-dir2/file && echo change > ignored-dir2/file &&
>> +     git add 'ignored-dir2/*' >actual 2>&1 &&
>
> Just making sure I'm reading correctly: this is the second thing that
> should be fixed, and that your earlier patch didn't.

Yes, that's correct. (Again, just trying to match functionality with ignored files.)

Show 8 quoted lines
> You're not testing the case
>
>  git add ignored-dir/
>
> which gives another case where Git tries to add files not explicitely
> given on the command-line. But the correct behavior of this case may
> be more controversial, so maybe it's indeed better to focus on the
> other cases.

A fair point. I would have thought the behavior here should be unchanged, namely that 'git add ignored-dir/' should spit out a "The following paths are ignored by one of your .gitignore files: ..." error, regardless of the directory's contents. Does anyone believe this should be different/would it be useful for me to draw up a test case for it now? In any case, I'll certainly put a test case for this into the final patch.

Greg
Previous: Matthieu MoyNext: Matthieu Moy
Message 20 of 28 in “git-add: Don't exclude explicitly-specified tracked files”
  1. git-add: Don't exclude explicitly-specified tracked filesGreg Brockman, Aug 11, 2010
  2. Ævar Arnfjörð BjarmasonAug 11, 2010
  3. Jens LehmannAug 11, 2010
  4. Greg BrockmanAug 12, 2010
  5. Junio C HamanoAug 11, 2010
  6. Greg BrockmanAug 11, 2010
  7. Junio C HamanoAug 12, 2010
  8. Greg BrockmanAug 12, 2010
  9. Matthieu MoyAug 12, 2010
  10. Greg BrockmanAug 12, 2010
  11. Matthieu MoyAug 12, 2010
  12. Junio C HamanoAug 12, 2010
  13. Greg BrockmanAug 12, 2010
  14. Jonathan NiederAug 12, 2010
  15. Ævar Arnfjörð BjarmasonAug 12, 2010
  16. Greg BrockmanAug 18, 2010
  17. Add test case for dealing with a tracked file in an ignored directoryGreg Brockman, Aug 18, 2010
  18. Greg BrockmanAug 18, 2010
  19. Matthieu MoyAug 18, 2010
  20. Greg BrockmanAug 19, 2010
  21. Matthieu MoyAug 19, 2010
  22. Ævar Arnfjörð BjarmasonAug 18, 2010
  23. Matthieu MoyAug 18, 2010
  24. Ævar Arnfjörð BjarmasonAug 18, 2010
  25. Jonathan NiederAug 19, 2010
  26. Ævar Arnfjörð BjarmasonAug 19, 2010
  27. Jonathan NiederAug 25, 2010
  28. Ævar Arnfjörð BjarmasonAug 29, 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.