From: James <rouzier@gmail.com>
To: git@vger.kernel.org
Cc: James Rouzier <rouzier@gmail.com>
Subject: [PATCH] clean: new option --exclude-from
Date: Thu, 26 Nov 2015 09:44:25 -0500 [thread overview]
Message-ID: <1448549065-16337-1-git-send-email-rouzier@gmail.com> (raw)
From: James Rouzier <rouzier@gmail.com>
Specify a file to read for exclude patterns.
---
Documentation/git-clean.txt | 5 ++++-
builtin/clean.c | 15 ++++++++++++++-
t/t7300-clean.sh | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt
index 641681f..ccd0aa4 100644
--- a/Documentation/git-clean.txt
+++ b/Documentation/git-clean.txt
@@ -8,7 +8,7 @@ git-clean - Remove untracked files from the working tree
SYNOPSIS
--------
[verse]
-'git clean' [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>...
+'git clean' [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [--exclude-from <file>] [-x | -X] [--] <path>...
DESCRIPTION
-----------
@@ -61,6 +61,9 @@ OPTIONS
$GIT_DIR/info/exclude, also consider these patterns to be in the
set of the ignore rules in effect.
+--exclude-from=<file>::
+ Read exclude patterns from <file>; 1 per line.
+
-x::
Don't use the standard ignore rules read from .gitignore (per
directory) and $GIT_DIR/info/exclude, but do still use the ignore
diff --git a/builtin/clean.c b/builtin/clean.c
index d7acb94..e4995a3 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -875,6 +875,16 @@ static void interactive_main_loop(void)
}
}
+static int option_parse_exclude_from(const struct option *opt,
+ const char *arg, int unset)
+{
+ struct dir_struct *dir = opt->value;
+
+ add_excludes_from_file(dir, arg);
+
+ return 0;
+}
+
int cmd_clean(int argc, const char **argv, const char *prefix)
{
int i, res;
@@ -898,11 +908,15 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
N_("remove whole directories")),
{ OPTION_CALLBACK, 'e', "exclude", &exclude_list, N_("pattern"),
N_("add <pattern> to ignore rules"), PARSE_OPT_NONEG, exclude_cb },
+ { OPTION_CALLBACK, 0, "exclude-from", &dir, N_("file"),
+ N_("exclude patterns are read from <file>"),
+ 0, option_parse_exclude_from },
OPT_BOOL('x', NULL, &ignored, N_("remove ignored files, too")),
OPT_BOOL('X', NULL, &ignored_only,
N_("remove only ignored files")),
OPT_END()
};
+ memset(&dir, 0, sizeof(dir));
git_config(git_clean_config, NULL);
if (force < 0)
@@ -913,7 +927,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, options, builtin_clean_usage,
0);
- memset(&dir, 0, sizeof(dir));
if (ignored_only)
dir.flags |= DIR_SHOW_IGNORED;
diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index 86ceb38..9b648b9 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -630,6 +630,41 @@ test_expect_success 'git clean -e' '
)
'
+test_expect_success 'git clean --exclude-from' '
+ rm -fr repo &&
+ mkdir repo &&
+ (
+ cd repo &&
+ git init &&
+ touch known 1 2 3 &&
+ git add known &&
+ echo 1 >> .git/clean-exclude &&
+ echo 2 >> .git/clean-exclude &&
+ git clean -f --exclude-from=.git/clean-exclude &&
+ test -e 1 &&
+ test -e 2 &&
+ ! (test -e 3) &&
+ test -e known
+ )
+'
+
+test_expect_success 'git clean -e --exclude-from' '
+ rm -fr repo &&
+ mkdir repo &&
+ (
+ cd repo &&
+ git init &&
+ touch known 1 2 3 &&
+ git add known &&
+ echo 1 >> .git/clean-exclude &&
+ git clean -f -e 2 --exclude-from=.git/clean-exclude &&
+ test -e 1 &&
+ test -e 2 &&
+ ! (test -e 3) &&
+ test -e known
+ )
+'
+
test_expect_success SANITY 'git clean -d with an unreadable empty directory' '
mkdir foo &&
chmod a= foo &&
--
2.3.6
next reply other threads:[~2015-11-26 14:44 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-26 14:44 James [this message]
2015-11-30 2:24 ` [PATCH] clean: new option --exclude-from Eric Sunshine
[not found] ` <CAGjXF72PgdjBw03ERVYxj+atvsBXK0LeJ6O3zTZgi3-kv9BWsw@mail.gmail.com>
2015-12-01 22:25 ` Eric Sunshine
2015-12-06 14:58 ` [PATCH v2 1/2] modernize t7300 James
2015-12-06 14:58 ` [PATCH v2 2/2] clean: new option --exclude-from James
2015-12-07 20:56 ` Jeff King
2015-12-07 21:44 ` Junio C Hamano
2015-12-07 22:53 ` Eric Sunshine
2015-12-07 21:40 ` [PATCH v2 1/2] modernize t7300 Junio C Hamano
2015-12-07 22:46 ` Eric Sunshine
2015-12-07 22:50 ` Junio C Hamano
2015-12-07 22:43 ` Eric Sunshine
2015-12-02 0:53 ` [PATCH] clean: new option --exclude-from Jeff King
2015-12-02 2:18 ` Junio C Hamano
2015-12-02 2:44 ` Jeff King
2015-12-02 16:40 ` Junio C Hamano
2015-12-02 16:47 ` Jeff King
2015-12-02 17:25 ` Junio C Hamano
2015-12-02 17:51 ` Jeff King
2015-12-06 3:51 ` Junio C Hamano
2015-12-07 19:39 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1448549065-16337-1-git-send-email-rouzier@gmail.com \
--to=rouzier@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.