From: Alexandre Julliard Date: Tue, 9 Jan 2007 20:25:46 +0000 (+0100) Subject: git-apply: Remove directories that have become empty after deleting a file. X-Git-Tag: v1.5.0-rc1~33 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d234b21c6966ee1d2dc4b5dcd9dca73a102bc442;p=git.git git-apply: Remove directories that have become empty after deleting a file. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- diff --git a/builtin-apply.c b/builtin-apply.c index 38a9fdd80..54fd2cb0c 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -2239,8 +2239,19 @@ static void remove_file(struct patch *patch) die("unable to remove %s from index", patch->old_name); cache_tree_invalidate_path(active_cache_tree, patch->old_name); } - if (!cached) - unlink(patch->old_name); + if (!cached) { + if (!unlink(patch->old_name)) { + char *name = xstrdup(patch->old_name); + char *end = strrchr(name, '/'); + while (end) { + *end = 0; + if (rmdir(name)) + break; + end = strrchr(name, '/'); + } + free(name); + } + } } static void add_index_file(const char *path, unsigned mode, void *buf, unsigned long size)