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

Re: [PATCH 0/2] Let "git submodule add" fail when .git/modules/<name> already exists

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 30, 2012, 04:47 UTC
Message-ID
<7vtxugglqy.fsf@alter.siamese.dyndns.org>
In-Reply-To
<50677E76.1050204@web.de>
Jens Lehmann <Jens.Lehmann@web.de> writes:
Show 6 quoted lines
>> The only long term solution I can think of is to use some kind of UUID for
>> the name, so that the names of newly added submodules won't have a chance
>> to clash anymore. For the short term aborting "git submodule add" when a
>> submodule of that name already exists in .git/modules of the superproject
>> together with the ability to provide a custom name might at least solve
>> the local clashes.

That assumes that the addition of the submodule for the second time is to add a completely different submodule at the same location and is done on purpose, but is that a sensible assumption?

If a superproject that is about an embedded appliance used to have a submodule A bound at its path "kernel", but for some reason stopped shipping with "kernel" and then later reintroduced the directory "kernel" bound to some submodule B, my gut feeling is that it is just as likely (if not more likely) that A and B are indeed the same submodule (i.e. it shares the same history) as they are totally unrelated.

Could it be that it is a user error combined with the immaturity of "git submodule" tool that does not yet support "it used to be here, but it disappears for a while and then it reappears in the history of the superproject" very well that caused the user to manually add a "new" submodule which in fact is the same submodule at the same path?

I think failing with a better error message is a good idea. It should suggest to either resurrect the submodule that is stashed away in "$GIT_DIR/modules/$name" if it indeed is the same, or to give it a different name (perhaps "kernel" used to be pointing at the Linux kernel history, then the user is replacing it with a totally different implementation that is really from different origin and do not share any history, perhaps BSD). In such a case, the user may want to pick bsd-kernel or something as its name, to differentiate it.

> Using some kind of UUID can easily be added in a subsequent patch,...

I would suggest thinking really long and hard before saying UUID. It is an easy cop-out to ensure uniqueness, but risks to allow two people (or one person at two different time) to give two unrelated names to a single thing that actually is the same.

A better alternative might be to use the commit object name at the root of the history of the submodule, which would catch the simplest and most common case of the mistake, I would think.

Previous: Jens LehmannNext: Jens Lehmann
Message 6 of 9 in “Bug in Submodule add”
  1. Jonathan JohnsonSep 26, 2012
  2. Jens LehmannSep 26, 2012
  3. 0/2 Let "git submodule add" fail when .git/modules/<name> already existsJens Lehmann, Sep 29, 2012
  4. 1/2 Teach "git submodule add" the --name optionJens Lehmann, Sep 29, 2012
  5. 2/2 submodule add: Fail when .git/modules/<name> already existsJens Lehmann, Sep 29, 2012
  6. Junio C HamanoSep 30, 2012
  7. Jens LehmannSep 30, 2012
  8. 2/2 submodule add: Fail when .git/modules/<name> already exists unless forcedJens Lehmann, Sep 30, 2012
  9. Junio C HamanoOct 1, 2012

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.