Re: [RFC/PATCH] Disallow commands from within unpopulated submodules.
- From
Jeff King <peff@peff.net>
- Date
- Jan 20, 2017, 21:48 UTC
- Message-ID
- <20170120214812.hhyjj3ldhhbrohlw@sigill.intra.peff.net>
- In-Reply-To
- <xmqq37gdxvbx.fsf@gitster.mtv.corp.google.com>
On Fri, Jan 20, 2017 at 01:41:54PM -0800, Junio C Hamano wrote:
Show 12 quoted lines
> Jeff King <peff@peff.net> writes: > > >> And in my current understanding of submodules the check in > >> .gitmodules ought to be enough, too. > > > > Yeah, that probably makes sense. You can have a gitlink without a > > .gitmodules file, but I don't quite know what that would mean in terms > > of submodules (I guess it's not a submodule but "something else"). > > That may be a lot better than reading the index unconditionally, but > I'd rather not to see "git rev-parse" read ".gitmodules" at all. It > would discourage scripted use of Git for no good reason.
Why is that? Just because it makes rev-parse seem more bloated?
I think Stefan's putting it into git.c is confusing the issue a bit. This is fundamentally about figuring out which git repository we're in, and that procedure is the right place to put the check.
IOW, when we call setup_git_repository() we are already walking up the tree and looking at .git/HEAD, .git/config, etc to see if we are in a valid git repository. It doesn't seem unreasonable to me to make this part of that check. I.e.:
- if we we walked up from the working tree (so we have a non-NULL
prefix); and- if there is a .gitmodules file; and
- if the .gitmodules file shows that we were inside what _should_ have
been a submodule; then- complain and do not accept the outer repository as a valid repo.
That adds only an extra failed open() for people who do not use submodules, and an extra config-file parse for people who do. And then only when they are not in the top-level of the working tree (so scripts, etc that cd_to_toplevel wouldn't pay per-invocation).
-Peff