Add -e/--exclude to git-clean.
With the -e/--exclude option for git-clean, a user can specify files that they haven't yet told git about, but either need for a short amount of time or plan to tell git about them later. This allows one to still use git-clean while these files are around without losing data. Signed-off-by: Jared Hance <jaredhance@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jared Hance committed
Jul 20, 2010 at 15:35 UTC
07de4eba60cdf1b24f297ce2b2816d3403323352
2 files changed
+23
-2
Documentation/git-clean.txt
+7
-1
@@ -8,7 +8,7 @@ git-clean - Remove untracked files from the working tree
8
SYNOPSIS
9
--------
10
[verse]
11
-'git clean' [-d] [-f] [-n] [-q] [-x | -X] [--] <path>...
11
+'git clean' [-d] [-f] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>...
12
13
DESCRIPTION
14
-----------
@@ -45,6 +45,12 @@ OPTIONS
45
Be quiet, only report errors, but not the files that are
46
successfully removed.
47
48
+-e <pattern>::
49
+--exclude=<pattern>::
50
+ Specify special exceptions to not be cleaned. Each <pattern> is
51
+ the same form as in $GIT_DIR/info/excludes and this option can be
52
+ given multiple times.
53
+
54
-x::
55
Don't use the ignore rules. This allows removing all untracked
56
files, including build products. This can be used (possibly in
builtin/clean.c
+16
-1
@@ -10,12 +10,13 @@
10
#include "cache.h"
11
#include "dir.h"
12
#include "parse-options.h"
13
+#include "string-list.h"
14
#include "quote.h"
15
16
static int force = -1; /* unset */
17
18
static const char *const builtin_clean_usage[] = {
18
- "git clean [-d] [-f] [-n] [-q] [-x | -X] [--] <paths>...",
19
+ "git clean [-d] [-f] [-n] [-q] [-e <pattern>] [-x | -X] [--] <paths>...",
20
NULL
21
};
22
@@ -26,6 +27,13 @@ static int git_clean_config(const char *var, const char *value, void *cb)
27
return git_default_config(var, value, cb);
28
}
29
30
+static int exclude_cb(const struct option *opt, const char *arg, int unset)
31
+{
32
+ struct string_list *exclude_list = opt->value;
33
+ string_list_append(exclude_list, arg);
34
+ return 0;
35
+}
36
+
37
int cmd_clean(int argc, const char **argv, const char *prefix)
38
{
39
int i;
@@ -36,6 +44,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
44
struct dir_struct dir;
45
static const char **pathspec;
46
struct strbuf buf = STRBUF_INIT;
47
+ struct string_list exclude_list = { NULL, 0, 0, 0 };
48
const char *qname;
49
char *seen = NULL;
50
struct option options[] = {
@@ -44,6 +53,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
53
OPT_BOOLEAN('f', "force", &force, "force"),
54
OPT_BOOLEAN('d', NULL, &remove_directories,
55
"remove whole directories"),
56
+ { OPTION_CALLBACK, 'e', "exclude", &exclude_list, "pattern",
57
+ "exclude <pattern>", PARSE_OPT_NONEG, exclude_cb },
58
OPT_BOOLEAN('x', NULL, &ignored, "remove ignored files, too"),
59
OPT_BOOLEAN('X', NULL, &ignored_only,
60
"remove only ignored files"),
@@ -81,6 +92,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
92
if (!ignored)
93
setup_standard_excludes(&dir);
94
95
+ for (i = 0; i < exclude_list.nr; i++)
96
+ add_exclude(exclude_list.items[i].string, "", 0, dir.exclude_list);
97
+
98
pathspec = get_pathspec(prefix, argv);
99
100
fill_directory(&dir, pathspec);
@@ -167,5 +181,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
181
free(seen);
182
183
strbuf_release(&directory);
184
+ string_list_clear(&exclude_list, 0);
185
return (errors != 0);
186
}