* This applies patches on top of some (arbitrary) version of the SCM.
*
*/
-#include <fnmatch.h>
#include "cache.h"
#include "cache-tree.h"
#include "quote.h"
struct fragment dummy;
if (parse_fragment_header(line, len, &dummy) < 0)
continue;
- error("patch fragment without header at line %d: %.*s", linenr, (int)len-1, line);
+ die("patch fragment without header at line %d: %.*s",
+ linenr, (int)len-1, line);
}
if (size < len + 6)
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)