Code

git-mergetool: properly handle "git mergetool -- filename"
[git.git] / builtin-rm.c
index ee8247b08cd007f73d5dfffa560a9efe33d327b9..e06640cf8d3418cbbe177b8fdcdccd19e0f3379f 100644 (file)
@@ -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,
@@ -104,7 +84,7 @@ static int check_local_mod(unsigned char *head, int index_only)
                                     "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.
@@ -131,7 +111,7 @@ static struct option builtin_rm_options[] = {
        OPT__DRY_RUN(&show_only),
        OPT__QUIET(&quiet),
        OPT_BOOLEAN( 0 , "cached",         &index_only, "only remove from the index"),
-       OPT_BOOLEAN('f', NULL,             &force,      "override the up-to-date check"),
+       OPT_BOOLEAN('f', "force",          &force,      "override the up-to-date check"),
        OPT_BOOLEAN('r', NULL,             &recursive,  "allow recursive removal"),
        OPT_BOOLEAN( 0 , "ignore-unmatch", &ignore_unmatch,
                                "exit with a zero status even if nothing matched"),
@@ -157,6 +137,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;
@@ -221,7 +202,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
                        printf("rm '%s'\n", path);
 
                if (remove_file_from_cache(path))
-                       die("git-rm: unable to remove %s", path);
+                       die("git rm: unable to remove %s", path);
        }
 
        if (show_only)
@@ -239,12 +220,12 @@ 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;
                        }
                        if (!removed)
-                               die("git-rm: %s: %s", path, strerror(errno));
+                               die("git rm: %s: %s", path, strerror(errno));
                }
        }