Re: [RFC PATCH] Introduce "precious" file concept
flat view
From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2018-11-12 09:49:51
On Mon, Nov 12 2018, Matthieu Moy wrote:
"Per Lundberg" [off-list ref] wrote:quoted
On 11/11/18 5:41 PM, Duy Nguyen wrote:quoted
On Sun, Nov 11, 2018 at 1:33 PM Ævar Arnfjörð Bjarmason [off-list ref] wrote:quoted
quoted
That will lose no data, and in the very rare cases where a checkout of tracked files would overwrite an ignored pattern, we can just error out (as we do with the "Ok to overwrite" branch removed) and tell the user to delete the files to proceed.There's also the other side of the coin. If this refuse to overwrite triggers too often, it can become an annoyance.I may have missed some cases, but to me the cases when checkout may try to overwrite an ignored file are essentially: * Someone "git add"ed a file meant to be ignored by mistake (e.g. "git add -f *.o"). * A file that was meant to be kept private (e.g. config.mak.dev) ends up being tracked. This may happen when we find a way to make per-developer settings the same for everyone.
Yes, the cases under discussion here are all cases where a tracked file clobbers a file matching a pattern in in .gitignore. What I'd add to your list is: * Some projects (I've seen this in the wild) add e.g. *.mp3 or whatever else usually doesn't belong in the repo as a "soft ignore". This is something we've never recommended, but have implicitly supported since the only caveats are a) you need a one-off "git add -f" and then they're tracked b) them being missing from "status" before being tracked c) the issue under discussion here. * Cases where e.g. filename changes to a directory or globs because of that make this more complex.
I both cases I'd want at least to be notified that something is going on, and in the second I'd probably want to keep my local file around.quoted
If we feel thrashable is stretching it too far (which I don't think it is), we could add a "core.ignore_files_are_trashable" setting that brings back the old semantics, for those who have a strong feeling about it.May I remind an idea I sugested in an old thread: add an intermediate level where ignored files to be overwritten are renamed (eg. foo -> foo~ like Emacs' backup files): https://public-inbox.org/git/vpqd3t9656k.fsf@bauges.imag.fr/ One advantage of the "rename" behavior is that it's safer that the current, but still not very disturbing for people who like the current behavior. This makes it a good candidate for a default behavior. This could come in complement with this thread's "precious" concept: * If you know what you're doing and know that such or such file is precious, mark it as such and Git will never overwrite it. * If you don't know about precious files, just keep the default setting and the worse that can happen is to get your file overwritten with a bakup of the old version kept around. This would probably play better with a notion of "precious" files than with a notion of "trashable" files.
I used to think this foo -> foo~ approach made the most sense (and said as much in https://public-inbox.org/git/871s8qdzph.fsf@evledraar.gmail.com/) but I think it's probably best not to do it and just error out, because: * We'd still need to handle the cases where "tests" the file collides with "tests" the directory. Then where do we move the colliding file? ~/.git/lost+found/* ? We could handle the subdir case with another special-case though... * I think such silent action will just leave users more confused, and in many cases (e.g. a merge) whatever message we print out will be missed in a deluge of other messaging, and they'll probably miss it. I'd like to avoid a case where a bunch of *~ files get committed because the user's workflow is (and some beginner git users do this): git pull && git add . && git commit && git push As the "pull" would now invoke a merge that would do this rename. * If I have the "foo" file open in my editor (a plausible way to run into this) I switch to another terminal, do the merge, miss the message, then re-save "foo". Now I have both "foo" and "foo~" on-disk. Another case where we should just refuse until the user resolves the situation to avoid the confusion.