git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] rm: accept -R and --recursive in addition to -r
@ 2019-09-17  8:30 Delan Azabani
  0 siblings, 0 replies; only message in thread
From: Delan Azabani @ 2019-09-17  8:30 UTC (permalink / raw)
  To: git

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-09-17  9:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-17  8:30 [PATCH] rm: accept -R and --recursive in addition to -r Delan Azabani

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).