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

Re: [PATCH] Add test that checkout does not overwrite entries in .git/info/exclude

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Nov 24, 2011, 01:35 UTC
Message-ID
<CACsJy8BYN-nu6a92dk-qpF5_jR_frKwg+DD1EThr2kMPGHV5kQ@mail.gmail.com>
In-Reply-To
<7vy5v6bvy4.fsf@alter.siamese.dyndns.org>
On Thu, Nov 24, 2011 at 12:16 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
>
>> On Mon, Nov 21, 2011 at 10:18 PM, Junio C Hamano <gitster@pobox.com> wrote:
>>> In the medium term, I think one reasonable way forward solving the "TODO
>>> that used to be tracked but now untracked and ignored" issue is to
>>> introduce "info/exclude-override" that comes between command line and
>>> in-tree patterns. The info/exclude file is designed as the fallback
>>> definition to be used when all other sources are too lax, and comes near
>>> the precedence stack; the "TODO" situation however calls for an override
>>> that is stronger than the in-tree patterns.
>>
>> "info/precious" might be a better name
>
> The above is only about the precedence order and is not about introducing
> the new "precious" class at all.

The way I see how info/exclude-override helps keep (ignored but) precious files is it un-ignores files that are ignored by info/exclude and .gitignore. But if we go that way, then git-add will also un-ignore precious files, allowing users to add them in-tree by mistake.

Show 25 quoted lines
>>> In the longer term, we should carefully determine if we need "precious" in
>>> the first place. The last time this was brought up there were people who
>>> argued they are OK with having to remove the ignored file by hand when
>>> checking out another branch (i.e. we switch the semantics of "ignored" so
>>> that they are "not tracked but all precious").
>>>
>>> I think it matters in two cases.
>>>
>>>  (1) If you change an untracked "cruft" file on branch A into a directory
>>>     with tracked files in it on another branch B. If you are on branch A,
>>>     have that "cruft" file (perhaps it is a build product after running
>>>     "make"), and try to checkout branch B, such an updated "git checkout"
>>>     will start erroring out telling you that "cruft" will be lost.
>>>
>>>  (2) If you have a directory on branch A, underneath of which there are
>>>     untracked "cruft" files (e.g. think "build/" directory that is full
>>>     of "*.o" files and ".gitignore" to mark object files as ignored but
>>>     is otherwise empty), and another branch B that has the same path as a
>>>     file. If you are on branch A, have "cruft" files in that directory,
>>>     and try to checkout branch B, such an updated "git checkout" will
>>>     start erroring out telling you that "cruft" will be lost.
>>
>> I think we should do this regardless precious being added or not.
>
> Because (see below)?

Because it may potentially lose user's changes. Assume file "A" is tracked and also ignored. Users may make some changes in A, then move HEAD away without touching worktree, now HEAD does not see "A" as tracked any more. If we switch to a branch that has A tracked, git may override A and wipe our user changes in that file. In short, if a file is tracked (either in source or target in 2-way merge) then we ignore excluded() result on that file.

>>> If people are OK with such a behaviour, we can do without "precious".
>>
>> What about git-clean to remove ignored but not precious files?
>
(git clean without -x snipped because I was talking about -x)
Show 16 quoted lines
>
> "clean -x" is more subtle. It has been a way to say "Remove cruft the
> usual way, and in addition, remove the expendable build products, just
> like 'make clean' _should_ do, but I do not trust my Makefile". If we
> introduced "precious", it would be very clear what it should do---even
> with "-x" precious files should be kept. But if we don't and just try to
> get away by changing the semantics of "ignored", they will still need to
> be removed, so we won't really get the "precious".
>
> The conclusion from this is that it is a mistake to change the semantics
> of "ignored" from the current "untracked and expendable if needed" if the
> purpose of that change is to avoid introducing the new "precious" class.
>
> I don't care too much about it, as I do not use "git clean -x" myself ;-)
> but that wouldn't stop others from think about the issue and try to come
> up with a good solid design.

I don't use "git clean -x" myself either. This is just some input to the discussion and true users are supposed to speak up. The point I want to make is, if users really want the ability remove non-precious ignored files, then we may need to add the new "precious" class that (and you seem to reach the same conclusion).

-- 
Duy
Previous: Junio C HamanoNext: Junio C Hamano
Message 17 of 23 in “Bug report - local (and git ignored) file silently removed after checkout”
  1. Bertrand BENOITNov 20, 2011
  2. Junio C HamanoNov 20, 2011
  3. Taylor HedbergNov 20, 2011
  4. Junio C HamanoNov 21, 2011
  5. Add test that checkout does not overwrite entries in .git/info/excludeJohannes Sixt, Nov 21, 2011
  6. Philip OakleyNov 21, 2011
  7. Junio C HamanoNov 21, 2011
  8. Junio C HamanoNov 21, 2011
  9. Nguyen Thai Ngoc DuyNov 21, 2011
  10. Junio C HamanoNov 21, 2011
  11. Nguyen Thai Ngoc DuyNov 23, 2011
  12. Nguyen Thai Ngoc DuyNov 21, 2011
  13. Junio C HamanoNov 21, 2011
  14. Bertrand BENOITNov 21, 2011
  15. Nguyen Thai Ngoc DuyNov 23, 2011
  16. Junio C HamanoNov 23, 2011
  17. Nguyen Thai Ngoc DuyNov 24, 2011
  18. Junio C HamanoNov 24, 2011
  19. Nguyen Thai Ngoc DuyNov 24, 2011
  20. Nguyen Thai Ngoc DuyNov 27, 2011
  21. 1/2 checkout,merge: loosen overwriting untracked file check based on info/excludeNguyễn Thái Ngọc Duy, Nov 27, 2011
  22. 2/2 checkout,merge: disallow overwriting ignored files with --no-overwrite-ignoreNguyễn Thái Ngọc Duy, Nov 27, 2011
  23. Junio C HamanoNov 29, 2011

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.