Skip to content

Commit 3fc0d13

Browse files
peffgitster
authored andcommitted
rm: fix bug in recursive subdirectory removal
If we remove a path in a/deep/subdirectory, we should try to remove as many trailing components as possible (i.e., subdirectory, then deep, then a). However, the test for the return value of rmdir was reversed, so we only ever deleted at most one level. The fix is in remove_path, so "apply" and "merge-recursive" also are fixed. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f01f109 commit 3fc0d13

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ int remove_path(const char *name)
864864
slash = dirs + (slash - name);
865865
do {
866866
*slash = '\0';
867-
} while (rmdir(dirs) && (slash = strrchr(dirs, '/')));
867+
} while (rmdir(dirs) == 0 && (slash = strrchr(dirs, '/')));
868868
free(dirs);
869869
}
870870
return 0;

t/t3600-rm.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,12 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
271271
test "$status" != 0
272272
'
273273

274+
test_expect_success 'rm removes subdirectories recursively' '
275+
mkdir -p dir/subdir/subsubdir &&
276+
echo content >dir/subdir/subsubdir/file &&
277+
git add dir/subdir/subsubdir/file &&
278+
git rm -f dir/subdir/subsubdir/file &&
279+
! test -d dir
280+
'
281+
274282
test_done

0 commit comments

Comments
 (0)