summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Alexandre Julliard <julliard@winehq.org>2007-01-09 21:25:46 +0100
committerLibravatar Junio C Hamano <junkio@cox.net>2007-01-09 16:05:00 -0800
commitd234b21c6966ee1d2dc4b5dcd9dca73a102bc442 (patch)
tree5e52ea6127e31171f901fb670a5298b1ff4ea37d
parentget_tree_entry: map blank requested entry to tree root (diff)
downloadtgif-d234b21c6966ee1d2dc4b5dcd9dca73a102bc442.tar.xz
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>
-rw-r--r--builtin-apply.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/builtin-apply.c b/builtin-apply.c
index 38a9fdd808..54fd2cb0c7 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)