diff options
Diffstat (limited to 'builtin/rm.c')
-rw-r--r-- | builtin/rm.c | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/builtin/rm.c b/builtin/rm.c index 0df0b4d94..18bf21899 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -267,18 +267,18 @@ static int ignore_unmatch = 0; static struct option builtin_rm_options[] = { OPT__DRY_RUN(&show_only, N_("dry run")), OPT__QUIET(&quiet, N_("do not list removed files")), - OPT_BOOLEAN( 0 , "cached", &index_only, N_("only remove from the index")), + OPT_BOOL( 0 , "cached", &index_only, N_("only remove from the index")), OPT__FORCE(&force, N_("override the up-to-date check")), - OPT_BOOLEAN('r', NULL, &recursive, N_("allow recursive removal")), - OPT_BOOLEAN( 0 , "ignore-unmatch", &ignore_unmatch, + OPT_BOOL('r', NULL, &recursive, N_("allow recursive removal")), + OPT_BOOL( 0 , "ignore-unmatch", &ignore_unmatch, N_("exit with a zero status even if nothing matched")), OPT_END(), }; int cmd_rm(int argc, const char **argv, const char *prefix) { - int i, newfd; - const char **pathspec; + int i, newfd, seen_any; + const char **pathspec, *match; char *seen; git_config(git_default_config, NULL); @@ -314,7 +314,6 @@ int cmd_rm(int argc, const char **argv, const char *prefix) pathspec = get_pathspec(prefix, argv); refresh_index(&the_index, REFRESH_QUIET, pathspec, NULL, NULL); - seen = NULL; for (i = 0; pathspec[i] ; i++) /* nothing */; seen = xcalloc(i, 1); @@ -328,27 +327,24 @@ int cmd_rm(int argc, const char **argv, const char *prefix) list.entry[list.nr++].is_submodule = S_ISGITLINK(ce->ce_mode); } - if (pathspec) { - const char *match; - int seen_any = 0; - for (i = 0; (match = pathspec[i]) != NULL ; i++) { - if (!seen[i]) { - if (!ignore_unmatch) { - die(_("pathspec '%s' did not match any files"), - match); - } - } - else { - seen_any = 1; + + seen_any = 0; + for (i = 0; (match = pathspec[i]) != NULL ; i++) { + if (!seen[i]) { + if (!ignore_unmatch) { + die(_("pathspec '%s' did not match any files"), + match); } - if (!recursive && seen[i] == MATCHED_RECURSIVELY) - die(_("not removing '%s' recursively without -r"), - *match ? match : "."); } - - if (! seen_any) - exit(0); + else { + seen_any = 1; + } + if (!recursive && seen[i] == MATCHED_RECURSIVELY) + die(_("not removing '%s' recursively without -r"), + *match ? match : "."); } + if (!seen_any) + exit(0); /* * If not forced, the file, the index and the HEAD (if exists) |