X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-rm.c;h=b7126e3e25d4f52ae8c4a120d524a24c11129785;hb=0eb5ebc1d862737ea2b313d0d77d120b3d114099;hp=6bd82111d25f669616653d655dd940f2bd5c99e7;hpb=5fc3e67ac0241c491dcf1c0c9dcd4a4d83e7c243;p=git.git diff --git a/builtin-rm.c b/builtin-rm.c index 6bd82111d..b7126e3e2 100644 --- a/builtin-rm.c +++ b/builtin-rm.c @@ -29,26 +29,6 @@ static void add_list(const char *name) list.name[list.nr++] = name; } -static int remove_file(const char *name) -{ - int ret; - char *slash; - - ret = unlink(name); - if (ret && errno == ENOENT) - /* The user has removed it from the filesystem by hand */ - ret = errno = 0; - - if (!ret && (slash = strrchr(name, '/'))) { - char *n = xstrdup(name); - do { - n[slash - name] = 0; - name = n; - } while (!rmdir(name) && (slash = strrchr(name, '/'))); - } - return ret; -} - static int check_local_mod(unsigned char *head, int index_only) { /* items in list are already sorted in the cache order, @@ -99,12 +79,13 @@ static int check_local_mod(unsigned char *head, int index_only) || hashcmp(ce->sha1, sha1)) staged_changes = 1; - if (local_changes && staged_changes) + if (local_changes && staged_changes && + !(index_only && is_empty_blob_sha1(ce->sha1))) errs = error("'%s' has staged content different " "from both the file and the HEAD\n" "(use -f to force removal)", name); else if (!index_only) { - /* It's not dangerous to git-rm --cached a + /* It's not dangerous to "git rm --cached" a * file if the index matches the file or the * HEAD, since it means the deleted content is * still available somewhere. @@ -157,6 +138,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix) if (read_cache() < 0) die("index file corrupt"); + refresh_cache(REFRESH_QUIET); pathspec = get_pathspec(prefix, argv); seen = NULL; @@ -239,7 +221,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix) int removed = 0; for (i = 0; i < list.nr; i++) { const char *path = list.name[i]; - if (!remove_file(path)) { + if (!remove_path(path)) { removed = 1; continue; }