Skip to content

Commit b48caa2

Browse files
sgrimmJunio C Hamano
authored andcommitted
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>
1 parent c7263d4 commit b48caa2

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

Documentation/git-rm.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ OPTIONS
4747
the paths only from the index, leaving working tree
4848
files.
4949

50+
\--quiet::
51+
git-rm normally outputs one line (in the form of an "rm" command)
52+
for each file removed. This option suppresses that output.
53+
5054

5155
DISCUSSION
5256
----------

builtin-rm.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "tree-walk.h"
1111

1212
static const char builtin_rm_usage[] =
13-
"git-rm [-f] [-n] [-r] [--cached] [--] <file>...";
13+
"git-rm [-f] [-n] [-r] [--cached] [--quiet] [--] <file>...";
1414

1515
static struct {
1616
int nr, alloc;
@@ -104,7 +104,7 @@ static struct lock_file lock_file;
104104
int cmd_rm(int argc, const char **argv, const char *prefix)
105105
{
106106
int i, newfd;
107-
int show_only = 0, force = 0, index_only = 0, recursive = 0;
107+
int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
108108
const char **pathspec;
109109
char *seen;
110110

@@ -132,6 +132,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
132132
force = 1;
133133
else if (!strcmp(arg, "-r"))
134134
recursive = 1;
135+
else if (!strcmp(arg, "--quiet"))
136+
quiet = 1;
135137
else
136138
usage(builtin_rm_usage);
137139
}
@@ -187,7 +189,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
187189
*/
188190
for (i = 0; i < list.nr; i++) {
189191
const char *path = list.name[i];
190-
printf("rm '%s'\n", path);
192+
if (!quiet)
193+
printf("rm '%s'\n", path);
191194

192195
if (remove_file_from_cache(path))
193196
die("git-rm: unable to remove %s", path);

t/t3600-rm.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,26 @@ test_expect_success \
8484
'When the rm in "git-rm -f" fails, it should not remove the file from the index' \
8585
'git-ls-files --error-unmatch baz'
8686

87+
test_expect_success '"rm" command printed' '
88+
echo frotz > test-file &&
89+
git add test-file &&
90+
git commit -m "add file for rm test" &&
91+
git rm test-file > rm-output &&
92+
test `egrep "^rm " rm-output | wc -l` = 1 &&
93+
rm -f test-file rm-output &&
94+
git commit -m "remove file from rm test"
95+
'
96+
97+
test_expect_success '"rm" command suppressed with --quiet' '
98+
echo frotz > test-file &&
99+
git add test-file &&
100+
git commit -m "add file for rm --quiet test" &&
101+
git rm --quiet test-file > rm-output &&
102+
test `wc -l < rm-output` = 0 &&
103+
rm -f test-file rm-output &&
104+
git commit -m "remove file from rm --quiet test"
105+
'
106+
87107
# Now, failure cases.
88108
test_expect_success 'Re-add foo and baz' '
89109
git add foo baz &&
@@ -154,4 +174,8 @@ test_expect_success 'Recursive with -r -f' '
154174
! test -d frotz
155175
'
156176

177+
test_expect_failure 'Remove nonexistent file returns nonzero exit status' '
178+
git rm nonexistent
179+
'
180+
157181
test_done

0 commit comments

Comments
 (0)