public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Delan Azabani <delan@azabani•com>
To: git@vger•kernel.org
Subject: [PATCH] rm: accept -R and --recursive in addition to -r
Date: Tue, 17 Sep 2019 18:30:00 +1000	[thread overview]
Message-ID: <76f0d8e57866db57@daria.daz.cat> (raw)

POSIX rm(1) accepts both -r and -R, so we accept -R here by analogy
with that and with commands like cp(1) + ls(1) + grep(1), where on
many or all platforms it’s the only way to recurse. For completeness
with GNU coreutils, we also accept --recursive here.

5c387428f10c2 introduces a mechanism that might have been nice to use
here (OPTION_ALIAS), but I didn’t use it because we would need to add
two different long options, and it’s primarily there to fix a problem
that won’t happen anyway unless there are two similar long options.

Signed-off-by: Delan Azabani <delan@azabani•com>
---
 builtin/rm.c  |  3 ++-
 t/t3600-rm.sh | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/builtin/rm.c b/builtin/rm.c
index 19ce95a901..36c4cea256 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -242,7 +242,8 @@ static struct option builtin_rm_options[] = {
 	OPT__QUIET(&quiet, N_("do not list removed files")),
 	OPT_BOOL( 0 , "cached",         &index_only, N_("only remove from the index")),
 	OPT__FORCE(&force, N_("override the up-to-date check"), PARSE_OPT_NOCOMPLETE),
-	OPT_BOOL('r', NULL,             &recursive,  N_("allow recursive removal")),
+	OPT_BOOL_F('R', NULL,           &recursive,  N_("allow recursive removal"), PARSE_OPT_HIDDEN),
+	OPT_BOOL('r', "recursive",      &recursive,  N_("allow recursive removal")),
 	OPT_BOOL( 0 , "ignore-unmatch", &ignore_unmatch,
 				N_("exit with a zero status even if nothing matched")),
 	OPT_END(),
diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 66282a720e..b2ddbba83c 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -212,6 +212,26 @@ test_expect_success 'Recursive with -r -f' '
 	test_path_is_missing frotz
 '
 
+test_expect_success 'Recursive with -R' '
+	mkdir -p frotz &&
+	touch frotz/R &&
+	git add frotz &&
+	git commit -m R &&
+	git rm -R frotz &&
+	test_path_is_missing frotz/R &&
+	test_path_is_missing frotz
+'
+
+test_expect_success 'Recursive with --recursive' '
+	mkdir -p frotz &&
+	touch frotz/recursive &&
+	git add frotz &&
+	git commit -m recursive &&
+	git rm --recursive frotz &&
+	test_path_is_missing frotz/recursive &&
+	test_path_is_missing frotz
+'
+
 test_expect_success 'Remove nonexistent file returns nonzero exit status' '
 	test_must_fail git rm nonexistent
 '
-- 
2.19.2


                 reply	other threads:[~2019-09-17  9:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=76f0d8e57866db57@daria.daz.cat \
    --to=delan@azabani$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox