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

Re: [PATCH] submodule: prevent overwriting .gitmodules entry on path reuse

From
JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com>
Date
May 12, 2025, 13:26 UTC
Message-ID
<CA+rGoLdzT01jLigX=Z+_tw715O0BibgVA+Sj+65Qwee7i5gLfg@mail.gmail.com>
In-Reply-To
<xmqqbjryxb5j.fsf@gitster.g>
On Mon, May 12, 2025 at 6:02 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 28 quoted lines
>
> K Jayatheerth <jayatheerthkulkarni2005@gmail.com> writes:
>
> > When a submodule is added at a path that previously hosted another submodule
> > (e.g., 'child'), Git reuses the submodule name derived from the path and
> > updates the corresponding entry in .gitmodules. This can silently overwrite
> > existing configuration if the old submodule was only moved (e.g., to
> > 'child_old') without renaming the submodule.
> >
> > This patch improves the `module_add()` logic by checking whether the
> > submodule name already exists in the config but maps to a different path.
>
> Quite sensible description of the problem and the proposed course of
> improvement.
>
> I do not think `--force` that allows the same name to be reused a
> good idea at all, though.  We shouldn't encourage its use to resolve
> such a case.  If what used to be called `child` now sits elsewhere,
> perhaps because the tree structure was reorganized due to mass
> renaming, but if it still is being used in the project, there is no
> good reason to nuke the configuration recorded for that existing
> module.
>
> The module name used in .git/config is purely local so the user
> should just give a new one a name that does not conflict, or even
> better yet, perhaps the tool should pick a unique and nonconflicting
> name automatically, no?
>

That makes sense I see the point in using --force to resolve name conflicts might not be ideal, especially when the previous submodule config may still be valid and in use.

As a potential improvement, I was thinking of mimicking how duplicate filenames are handled: if the default submodule name (derived from the path) already exists and maps to a different path, we could automatically append an incrementing number (foo, foo1, foo2, etc.) until a non-conflicting name is found.

-Jayatheerth
Previous: Junio C HamanoNext: K Jayatheerth
Message 4 of 24 in “submodule: prevent overwriting .gitmodules entry on path reuse”
  1. submodule: prevent overwriting .gitmodules entry on path reuseK Jayatheerth, May 10, 2025
  2. JAYATHEERTH KMay 10, 2025
  3. Junio C HamanoMay 12, 2025
  4. JAYATHEERTH KMay 12, 2025
  5. submodule: prevent overwriting .gitmodules entry on path reuseK Jayatheerth, May 13, 2025
  6. Junio C HamanoMay 13, 2025
  7. submodule: prevent overwriting .gitmodules entry on path reuseK Jayatheerth, May 14, 2025
  8. Junio C HamanoMay 14, 2025
  9. JAYATHEERTH KMay 16, 2025
  10. submodule: prevent overwriting .gitmodules entry on path reuseK Jayatheerth, May 16, 2025
  11. JAYATHEERTH KMay 16, 2025
  12. submodule: prevent overwriting .gitmodules entry on path reuseK Jayatheerth, May 18, 2025
  13. JAYATHEERTH KMay 18, 2025
  14. Junio C HamanoMay 19, 2025
  15. JAYATHEERTH KMay 20, 2025
  16. Junio C HamanoMay 20, 2025
  17. 0/2 Avoid submodule overwritten and skip redundant active entriesK Jayatheerth, May 24, 2025
  18. 1/2 submodule: prevent overwriting .gitmodules entry on path reuseK Jayatheerth, May 24, 2025
  19. 2/2 submodule: skip redundant active entries when pattern covers pathK Jayatheerth, May 24, 2025
  20. JAYATHEERTH KMay 24, 2025
  21. 0/2 Avoid submodule overwritten and skip redundant active entriesK Jayatheerth, May 24, 2025
  22. 1/2 The seventeenth batchK Jayatheerth, May 24, 2025
  23. JAYATHEERTH KMay 24, 2025
  24. 2/2 submodule: prevent overwriting .gitmodules entry on path reuseK Jayatheerth, May 24, 2025

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.