Merge branch 'jc/typebreak'
[gitweb.git] / builtin-clean.c
index 55658e742fb0b8d23b9aa140c1d9cabeddd4b3d9..56ae4eb9bb4efad179f7d664880457535bd6048f 100644 (file)
@@ -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>...",
@@ -22,14 +22,14 @@ static int git_clean_config(const char *var, const char *value)
 {
        if (!strcmp(var, "clean.requireforce"))
                force = !git_config_bool(var, value);
-       return 0;
+       return git_default_config(var, value);
 }
 
 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;
@@ -47,29 +47,28 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
        };
 
        git_config(git_clean_config);
+       if (force < 0)
+               force = 0;
+       else
+               config_set = 1;
+
        argc = parse_options(argc, argv, options, builtin_clean_usage, 0);
 
        memset(&dir, 0, sizeof(dir));
-       if (ignored_only) {
-               dir.show_ignored =1;
-               dir.exclude_per_dir = ".gitignore";
-       }
+       if (ignored_only)
+               dir.show_ignored = 1;
 
        if (ignored && ignored_only)
                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;
 
-       if (!ignored) {
-               dir.exclude_per_dir = ".gitignore";
-               if (!access(git_path("info/exclude"), F_OK)) {
-                       char *exclude_path = git_path("info/exclude");
-                       add_excludes_from_file(&dir, exclude_path);
-               }
-       }
+       if (!ignored)
+               setup_standard_excludes(&dir);
 
        pathspec = get_pathspec(prefix, argv);
        read_cache();