{"thread":{"id":"51864","subject":"[PATCH] rm: accept -R and --recursive in addition to -r","startedAt":"2019-09-17T09:32:11Z","lastAt":"2019-09-17T09:32:11Z","messageCount":1,"participants":["Delan Azabani"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"382477","messageId":"76f0d8e57866db57@daria.daz.cat","threadId":"51864","inReplyTo":null,"subject":"[PATCH] rm: accept -R and --recursive in addition to -r","fromName":"Delan Azabani","fromEmail":"delan@azabani.com","sentAt":"2019-09-17T08:30:00Z","receivedAt":"2019-09-17T09:32:11Z","isPatch":true,"sender":{"key":"delan@azabani.com","avatar":null},"body":"POSIX rm(1) accepts both -r and -R, so we accept -R here by analogy\nwith that and with commands like cp(1) + ls(1) + grep(1), where on\nmany or all platforms it’s the only way to recurse. For completeness\nwith GNU coreutils, we also accept --recursive here.\n\n5c387428f10c2 introduces a mechanism that might have been nice to use\nhere (OPTION_ALIAS), but I didn’t use it because we would need to add\ntwo different long options, and it’s primarily there to fix a problem\nthat won’t happen anyway unless there are two similar long options.\n\nSigned-off-by: Delan Azabani <delan@azabani.com>\n---\n builtin/rm.c  |  3 ++-\n t/t3600-rm.sh | 20 ++++++++++++++++++++\n 2 files changed, 22 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex 19ce95a901..36c4cea256 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -242,7 +242,8 @@ static struct option builtin_rm_options[] = {\n \tOPT__QUIET(&quiet, N_(\"do not list removed files\")),\n \tOPT_BOOL( 0 , \"cached\",         &index_only, N_(\"only remove from the index\")),\n \tOPT__FORCE(&force, N_(\"override the up-to-date check\"), PARSE_OPT_NOCOMPLETE),\n-\tOPT_BOOL('r', NULL,             &recursive,  N_(\"allow recursive removal\")),\n+\tOPT_BOOL_F('R', NULL,           &recursive,  N_(\"allow recursive removal\"), PARSE_OPT_HIDDEN),\n+\tOPT_BOOL('r', \"recursive\",      &recursive,  N_(\"allow recursive removal\")),\n \tOPT_BOOL( 0 , \"ignore-unmatch\", &ignore_unmatch,\n \t\t\t\tN_(\"exit with a zero status even if nothing matched\")),\n \tOPT_END(),\ndiff --git a/t/t3600-rm.sh b/t/t3600-rm.sh\nindex 66282a720e..b2ddbba83c 100755\n--- a/t/t3600-rm.sh\n+++ b/t/t3600-rm.sh\n@@ -212,6 +212,26 @@ test_expect_success 'Recursive with -r -f' '\n \ttest_path_is_missing frotz\n '\n \n+test_expect_success 'Recursive with -R' '\n+\tmkdir -p frotz &&\n+\ttouch frotz/R &&\n+\tgit add frotz &&\n+\tgit commit -m R &&\n+\tgit rm -R frotz &&\n+\ttest_path_is_missing frotz/R &&\n+\ttest_path_is_missing frotz\n+'\n+\n+test_expect_success 'Recursive with --recursive' '\n+\tmkdir -p frotz &&\n+\ttouch frotz/recursive &&\n+\tgit add frotz &&\n+\tgit commit -m recursive &&\n+\tgit rm --recursive frotz &&\n+\ttest_path_is_missing frotz/recursive &&\n+\ttest_path_is_missing frotz\n+'\n+\n test_expect_success 'Remove nonexistent file returns nonzero exit status' '\n \ttest_must_fail git rm nonexistent\n '\n-- \n2.19.2\n\n"}]}