Merge branch 'pc/uninteresting-submodule-disappear-upon-switch-branches'
authorJunio C Hamano <gitster@pobox.com>
Tue, 19 Jan 2010 02:12:57 +0000 (18:12 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 Jan 2010 02:12:57 +0000 (18:12 -0800)
* pc/uninteresting-submodule-disappear-upon-switch-branches:
Remove empty directories when checking out a commit with fewer submodules

t/t7400-submodule-basic.sh
unpack-trees.c
index a0cc99ab9f5b262851a1075193f5529b5582fd0a..1a4dc5f89353df7d7bda4bea539ee5bd7a3b9bae 100755 (executable)
@@ -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 &&
index acdd3117370e596716a0bdb751d6255690e6c700..0ddbef3e6355da40a1293a6a7c49b4bc5d75b842 100644 (file)
@@ -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));
 }