diff options
author | Steven Grimm <koreth@midwinter.com> | 2007-04-16 00:53:24 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-04-17 00:19:11 -0700 |
commit | bb1faf0d5bc53b193bbe25e7425458c8eb85efa3 (patch) | |
tree | 46db8d5a9e7845ebe78ee2148a5bd69c8b989268 /builtin-rm.c | |
parent | f948792990f82a35bf0c98510e7511ef8acb9cd3 (diff) | |
download | git-bb1faf0d5bc53b193bbe25e7425458c8eb85efa3.tar.gz |
Add --ignore-unmatch option to exit with zero status when no files are removed.
Signed-off-by: Steven Grimm <koreth@midwinter.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-rm.c')
-rw-r--r-- | builtin-rm.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/builtin-rm.c b/builtin-rm.c index b77b058e38..4a0bd93c8b 100644 --- a/builtin-rm.c +++ b/builtin-rm.c @@ -10,7 +10,7 @@ #include "tree-walk.h" static const char builtin_rm_usage[] = -"git-rm [-f] [-n] [-r] [--cached] [--quiet] [--] <file>..."; +"git-rm [-f] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>..."; static struct { int nr, alloc; @@ -105,6 +105,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix) { int i, newfd; int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0; + int ignore_unmatch = 0; const char **pathspec; char *seen; @@ -134,6 +135,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix) recursive = 1; else if (!strcmp(arg, "--quiet")) quiet = 1; + else if (!strcmp(arg, "--ignore-unmatch")) + ignore_unmatch = 1; else usage(builtin_rm_usage); } @@ -155,14 +158,24 @@ int cmd_rm(int argc, const char **argv, const char *prefix) if (pathspec) { const char *match; + int seen_any = 0; for (i = 0; (match = pathspec[i]) != NULL ; i++) { - if (!seen[i]) - die("pathspec '%s' did not match any files", - match); + if (!seen[i]) { + if (!ignore_unmatch) { + die("pathspec '%s' did not match any files", + match); + } + } + else { + seen_any = 1; + } if (!recursive && seen[i] == MATCHED_RECURSIVELY) die("not removing '%s' recursively without -r", *match ? match : "."); } + + if (! seen_any) + exit(0); } /* |