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

Re: [RFC] git submodule purge

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Mar 16, 2015, 20:03 UTC
Message-ID
<20150316200353.GB5186@google.com>
In-Reply-To
<20150316134407.GA31794@pks-tp.elego.de>

(+cc: Jens and Heiko, submodule experts) Hi,

Patrick Steinhardt wrote:
Show 24 quoted lines
> This proposal is just for discussion. If there is any interest I
> will implement the feature and send some patches.
>
> Currently it is hard to properly remove submodules. That is when
> a submodule is deinitialized and removed from a repository the
> directory '.git/modules/<SM_NAME>' will still be present and
> there is no way to remove it despite manually calling `rm` on it.
> I think there should be a command that is able to remove those
> dangling repositories if the following conditions are met:
>
> - the submodule should not be initialized
>
> - the submodule should not have an entry in .gitmodules in the
>   currently checked out revision
>
> - the submodule should not contain any commits that are not
>   upstream
>
> - the submodule should not contain other submodules that do not
>   meet those conditions
>
> This would ensure that it is hard to loose any commits that may
> be of interest. In the case that the user knows what he is doing
> we may provide a '--force' switch to override those checks.
Those conditions look simultaneously too strong and too weak. ;-)

In principle, it should be safe to remove .git/modules/<name> as long as

 (1) it (and its submodules, sub-sub-modules, etc) doesn't have any
     un-pushed local commits.
 (2) it is not being referred to by a .git file in the work tree of
     the parent repository.

Condition (1) can be relaxed if the user knows what they are losing and is okay with that. Condition (2) can be avoided by removing (de-initing) the copy of that submodule in the worktree at the same time.

The functionality sounds like a useful thing to have, whether as an option to 'git submodule deinit' or as a new subcommand. In the long term I would like it to be possible to do everything 'git submodule' can do using normal git commands instead of that specialized interface. What command do you think this would eventually belong in? (An option to "git gc", maybe?)

Thanks, Jonathan

Previous: Fredrik GustafssonNext: Patrick Steinhardt
Message 5 of 11 in “[RFC] git submodule purge”
  1. Patrick SteinhardtMar 16, 2015
  2. Junio C HamanoMar 16, 2015
  3. Patrick SteinhardtMar 17, 2015
  4. Fredrik GustafssonMar 17, 2015
  5. Jonathan NiederMar 16, 2015
  6. Patrick SteinhardtMar 17, 2015
  7. Jens LehmannMar 23, 2015
  8. Patrick SteinhardtMar 25, 2015
  9. Jens LehmannMar 25, 2015
  10. Patrick SteinhardtMar 26, 2015
  11. Jens LehmannMar 26, 2015

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.