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

Re: [PATCH] Remove empty directories when checking out a commit with fewer submodules

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 11, 2010, 09:53 UTC
Message-ID
<7vocl1t1b8.fsf@alter.siamese.dyndns.org>
In-Reply-To
<alpine.DEB.1.00.1001110954410.4985@pacific.mpi-cbg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 7 quoted lines
> NAK.  We should not even try to _unlink_ submodule subdirectories; it 
> would be _way_ too easy to lose data that way.  Remember, submodules are a 
> totally different beast from regular files.  They can contain valuable, 
> yet uncommitted data, that is not even meant to be committed.
>
> So you say if the submodule directories are empty, it is safe?  Not so.  
> They will never be empty: there is always .git/...
NACK on NAK.

Don't worry, your data will be safe. The only case rmdir would actually remove it is (1) you check out superproject that has submodule A, but you choose not to "submodule init/update" it, because you don't need a checkout of that part of the tree for your job, and then (2) you switch to a different version of the superproject that doesn't anymore (or didn't back then) have that submodule. In such a use case, you will have only an empty directory for A in step (1). The unnecessary empty directory A will be left behind, even after switching to a version that shouldn't have the directory there in step (2), if you do not rmdir it. So the patch is a strict bugfix (it attempted to unlink, which is a bug; it really meant "rmdir" and not "rm -rf" which you seem to be worried about).

It is a separate matter to _enhance_ the codepath to actually either (A) refuse to overwrite (if the version of the superproject you are switching to in step (2) had a regular file or a directory that is part of the superproject there, and/or (B) move it away to somewhere safe (recall the discussion of ".git/modules/$submodule" hierarchy of the superproject?) automatically when it will disappear. Such enhancements will help people who _do_ "submodule init/update" the submodule in step (1) and switch to a version of the superproject that lacks it in step (2).

Previous: Johannes Schindelin
Message 5 of 5 in “Remove empty directories when checking out a commit with fewer submodules”
  1. Remove empty directories when checking out a commit with fewer submodulesPeter Collingbourne, Jan 11, 2010
  2. Johannes SchindelinJan 11, 2010
  3. Johan HerlandJan 11, 2010
  4. Johannes SchindelinJan 11, 2010
  5. Junio C HamanoJan 11, 2010

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.