rm: accept -R and --recursive in addition to -r
PATCH 1/1 rm: accept -R and --recursive in addition to -r
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 <[email protected]>
--- builtin/rm.c | 3 ++- t/t3600-rm.sh | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)
builtin/rm.c +2 -1
@@ -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(),
t/t3600-rm.sh +20 -0
@@ -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 '
Signature · 1 line
2.19.2