@matheusbsbs / matheus-bagliano / commits / 625db1b753
Fork 0

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. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Nov 12, 2007 at 21:13 UTC 625db1b7530b621f32b0ef1ef502a09a05872f5d
1 file changed +9 -3
builtin-clean.c
+9 -3
@@ -11,7 +11,7 @@
11 #include "dir.h"
12 #include "parse-options.h"
13
14 -static int force;
14 +static int force = -1; /* unset */
15
16 static const char *const builtin_clean_usage[] = {
17 "git-clean [-d] [-f] [-n] [-q] [-x | -X] [--] <paths>...",
@@ -29,7 +29,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
29 {
30 int j;
31 int show_only = 0, remove_directories = 0, quiet = 0, ignored = 0;
32 - int ignored_only = 0, baselen = 0;
32 + int ignored_only = 0, baselen = 0, config_set = 0;
33 struct strbuf directory;
34 struct dir_struct dir;
35 const char *path, *base;
@@ -47,6 +47,11 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
47 };
48
49 git_config(git_clean_config);
50 + if (force < 0)
51 + force = 0;
52 + else
53 + config_set = 1;
54 +
55 argc = parse_options(argc, argv, options, builtin_clean_usage, 0);
56
57 memset(&dir, 0, sizeof(dir));
@@ -59,7 +64,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
64 die("-x and -X cannot be used together");
65
66 if (!show_only && !force)
62 - die("clean.requireForce set and -n or -f not given; refusing to clean");
67 + die("clean.requireForce%s set and -n or -f not given; "
68 + "refusing to clean", config_set ? "" : " not");
69
70 dir.show_other_directories = 1;
71