Skip to content

Commit 26b9f5c

Browse files
committed
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
2 parents 2431575 + c5e558a commit 26b9f5c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

t/t7400-submodule-basic.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ test_expect_success 'ls-files gracefully handles trailing slash' '
299299
300300
'
301301

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+
302311
test_expect_success 'submodule <invalid-path> warns' '
303312
304313
git submodule no-such-submodule 2> output.err &&

unpack-trees.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,16 @@ static void unlink_entry(struct cache_entry *ce)
6767
{
6868
if (has_symlink_or_noent_leading_path(ce->name, ce_namelen(ce)))
6969
return;
70-
if (unlink_or_warn(ce->name))
71-
return;
70+
if (S_ISGITLINK(ce->ce_mode)) {
71+
if (rmdir(ce->name)) {
72+
warning("unable to rmdir %s: %s",
73+
ce->name, strerror(errno));
74+
return;
75+
}
76+
}
77+
else
78+
if (unlink_or_warn(ce->name))
79+
return;
7280
schedule_dir_for_removal(ce->name, ce_namelen(ce));
7381
}
7482

0 commit comments

Comments
 (0)