summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2010-01-18 18:12:57 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-01-18 18:12:57 -0800
commit26b9f5cc99a35d4f678c2f565e48237fc9515444 (patch)
tree52775c8cb6e23c620adb84f6f34186085a41d8d9
parentMerge branch 'nd/include-termios-for-osol' (diff)
parentRemove empty directories when checking out a commit with fewer submodules (diff)
downloadtgif-26b9f5cc99a35d4f678c2f565e48237fc9515444.tar.xz
Merge branch 'pc/uninteresting-submodule-disappear-upon-switch-branches'
* pc/uninteresting-submodule-disappear-upon-switch-branches: Remove empty directories when checking out a commit with fewer submodules
-rwxr-xr-xt/t7400-submodule-basic.sh9
-rw-r--r--unpack-trees.c12
2 files changed, 19 insertions, 2 deletions
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index a0cc99ab9f..1a4dc5f893 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 acdd311737..0ddbef3e63 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -67,8 +67,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));
}