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

git-apply: Remove directories that have become empty after deleting a file.

Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Alexandre Julliard committed Jan 9, 2007 at 21:25 UTC d234b21c6966ee1d2dc4b5dcd9dca73a102bc442
1 file changed +13 -2
builtin-apply.c
+13 -2
@@ -2239,8 +2239,19 @@ static void remove_file(struct patch *patch)
2239 die("unable to remove %s from index", patch->old_name);
2240 cache_tree_invalidate_path(active_cache_tree, patch->old_name);
2241 }
2242 - if (!cached)
2243 - unlink(patch->old_name);
2242 + if (!cached) {
2243 + if (!unlink(patch->old_name)) {
2244 + char *name = xstrdup(patch->old_name);
2245 + char *end = strrchr(name, '/');
2246 + while (end) {
2247 + *end = 0;
2248 + if (rmdir(name))
2249 + break;
2250 + end = strrchr(name, '/');
2251 + }
2252 + free(name);
2253 + }
2254 + }
2255 }
2256
2257 static void add_index_file(const char *path, unsigned mode, void *buf, unsigned long size)