git-clean: Fix error message if clean.requireForce is not set.
PATCH 1/1 git-clean: Fix error message if clean.requireForce is not set.
It was distracting to see this error message:
clean.requireForce set and -n or -f not given; refusing to clean
even though clean.requireForce was not set at all. This patch distinguishes the cases and gives a different message depending on whether the configuration variable is not set or set to true.
While we are here, we also divert the error messages to stderr.
--- git-clean.sh | 24 +++++++++++++++--------- 1 files changed, 15 insertions(+), 9 deletions(-)
git-clean.sh +15 -9
@@ -25,10 +25,7 @@ rmrf="rm -rf --" rm_refuse="echo Not removing" echo1="echo" -# requireForce used to default to false but now it defaults to true. -# IOW, lack of explicit "clean.requireForce = false" is taken as -# "clean.requireForce = true". -disabled=$(git config --bool clean.requireForce || echo true) +disabled=$(git config --bool clean.requireForce) while test $# != 0 do
@@ -37,10 +34,10 @@ do cleandir=1 ;; -f) - disabled= + disabled=false ;; -n) - disabled= + disabled=false rmf="echo Would remove" rmrf="echo Would remove" rm_refuse="echo Would not remove"
@@ -68,10 +65,19 @@ do shift done -if [ "$disabled" = true ]; then - echo "clean.requireForce set and -n or -f not given; refusing to clean" +# requireForce used to default to false but now it defaults to true. +# IOW, lack of explicit "clean.requireForce = false" is taken as +# "clean.requireForce = true". +case "$disabled" in +"") + echo >&2 "clean.requireForce not set and -n or -f not given; refusing to clean" exit 1 -fi + ;; +"true") + echo >&2 "clean.requireForce set and -n or -f not given; refusing to clean" + exit 1 + ;; +esac case "$ignored,$ignoredonly" in 1,1) usage;;
Signature · 1 line
1.5.3.5.1368.g3cabf
Quoted 8 lines · Johannes Sixt
It was distracting to see this error message:
clean.requireForce set and -n or -f not given; refusing to clean
even though clean.requireForce was not set at all. This patch distinguishes
the cases and gives a different message depending on whether the configuration variable is not set or set to true.
Note that your patch won't apply to next as is :)
Signature · 3 lines
·O· Pierre Habouzit ··O [email protected] OOO http://www.madism.org
Quoted 10 lines · Pierre Habouzit
Quoted 7 lines · Johannes Sixt
It was distracting to see this error message:
clean.requireForce set and -n or -f not given; refusing to clean
even though clean.requireForce was not set at all. This patch distinguishes the cases and gives a different message depending on whether the configuration variable is not set or set to true.
Note that your patch won't apply to next as is :)
You mean because of the builtinification of git-clean? I was hoping that Shawn (Bohrer) is listening and will update his patch. ;) It has the same problem.
-- Hannes
Quoted 10 lines · Johannes Sixt
Quoted 9 lines · Pierre Habouzit
Quoted 8 lines · Johannes Sixt
It was distracting to see this error message:
clean.requireForce set and -n or -f not given; refusing to clean
even though clean.requireForce was not set at all. This patch distinguishes
the cases and gives a different message depending on whether the configuration variable is not set or set to true.
Quoted 5 lines
Quoted 1 line
Note that your patch won't apply to next as is :)
You mean because of the builtinification of git-clean? I was hoping that Shawn (Bohrer) is listening and will update his patch. ;) It has the same problem.
No, afaict the builtin git-clean isn't in next yet. Though the
git-rev-parse --parseopt-ification is :)
Signature · 3 lines
·O· Pierre Habouzit ··O [email protected] OOO http://www.madism.org
Quoted 7 lines · Johannes Sixt
It was distracting to see this error message:
clean.requireForce set and -n or -f not given; refusing to clean
even though clean.requireForce was not set at all. This patch distinguishes the cases and gives a different message depending on whether the configuration variable is not set or set to true.
And this will be the counterpart for 'pu'...
---
builtin-clean.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)
builtin-clean.c +9 -3
@@ -11,7 +11,7 @@#include "dir.h" #include "parse-options.h" -static int force; +static int force =-1 ;/* unset */ static const char *const builtin_clean_usage[] = {"git-clean [-d] [-f] [-n] [-q] [-x | -X] [--] <paths>..." ,
@@ -29,7 +29,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) {int j;int show_only =0 , remove_directories =0 , quiet =0 , ignored =0 ; -int ignored_only =0 , baselen =0 ; +int ignored_only =0 , baselen =0 , config_set =0 ;struct strbuf directory;struct dir_struct dir;const char *path, *base;
@@ -49,6 +49,11 @@ int cmd_clean(int argc, const char **argv, const char *prefix)git_config (git_clean_config); argc =parse_options (argc, argv, options, builtin_clean_usage,0 ); +if (force <0 ) + force =0 ; +else + config_set =1 ; +memset (&dir,0 ,sizeof (dir));if (ignored_only) { dir.show_ignored =1 ;
@@ -59,7 +64,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)die ("-x and -X cannot be used together" );if (!show_only && !force) -die ("clean.requireForce set and -n or -f not given; refusing to clean" ); +die ("clean.requireForce%s set and -n or -f not given; " +"refusing to clean" , config_set ?"" :" not" ); dir.show_other_directories =1 ;