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

Re: [BUG] 'add -u' doesn't work from untracked subdir

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 10, 2009, 19:53 UTC
Message-ID
<7vmy527f0b.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20090910084653.6117@nanako3.lavabit.com>
Nanako Shiraishi <nanako3@lavabit.com> writes:
Show 19 quoted lines
> Quoting Junio C Hamano <gitster@pobox.com>
>
>> We could probably declare "In 1.X.0 everything will be relative to the
>> root and you have to give an explicit '.' if you mean the cwd".
>>
>> Three questions:
>>
>>  #1 What are the commands that will be affected, other than "add -u" and
>>     "grep"?  Are there others?
>>
>>  #2 Do all the commands in the answer to #1 currently behave exactly the
>>     same when run without any path parameter and when run with a single
>>     '.'?
>
> 'git-archive' behaves relative to your current directory.
>
>   http://thread.gmane.org/gmane.comp.version-control.git/41300/focus=44125
>
> You can limit it to the current directory with a dot.
Thanks.

If you want to make a tarball of the Documentation directory from your work tree, you do this:

    $ cd Documentation
    $ tar cf - . >/tmp/docs.tar
If you want to do the same but from your committed content, you do this:
    $ cd Documentation
    $ git archive HEAD >/tmp/docs.tar
and you do not have to say:
    $ cd Documentation
    $ git archive HEAD . >/tmp/docs.tar

So in that sense it does make sense to archive the current directory. It matches what the users expect from their archivers.

The traditional archivers may not default to "." but we do. That is about giving a sensible default [*1*]. Perhaps defaulting to the cwd behaviour for one command may seem a sensible thing when looking at that particular command alone; archive and grep fall into that category.

But as this "add -u" discussion showed us [*2*], people may expect different "sensible default", and as a suite of commands as the whole, it becomes messy. People have to remember which ones obey cwd, and to some people the choice is not intuitive.

To avoid confusion, I am beginning to agree with people who said in the thread that it is a good idea to consistently default to the root of the contents. When we use "everything" as the default due to lack of command line pathspec, we would use "everything from root" no matter where you are, regardless of what command we are talking about. That would make the rule easier to remember [*3*].

This changes the way how "git (add -u|grep|clean|archive)" without pathspec and "git (add -u|grep|clean|archive) ." with an explicit dot work. The former (adds all changed files in, finds hits in, removes untracked paths in, creates a tarball for) the whole tree, while the latter limits the operation explicitly to the current directory.

If this were going to happen as a list concensus, I am very tempted to suggest that we at least _consider_ applying the same rule even to ls-files and ls-tree. That would impact scripts, so we need to be extra careful, though.

Also this takes us to a tangent.

If we try to give a sensible default to make it easier for the user, perhaps we should also default to HEAD when the user did not specify which tree-ish to archive from. This is a topic in a separate thread.

[Footnote]

*1* Actually we don't allow "git archive HEAD ..", which I think is a bug. Also we do not have --full-tree workaround, which makes it slightly cumbersome to use.

*2* And the thread you quoted shows us that the argument applies equally to "git archive" as well; you see me complaining that it is unintuitive for me to care about "archive", and the counterargument was that ls-tree does so. I however think it is more important for archive to behave in a way that is easier for the users to understand, than mimick the historical mistake in a plumbing command.

*3* Command line pathspec of course should honor cwd as before. When you say "git distim Makefile" inside t/ directory, we distim t/Makefile, not the toplevel Makefile. This discussion is only about the case where the user didn't give us any pathspec.

Previous: Nanako ShiraishiNext: Clemens Buchacher
Message 12 of 35 in “[BUG] 'add -u' doesn't work from untracked subdir”
  1. SZEDER GáborSep 2, 2009
  2. Jeff KingSep 2, 2009
  3. Clemens BuchacherSep 4, 2009
  4. Jeff KingSep 5, 2009
  5. Junio C HamanoSep 5, 2009
  6. Jeff KingSep 5, 2009
  7. Junio C HamanoSep 5, 2009
  8. Jeff KingSep 5, 2009
  9. Junio C HamanoSep 5, 2009
  10. Clemens BuchacherSep 6, 2009
  11. Nanako ShiraishiSep 9, 2009
  12. Junio C HamanoSep 10, 2009
  13. Clemens BuchacherSep 10, 2009
  14. 1/2 grep: accept relative paths outside current working directoryClemens Buchacher, Sep 5, 2009
  15. 2/2 add 'scope' config optionClemens Buchacher, Sep 5, 2009
  16. 2/2 add 'scope' config optionClemens Buchacher, Sep 5, 2009
  17. Junio C HamanoSep 6, 2009
  18. grep: fix exit status if external_grep() returns errorClemens Buchacher, Sep 7, 2009
  19. Junio C HamanoSep 7, 2009
  20. Jeff KingSep 5, 2009
  21. Junio C HamanoSep 5, 2009
  22. Clemens BuchacherSep 5, 2009
  23. Junio C HamanoSep 5, 2009
  24. Jakub NarebskiSep 5, 2009
  25. Clemens BuchacherSep 5, 2009
  26. Junio C HamanoSep 5, 2009
  27. Matthieu MoySep 6, 2009
  28. Clemens BuchacherSep 6, 2009
  29. Matthieu MoySep 7, 2009
  30. SZEDER GáborSep 7, 2009
  31. Matthieu MoySep 7, 2009
  32. Nanako ShiraishiSep 7, 2009
  33. Junio C HamanoSep 7, 2009
  34. Clemens BuchacherSep 7, 2009
  35. SZEDER GáborSep 4, 2009

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.