git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Remove empty directories when checking out a commit with fewer submodules
@ 2010-01-11  2:59 Peter Collingbourne
  2010-01-11  8:57 ` Johannes Schindelin
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Collingbourne @ 2010-01-11  2:59 UTC (permalink / raw)
  To: git; +Cc: Peter Collingbourne

Change the unlink_entry function to use rmdir to remove submodule
directories.  Currently we try to use unlink, which will never succeed.

Of course rmdir will only succeed for empty (i.e. not checked out)
submodule directories.  Behaviour if a submodule is checked out stays
essentially the same: print a warning message and keep the submodule
directory.

Signed-off-by: Peter Collingbourne <peter@pcc.me.uk>
---
 t/t7400-submodule-basic.sh |    9 +++++++++
 unpack-trees.c             |   12 ++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index a0cc99a..1a4dc5f 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -299,6 +299,15 @@ test_expect_success 'ls-files gracefully handles trailing slash' '
 
 '
 
+test_expect_success 'moving to a commit without submodule does not leave empty dir' '
+	rm -rf init &&
+	mkdir init &&
+	git reset --hard &&
+	git checkout initial &&
+	test ! -d init &&
+	git checkout second
+'
+
 test_expect_success 'submodule <invalid-path> warns' '
 
 	git submodule no-such-submodule 2> output.err &&
diff --git a/unpack-trees.c b/unpack-trees.c
index dd5999c..b69847d 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -61,8 +61,16 @@ static void unlink_entry(struct cache_entry *ce)
 {
 	if (has_symlink_or_noent_leading_path(ce->name, ce_namelen(ce)))
 		return;
-	if (unlink_or_warn(ce->name))
-		return;
+	if (S_ISGITLINK(ce->ce_mode)) {
+		if (rmdir(ce->name)) {
+			warning("unable to rmdir %s: %s",
+				ce->name, strerror(errno));
+			return;
+		}
+	}
+	else
+		if (unlink_or_warn(ce->name))
+			return;
 	schedule_dir_for_removal(ce->name, ce_namelen(ce));
 }
 
-- 
1.6.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-01-11  9:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-11  2:59 [PATCH] Remove empty directories when checking out a commit with fewer submodules Peter Collingbourne
2010-01-11  8:57 ` Johannes Schindelin
2010-01-11  9:32   ` Johan Herland
2010-01-11  9:45     ` Johannes Schindelin
2010-01-11  9:53   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).