@matheusbsbs / matheus-bagliano / commits / 3fc0d131c5
Fork 0

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

Jeff King committed Feb 19, 2010 at 00:57 UTC 3fc0d131c573f6f774e2e4abba9cbda694b08321
2 files changed +9 -1
dir.c
+1 -1
@@ -864,7 +864,7 @@ int remove_path(const char *name)
864 slash = dirs + (slash - name);
865 do {
866 *slash = '\0';
867 - } while (rmdir(dirs) && (slash = strrchr(dirs, '/')));
867 + } while (rmdir(dirs) == 0 && (slash = strrchr(dirs, '/')));
868 free(dirs);
869 }
870 return 0;
t/t3600-rm.sh
+8
@@ -271,4 +271,12 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
271 test "$status" != 0
272 '
273
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 +
282 test_done