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

Re: git add -A fails in empty repository since 1.8.5

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 18, 2013, 18:54 UTC
Message-ID
<xmqqioumhtvp.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CACsJy8DY7eZm7-P=azJF-jEiBKM_QPf_GXG3uzbuw5C1vq1Q5A@mail.gmail.com>
Duy Nguyen <pclouds@gmail.com> writes:
Show 15 quoted lines
> On Wed, Dec 18, 2013 at 3:44 PM, Antoine Pelisse <apelisse@gmail.com> wrote:
>> FWIW, git-bisect points to 84b8b5d (that is $gmane/230349).
>>
>> On Wed, Dec 18, 2013 at 9:06 AM, Thomas Ferris Nicolaisen
>> <tfnico@gmail.com> wrote:
>>> This was discussed on the Git user list recently [1].
>>>
>>> #in a repo with no files
>>>> git add -A
>>> fatal: pathspec '.' did not match any files
>>>
>>> The same goes for git add . (and -u).
>>>
>>> Whereas I think some warning feedback is useful, we are curious
>>> whether this is an intentional change or not.

The logic to produce that error message is primarily to catch a typo like:

	$ git add Nakefile
when the user meant to say Makefile.

It could be argued that a "git add [<any option>] .", with an explicit "." given by the end-user, that is run in an empty directory may be an error worth reporting. Just like it is likely for the user to have wanted to add some other file when he typed Nakefile and it is not good to silently decide "ah, nothing matches the pathspec, so not adding anything is the right thing to do" in such a case, it is plausible that the user thought that he was in some other directory he wanted to add its contents to the index when he gave us the explicit ".", while he was in fact in a wrong directory, and it is not good to silently decide "nothing there to add so I won't do anything" without any indication of an error.

We should *not* error out "git add [<any option>]" without any end-user pathspecs, especially with that error message, on the other hand.

Show 21 quoted lines
> I was not aware of this case when I made the change. It's caused by
> this change that removes pathspec.raw[i][0] check in builtin/add.c in
> 84b8b5d .
>
> -               for (i = 0; pathspec.raw[i]; i++) {
> -                       if (!seen[i] && pathspec.raw[i][0]
> -                           && !file_exists(pathspec.raw[i])) {
> +               for (i = 0; i < pathspec.nr; i++) {
> +                       const char *path = pathspec.items[i].match;
> +                       if (!seen[i] && !file_exists(path)) {
>
> Adding it back requires some thinking because "path" in the new code
> could be something magic.. and the new behavior makes sense, so I'm
> inclined to keep it as is, unless people have other opinions.
>
>>>
>>> [1] https://groups.google.com/d/topic/git-users/Qs4YSPhTsqE/discussion
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe git" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous: Duy NguyenNext: Matthieu Moy
Message 4 of 18 in “git add -A fails in empty repository since 1.8.5”
  1. Thomas Ferris NicolaisenDec 18, 2013
  2. Antoine PelisseDec 18, 2013
  3. Duy NguyenDec 18, 2013
  4. Junio C HamanoDec 18, 2013
  5. Matthieu MoyDec 18, 2013
  6. Junio C HamanoDec 18, 2013
  7. Junio C HamanoDec 18, 2013
  8. Duy NguyenDec 19, 2013
  9. add: don't complain when adding empty project rootNguyễn Thái Ngọc Duy, Dec 23, 2013
  10. Torsten BögershausenDec 23, 2013
  11. Duy NguyenDec 23, 2013
  12. Torsten BögershausenDec 24, 2013
  13. Duy NguyenDec 24, 2013
  14. Torsten BögershausenJan 30, 2014
  15. Junio C HamanoJan 31, 2014
  16. Jonathan NiederDec 26, 2013
  17. Junio C HamanoDec 26, 2013
  18. Junio C HamanoDec 26, 2013

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.