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

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
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 13 in “Disallow commands from within unpopulated submodules.”
  1. Disallow commands from within unpopulated submodules.Stefan Beller, Jan 19, 2017
  2. Jeff KingJan 20, 2017
  3. Stefan BellerJan 20, 2017
  4. Jeff KingJan 20, 2017
  5. Stefan BellerJan 20, 2017
  6. Jeff KingJan 20, 2017
  7. Stefan BellerJan 20, 2017
  8. Junio C HamanoJan 20, 2017
  9. Jeff KingJan 20, 2017
  10. Junio C HamanoJan 20, 2017
  11. Jeff KingJan 20, 2017
  12. Stefan BellerJan 20, 2017
  13. Duy NguyenJan 21, 2017

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.