summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1771299)
raw | patch | inline | side by side (parent: 1771299)
author | Junio C Hamano <junkio@cox.net> | |
Tue, 11 Oct 2005 00:34:08 +0000 (17:34 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 11 Oct 2005 00:34:08 +0000 (17:34 -0700) |
This fixes everybody's favorite gripe that switching branche with
'git checkout' leaves empty directories.
Signed-off-by: Junio C Hamano <junkio@cox.net>
'git checkout' leaves empty directories.
Signed-off-by: Junio C Hamano <junkio@cox.net>
read-tree.c | patch | blob | history |
diff --git a/read-tree.c b/read-tree.c
index 5fdf58d240e68f2c4b332dbdd02be357641127f8..6a456ae61100f8e45f97394d7ea23be4faa63fc4 100644 (file)
--- a/read-tree.c
+++ b/read-tree.c
ce->name);
}
+/* Unlink the last component and attempt to remove leading
+ * directories, in case this unlink is the removal of the
+ * last entry in the directory -- empty directories are removed.
+ */
+static void unlink_entry(char *name)
+{
+ char *cp, *prev;
+
+ if (unlink(name))
+ return;
+ prev = NULL;
+ while (1) {
+ int status;
+ cp = strrchr(name, '/');
+ if (prev)
+ *prev = '/';
+ if (!cp)
+ break;
+
+ *cp = 0;
+ status = rmdir(name);
+ if (status) {
+ *cp = '/';
+ break;
+ }
+ prev = cp;
+ }
+}
+
static void check_updates(struct cache_entry **src, int nr)
{
static struct checkout state = {
struct cache_entry *ce = *src++;
if (!ce->ce_mode) {
if (update)
- unlink(ce->name);
+ unlink_entry(ce->name);
continue;
}
if (ce->ce_flags & mask) {