From: Steven Grimm <koreth@midwinter.com>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH 1/2] Add --quiet option to suppress output of "rm" commands for removed files.
Date: Mon, 16 Apr 2007 00:46:48 -0700 [thread overview]
Message-ID: <20070416074648.GA18719@midwinter.com> (raw)
In-Reply-To: <7vps65yvc1.fsf@assigned-by-dhcp.cox.net>
Signed-off-by: Steven Grimm <koreth@midwinter.com>
---
Splitting this into two different options (and two patches) per Junio's
comments.
Documentation/git-rm.txt | 4 ++++
builtin-rm.c | 10 +++++++---
t/t3600-rm.sh | 24 ++++++++++++++++++++++++
3 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-rm.txt b/Documentation/git-rm.txt
index 6feebc0..b051ccb 100644
--- a/Documentation/git-rm.txt
+++ b/Documentation/git-rm.txt
@@ -47,6 +47,10 @@ OPTIONS
the paths only from the index, leaving working tree
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
----------
diff --git a/builtin-rm.c b/builtin-rm.c
index 8a0738f..7eb9a42 100644
--- a/builtin-rm.c
+++ b/builtin-rm.c
@@ -10,7 +10,7 @@
#include "tree-walk.h"
static const char builtin_rm_usage[] =
-"git-rm [-f] [-n] [-r] [--cached] [--] <file>...";
+"git-rm [-f] [-n] [-r] [--cached] [--quiet] [--] <file>...";
static struct {
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 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;
char *seen;
@@ -132,6 +132,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
force = 1;
else if (!strcmp(arg, "-r"))
recursive = 1;
+ else if (!strcmp(arg, "--quiet"))
+ quiet = 1;
else
usage(builtin_rm_usage);
}
@@ -187,7 +189,9 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
*/
for (i = 0; i < list.nr; 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))
die("git-rm: unable to remove %s", path);
diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index e31cf93..da9da92 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -84,6 +84,26 @@ 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 '"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.
test_expect_success 'Re-add foo and baz' '
git add foo baz &&
@@ -154,4 +174,8 @@ test_expect_success 'Recursive with -r -f' '
! test -d frotz
'
+test_expect_failure 'Remove nonexistent file returns nonzero exit status' '
+ git rm nonexistent
+'
+
test_done
--
1.5.1.1.99.g0ea98
next prev parent reply other threads:[~2007-04-16 7:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-16 0:04 [PATCH] Add -q option to "git rm" to suppress output when there aren't errors Steven Grimm
2007-04-16 0:13 ` Junio C Hamano
2007-04-16 0:17 ` Steven Grimm
2007-04-16 1:14 ` Junio C Hamano
2007-04-16 7:46 ` Steven Grimm [this message]
2007-04-16 7:53 ` [PATCH 2/2] Add --ignore-notfound option to exit with zero status when no files are removed Steven Grimm
2007-04-16 7:59 ` Junio C Hamano
2007-04-16 8:13 ` Steven Grimm
2007-04-16 8:50 ` Jeff King
2007-04-16 8:53 ` Junio C Hamano
2007-04-16 9:04 ` Jeff King
2007-04-16 18:29 ` Josef Weidendorfer
2007-04-16 8:12 ` Steven Grimm
2007-04-16 7:54 ` [PATCH] Add -q option to "git rm" to suppress output when there aren't errors Alex Riesen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070416074648.GA18719@midwinter.com \
--to=koreth@midwinter.com \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.