@matheusbsbs / matheus-bagliano / commits / c5e558a80a
Fork 0

Remove empty directories when checking out a commit with fewer submodules

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Peter Collingbourne committed Jan 11, 2010 at 02:59 UTC c5e558a80ad27774b9984258a31fbf46a1d7c152
2 files changed +19 -2
t/t7400-submodule-basic.sh
+9
@@ -299,6 +299,15 @@ test_expect_success 'ls-files gracefully handles trailing slash' '
299
300 '
301
302 +test_expect_success 'moving to a commit without submodule does not leave empty dir' '
303 + rm -rf init &&
304 + mkdir init &&
305 + git reset --hard &&
306 + git checkout initial &&
307 + test ! -d init &&
308 + git checkout second
309 +'
310 +
311 test_expect_success 'submodule <invalid-path> warns' '
312
313 git submodule no-such-submodule 2> output.err &&
unpack-trees.c
+10 -2
@@ -61,8 +61,16 @@ static void unlink_entry(struct cache_entry *ce)
61 {
62 if (has_symlink_or_noent_leading_path(ce->name, ce_namelen(ce)))
63 return;
64 - if (unlink_or_warn(ce->name))
65 - return;
64 + if (S_ISGITLINK(ce->ce_mode)) {
65 + if (rmdir(ce->name)) {
66 + warning("unable to rmdir %s: %s",
67 + ce->name, strerror(errno));
68 + return;
69 + }
70 + }
71 + else
72 + if (unlink_or_warn(ce->name))
73 + return;
74 schedule_dir_for_removal(ce->name, ce_namelen(ce));
75 }
76