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

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>

Steven Grimm committed Apr 16, 2007 at 00:46 UTC b48caa20de7f62f648de7d3dbb0ceb462879e903
3 files changed +34 -3
Documentation/git-rm.txt
+4
@@ -47,6 +47,10 @@ OPTIONS
47 the paths only from the index, leaving working tree
48 files.
49
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 +
54
55 DISCUSSION
56 ----------
builtin-rm.c
+6 -3
@@ -10,7 +10,7 @@
10 #include "tree-walk.h"
11
12 static const char builtin_rm_usage[] =
13 -"git-rm [-f] [-n] [-r] [--cached] [--] <file>...";
13 +"git-rm [-f] [-n] [-r] [--cached] [--quiet] [--] <file>...";
14
15 static struct {
16 int nr, alloc;
@@ -104,7 +104,7 @@ static struct lock_file lock_file;
104 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;
107 + int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
108 const char **pathspec;
109 char *seen;
110
@@ -132,6 +132,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
132 force = 1;
133 else if (!strcmp(arg, "-r"))
134 recursive = 1;
135 + else if (!strcmp(arg, "--quiet"))
136 + quiet = 1;
137 else
138 usage(builtin_rm_usage);
139 }
@@ -187,7 +189,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
189 */
190 for (i = 0; i < list.nr; i++) {
191 const char *path = list.name[i];
190 - printf("rm '%s'\n", path);
192 + if (!quiet)
193 + printf("rm '%s'\n", path);
194
195 if (remove_file_from_cache(path))
196 die("git-rm: unable to remove %s", path);
t/t3600-rm.sh
+24
@@ -84,6 +84,26 @@ 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 '"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 +
107 # Now, failure cases.
108 test_expect_success 'Re-add foo and baz' '
109 git add foo baz &&
@@ -154,4 +174,8 @@ test_expect_success 'Recursive with -r -f' '
174 ! test -d frotz
175 '
176
177 +test_expect_failure 'Remove nonexistent file returns nonzero exit status' '
178 + git rm nonexistent
179 +'
180 +
181 test_done