@matheusbsbs / matheus-bagliano / commits / bb1faf0d5b
Fork 0

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>

Steven Grimm committed Apr 16, 2007 at 00:53 UTC bb1faf0d5bc53b193bbe25e7425458c8eb85efa3
3 files changed +25 -5
Documentation/git-rm.txt
+4 -1
@@ -7,7 +7,7 @@ git-rm - Remove files from the working tree and from the index
7
8 SYNOPSIS
9 --------
10 -'git-rm' [-f] [-n] [-r] [--cached] [--] <file>...
10 +'git-rm' [-f] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...
11
12 DESCRIPTION
13 -----------
@@ -47,6 +47,9 @@ OPTIONS
47 the paths only from the index, leaving working tree
48 files.
49
50 +\--ignore-unmatch::
51 + Exit with a zero status even if no files matched.
52 +
53 \--quiet::
54 git-rm normally outputs one line (in the form of an "rm" command)
55 for each file removed. This option suppresses that output.
builtin-rm.c
+17 -4
@@ -10,7 +10,7 @@
10 #include "tree-walk.h"
11
12 static const char builtin_rm_usage[] =
13 -"git-rm [-f] [-n] [-r] [--cached] [--quiet] [--] <file>...";
13 +"git-rm [-f] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...";
14
15 static struct {
16 int nr, alloc;
@@ -105,6 +105,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
105 {
106 int i, newfd;
107 int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
108 + int ignore_unmatch = 0;
109 const char **pathspec;
110 char *seen;
111
@@ -134,6 +135,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
135 recursive = 1;
136 else if (!strcmp(arg, "--quiet"))
137 quiet = 1;
138 + else if (!strcmp(arg, "--ignore-unmatch"))
139 + ignore_unmatch = 1;
140 else
141 usage(builtin_rm_usage);
142 }
@@ -155,14 +158,24 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
158
159 if (pathspec) {
160 const char *match;
161 + int seen_any = 0;
162 for (i = 0; (match = pathspec[i]) != NULL ; i++) {
159 - if (!seen[i])
160 - die("pathspec '%s' did not match any files",
161 - match);
163 + if (!seen[i]) {
164 + if (!ignore_unmatch) {
165 + die("pathspec '%s' did not match any files",
166 + match);
167 + }
168 + }
169 + else {
170 + seen_any = 1;
171 + }
172 if (!recursive && seen[i] == MATCHED_RECURSIVELY)
173 die("not removing '%s' recursively without -r",
174 *match ? match : ".");
175 }
176 +
177 + if (! seen_any)
178 + exit(0);
179 }
180
181 /*
t/t3600-rm.sh
+4
@@ -84,6 +84,10 @@ test_expect_success \
84 'When the rm in "git-rm -f" fails, it should not remove the file from the index' \
85 'git-ls-files --error-unmatch baz'
86
87 +test_expect_success 'Remove nonexistent file with --ignore-unmatch' '
88 + git rm --ignore-unmatch nonexistent
89 +'
90 +
91 test_expect_success '"rm" command printed' '
92 echo frotz > test-file &&
93 git add test-file &&