Subject: Re: [RFC] Define "precious" attribute and support it in `git clean`

From: Junio C Hamano <[email-masked]>
Date: Thu, 12 Oct 2023 09:58:19 -0700

Sebastian Thiel <[email-masked]> writes:

> ### What about a `$` syntax in `.gitignore` files?
>
> I looked into adding a new prefix, `$` to indicate the following path is
> precious or… valuable. It can be escaped with `\$` just like `\!`. 

I have been regretting that I did not make the quoting syntax not
obviously extensible in f87f9497 (git-ls-files: --exclude mechanism
updates., 2005-07-24), which technically was a breaking change (as a
relative pathname that began with '!' were not special, but after
the change, it became necessary to '\'-quote it).  A relative
pathname that begins with '$' would be now broken the same way, but
hopefully the fallout would be minor.  I presume you picked '$'
exactly because of this reason?

I do not think it will be the end of the world if we don't do so,
but it would be really really nice if we at least explored a way (or
two) to make a big enough hole in the syntax to not just add
"precious", but leave room to later add other traits, without having
to worry about breaking the backward compatibility again.  A
simplest and suboptimal way may be to declare that a path that
begins with '$' now needs '\'-quoting (just like your proposal),
reserve '$$' as the precious prefix, and '$' followed by any other
byte reserved for future use, but there may be better ideas.

> *Unfortunately*, users can't just add a local `.git/info/exclude` file with
> `$.config` in it and expect `.config` to be considered precious as the pattern
> search order will search this last as it's part of the exclude-globals.

That it nothing new and is the same for ignored files.  The lower
precedence files do not override higher precedence files.

> Thus, to make this work, projects that ship the `.gitignore` files would *have
> to add patterns* that make certain files precious.

Not really.  They do not have to do anything if they are content
with the current Git ecosystem.  And users who have precious stuff
can mark them in the.git/info/excludes no?  The only case that is
problematic is when the project says 'foo' is ignored and expendable
but the user thinks otherwise.  So to make this work, projects that
ship the ".gitignore" files have to avoid adding patterns to ignore
things that it may reasonably be expected for its users to mark
precious.

> Such opted-in projects would produce `.gitignore` files like these:
>
>     .*
>     $.config

I would understand if you ignored "*~" or "*.o", but why ignore ".*"?

THanks.