Re: gitignore as symbolic link
- From
Matheus Tavares <matheus.bernardino@usp.br>
- Date
- Oct 22, 2021, 22:40 UTC
- Message-ID
- <CAHd-oW50puNCrYTQhR4qffgtP6-wJerWLhmhCV+nYcLVNu+CBg@mail.gmail.com>
- In-Reply-To
- <YXLro/8c1Feg6TcN@kitchen>
On Fri, Oct 22, 2021 at 1:57 PM Rene Kita <mail@rkta.de> wrote:
Show 12 quoted lines
> > On Thu, Oct 21, 2021 at 05:07:44PM -0800, Justus Ranvier wrote: > > I have several repositories where the top level .gitignore file is a > > symbolic link to the actual file which is contained in a submodule which all > > the repositories share. > > > > This worked fine up to and including version 2.31.1 but as of 2.32.0 running > > any command which would cause .gitignore to be read results in a "too many > > levels of symbolic links error" and git behaves as if .gitignore is not > > present. > > > This was fixed in commit a185dd58ecc17f2ea16985d59c9bb7b09bec7775 [1].
Hmm, the behavior Justus described is actually related to another change. Since v2.32.0, git no longer follows ".gitattributes", ".gitignore" and ".mailmap" if they are symbolic links. It does that by open()-ing these files with the O_NOFOLLOW flag, which returns ELOOP ("too many levels of symbolic links error") when the basename is a symlink. So the behavior you experienced is actually not a bug, but an intended change.
For a full explanation please see a2ef579e261 ("attr: do not respect symlinks for in-tree .gitattributes", 2021-02-16) [2] and feb9b7792f ("exclude: do not respect symlinks for in-tree .gitignore", 2021-02-16) [3].
But the short version is: git accesses these files either from the working tree or the object store (think, e.g. a bare repo). Git never follows symlinks in the second case, so following them on the working tree was an inconsistent behavior which was fixed. (This also has a security implication, in the sense that it could be dangerous to follow symlinks that lead to paths outside the repository.)
Note that "core.excludesFile" and "$GIT_DIR/info/exclude" are still allowed to be symlinks.
[2]: https://github.com/git/git/commit/2ef579e261 [3]: https://github.com/git/git/commit/feb9b7792f
> [1] https://lore.kernel.org/git/xmqqlf83h2a7.fsf@gitster.g/