Skip to content

Commit

Permalink
Remove empty directories when checking out a commit with fewer submod…
Browse files Browse the repository at this point in the history
…ules

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>
  • Loading branch information
Peter Collingbourne authored and Junio C Hamano committed Jan 12, 2010
1 parent 902f235 commit c5e558a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions t/t7400-submodule-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
12 changes: 10 additions & 2 deletions unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit c5e558a

Please sign in to comment.