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>
This commit is contained in:
parent
f948792990
commit
bb1faf0d5b
@ -7,7 +7,7 @@ git-rm - Remove files from the working tree and from the index
|
||||
|
||||
SYNOPSIS
|
||||
--------
|
||||
'git-rm' [-f] [-n] [-r] [--cached] [--] <file>...
|
||||
'git-rm' [-f] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
@ -47,6 +47,9 @@ OPTIONS
|
||||
the paths only from the index, leaving working tree
|
||||
files.
|
||||
|
||||
\--ignore-unmatch::
|
||||
Exit with a zero status even if no files matched.
|
||||
|
||||
\--quiet::
|
||||
git-rm normally outputs one line (in the form of an "rm" command)
|
||||
for each file removed. This option suppresses that output.
|
||||
|
21
builtin-rm.c
21
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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -84,6 +84,10 @@ test_expect_success \
|
||||
'When the rm in "git-rm -f" fails, it should not remove the file from the index' \
|
||||
'git-ls-files --error-unmatch baz'
|
||||
|
||||
test_expect_success 'Remove nonexistent file with --ignore-unmatch' '
|
||||
git rm --ignore-unmatch nonexistent
|
||||
'
|
||||
|
||||
test_expect_success '"rm" command printed' '
|
||||
echo frotz > test-file &&
|
||||
git add test-file &&
|
||||
|
Loading…
Reference in New Issue
Block a user