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

Re: [PATCH v2 6/7] add: warn when pathspec only matches SKIP_WORKTREE entries

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 4, 2021, 21:03 UTC
Message-ID
<xmqq5z26eime.fsf@gitster.c.googlers.com>
In-Reply-To
<CABPp-BE9QA5RAwdebmAyK3b3wh1mGE+NF7sPS5RCf4FogYBV7A@mail.gmail.com>
Elijah Newren <newren@gmail.com> writes:
> I think it's kind of lame that git-add won't provide a warning for
> ignored files when the match is via glob/pattern; if git-add didn't
> end up adding anything, but an ignored file was matched, I think a
> warning is appropriate.
I am not so sure.  When I have this in my exclude list:
	tmp-*
and have this file in the working tree:
	tmp-000.txt
I am not sure if I want to see any such warning when I did
	$ git add "*.txt"

After all, I said that I never would want to worry about anything that begins with "tmp-". It would be a totally different issue if I did

	$ git add tmp-000.txt

as I am contermanding my previous wish and saying that I care about this particular file, even if its name begins with "tmp-".

So far, the flow of logic is simple, clear and straight-forward.
BUT.
What makes the whole thing tricky is that people don't do
	$ git add "*.txt"
The instead do
	$ git add *.txt

and "git add" cannot tell if the tmp-000.txt it sees is what the user meant, or what the shell expanded.

If there were no shell glob expansion, then "warn only if a glob/pattern did not match any" would have been an attractive option, especially when we had another file in the working tree, say, hello.txt, next to the tmp-000.txt. Then

	$ git add "*.txt"

would add only hello.txt, and we won't see a warning about tmp-000.txt. But end-users will use shell expansion, i.e.

	$ git add *.txt
(1) warning against tmp-000.txt because the command line named it
    explicitly (from "git add"'s point of view, but never from the
    user's point of view) would be a disaster.  I think that is why
    your suggestion was "if git-add did not add anything then warn".
    but ...
(2) not warning, because the command line named hello.txt as well,
    i.e. "git add" added something, would make it inconsistent.
    Whether there is another file whose name ends with .txt, what
    the user typed (i.e. *.txt) to the command line is the same, and
    the exclude pattern (i.e. tmp-*) is the same, but the presence
    of an unrelated hello.txt affects if a warning is given for
    tmp-000.txt.
So, I dunno.
Previous: Elijah NewrenNext: Elijah Newren
Message 14 of 19 in “add/rm: honor sparse checkout and warn on sparse paths”
  1. 0/7 add/rm: honor sparse checkout and warn on sparse pathsMatheus Tavares, Feb 24, 2021
  2. 1/7 add: include magic part of pathspec on --refresh errorMatheus Tavares, Feb 24, 2021
  3. 2/7 t3705: add tests for `git add` in sparse checkoutsMatheus Tavares, Feb 24, 2021
  4. Elijah NewrenFeb 24, 2021
  5. 3/7 add: make --chmod and --renormalize honor sparse checkoutsMatheus Tavares, Feb 24, 2021
  6. 4/7 pathspec: allow to ignore SKIP_WORKTREE entries on index matchingMatheus Tavares, Feb 24, 2021
  7. Elijah NewrenFeb 24, 2021
  8. 5/7 refresh_index(): add REFRESH_DONT_MARK_SPARSE_MATCHES flagMatheus Tavares, Feb 24, 2021
  9. 6/7 add: warn when pathspec only matches SKIP_WORKTREE entriesMatheus Tavares, Feb 24, 2021
  10. Elijah NewrenFeb 24, 2021
  11. Matheus TavaresFeb 24, 2021
  12. Matheus TavaresMar 4, 2021
  13. Elijah NewrenMar 4, 2021
  14. Junio C HamanoMar 4, 2021
  15. Elijah NewrenMar 4, 2021
  16. Matheus Tavares BernardinoMar 4, 2021
  17. 7/7 rm: honor sparse checkout patternsMatheus Tavares, Feb 24, 2021
  18. Elijah NewrenFeb 24, 2021
  19. Elijah NewrenFeb 24, 2021

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.