Remove empty directories when checking out a commit with fewer submodules
[gitweb.git] / unpack-trees.c
index dd5999c3562219b7993420b22257f4088ab82b8d..b69847d6c9205d837c91ef7a1c5e7cb794d7fdad 100644 (file)
@@ -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));
 }