Add --quiet option to suppress output of "rm" commands for removed files.
Signed-off-by: Steven Grimm <koreth@midwinter.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
c7263d4d3d
commit
b48caa20de
@ -47,6 +47,10 @@ OPTIONS
|
|||||||
the paths only from the index, leaving working tree
|
the paths only from the index, leaving working tree
|
||||||
files.
|
files.
|
||||||
|
|
||||||
|
\--quiet::
|
||||||
|
git-rm normally outputs one line (in the form of an "rm" command)
|
||||||
|
for each file removed. This option suppresses that output.
|
||||||
|
|
||||||
|
|
||||||
DISCUSSION
|
DISCUSSION
|
||||||
----------
|
----------
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include "tree-walk.h"
|
#include "tree-walk.h"
|
||||||
|
|
||||||
static const char builtin_rm_usage[] =
|
static const char builtin_rm_usage[] =
|
||||||
"git-rm [-f] [-n] [-r] [--cached] [--] <file>...";
|
"git-rm [-f] [-n] [-r] [--cached] [--quiet] [--] <file>...";
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
int nr, alloc;
|
int nr, alloc;
|
||||||
@ -104,7 +104,7 @@ static struct lock_file lock_file;
|
|||||||
int cmd_rm(int argc, const char **argv, const char *prefix)
|
int cmd_rm(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
int i, newfd;
|
int i, newfd;
|
||||||
int show_only = 0, force = 0, index_only = 0, recursive = 0;
|
int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
|
||||||
const char **pathspec;
|
const char **pathspec;
|
||||||
char *seen;
|
char *seen;
|
||||||
|
|
||||||
@ -132,6 +132,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
|
|||||||
force = 1;
|
force = 1;
|
||||||
else if (!strcmp(arg, "-r"))
|
else if (!strcmp(arg, "-r"))
|
||||||
recursive = 1;
|
recursive = 1;
|
||||||
|
else if (!strcmp(arg, "--quiet"))
|
||||||
|
quiet = 1;
|
||||||
else
|
else
|
||||||
usage(builtin_rm_usage);
|
usage(builtin_rm_usage);
|
||||||
}
|
}
|
||||||
@ -187,7 +189,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
|
|||||||
*/
|
*/
|
||||||
for (i = 0; i < list.nr; i++) {
|
for (i = 0; i < list.nr; i++) {
|
||||||
const char *path = list.name[i];
|
const char *path = list.name[i];
|
||||||
printf("rm '%s'\n", path);
|
if (!quiet)
|
||||||
|
printf("rm '%s'\n", path);
|
||||||
|
|
||||||
if (remove_file_from_cache(path))
|
if (remove_file_from_cache(path))
|
||||||
die("git-rm: unable to remove %s", path);
|
die("git-rm: unable to remove %s", path);
|
||||||
|
@ -84,6 +84,26 @@ test_expect_success \
|
|||||||
'When the rm in "git-rm -f" fails, it should not remove the file from the index' \
|
'When the rm in "git-rm -f" fails, it should not remove the file from the index' \
|
||||||
'git-ls-files --error-unmatch baz'
|
'git-ls-files --error-unmatch baz'
|
||||||
|
|
||||||
|
test_expect_success '"rm" command printed' '
|
||||||
|
echo frotz > test-file &&
|
||||||
|
git add test-file &&
|
||||||
|
git commit -m "add file for rm test" &&
|
||||||
|
git rm test-file > rm-output &&
|
||||||
|
test `egrep "^rm " rm-output | wc -l` = 1 &&
|
||||||
|
rm -f test-file rm-output &&
|
||||||
|
git commit -m "remove file from rm test"
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '"rm" command suppressed with --quiet' '
|
||||||
|
echo frotz > test-file &&
|
||||||
|
git add test-file &&
|
||||||
|
git commit -m "add file for rm --quiet test" &&
|
||||||
|
git rm --quiet test-file > rm-output &&
|
||||||
|
test `wc -l < rm-output` = 0 &&
|
||||||
|
rm -f test-file rm-output &&
|
||||||
|
git commit -m "remove file from rm --quiet test"
|
||||||
|
'
|
||||||
|
|
||||||
# Now, failure cases.
|
# Now, failure cases.
|
||||||
test_expect_success 'Re-add foo and baz' '
|
test_expect_success 'Re-add foo and baz' '
|
||||||
git add foo baz &&
|
git add foo baz &&
|
||||||
@ -154,4 +174,8 @@ test_expect_success 'Recursive with -r -f' '
|
|||||||
! test -d frotz
|
! test -d frotz
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_failure 'Remove nonexistent file returns nonzero exit status' '
|
||||||
|
git rm nonexistent
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user