From: Alexander Kuleshov <kuleshovmail@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>,
Alexander Kuleshov <kuleshovmail@gmail.com>
Subject: [PATCH RFC 1/3] add: add new --exclude option to git add
Date: Sun, 15 Mar 2015 19:49:59 +0600 [thread overview]
Message-ID: <1426427399-22423-1-git-send-email-kuleshovmail@gmail.com> (raw)
This patch introduces new --exclude option for the git add
command.
We already have core.excludesfile configuration variable which indicates
a path to file which contains patterns to exclude. This patch provides
ability to pass --exclude option to the git add command to exclude paths
from command line in addition to which found in the ignore files.
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
builtin/add.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/builtin/add.c b/builtin/add.c
index 3390933..5c602a6 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -244,6 +244,16 @@ static int ignore_removal_cb(const struct option *opt, const char *arg, int unse
return 0;
}
+struct string_list exclude_list = STRING_LIST_INIT_NODUP;
+struct exclude_list *el;
+
+static int exclude_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct string_list *exclude_list = opt->value;
+ string_list_append(exclude_list, arg);
+ return 0;
+}
+
static struct option builtin_add_options[] = {
OPT__DRY_RUN(&show_only, N_("dry run")),
OPT__VERBOSE(&verbose, N_("be verbose")),
@@ -255,6 +265,9 @@ static struct option builtin_add_options[] = {
OPT_BOOL('u', "update", &take_worktree_changes, N_("update tracked files")),
OPT_BOOL('N', "intent-to-add", &intent_to_add, N_("record only the fact that the path will be added later")),
OPT_BOOL('A', "all", &addremove_explicit, N_("add changes from all tracked and untracked files")),
+ { OPTION_CALLBACK, 0, "exclude", &exclude_list, N_("pattern"),
+ N_("do no add files matching pattern to index"),
+ 0, exclude_cb },
{ OPTION_CALLBACK, 0, "ignore-removal", &addremove_explicit,
NULL /* takes no arguments */,
N_("ignore paths removed in the working tree (same as --no-all)"),
@@ -298,6 +311,7 @@ static int add_files(struct dir_struct *dir, int flags)
int cmd_add(int argc, const char **argv, const char *prefix)
{
+ int i;
int exit_status = 0;
struct pathspec pathspec;
struct dir_struct dir;
@@ -381,6 +395,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
if (!ignored_too) {
dir.flags |= DIR_COLLECT_IGNORED;
setup_standard_excludes(&dir);
+
+ el = add_exclude_list(&dir, EXC_CMDL, "--exclude option");
+ for (i = 0; i < exclude_list.nr; i++)
+ add_exclude(exclude_list.items[i].string, "", 0, el, -(i+1));
+
}
memset(&empty_pathspec, 0, sizeof(empty_pathspec));
@@ -446,5 +465,6 @@ finish:
die(_("Unable to write new index file"));
}
+ string_list_clear(&exclude_list, 0);
return exit_status;
}
--
2.3.3.472.g20ceeac
next reply other threads:[~2015-03-15 13:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-15 13:49 Alexander Kuleshov [this message]
2015-03-15 13:50 ` [PATCH 2/3] Documentation/git-add.txt: describe --exclude option Alexander Kuleshov
2015-03-15 18:14 ` Eric Sunshine
2015-03-15 13:50 ` [PATCH 3/3] t3700-add: added test for " Alexander Kuleshov
2015-03-15 18:00 ` Torsten Bögershausen
2015-03-15 18:18 ` Eric Sunshine
2015-03-15 17:39 ` [PATCH RFC 1/3] add: add new --exclude option to git add Philip Oakley
2015-03-15 17:51 ` Torsten Bögershausen
2015-03-15 18:00 ` Alexander Kuleshov
2015-03-16 6:38 ` Torsten Bögershausen
2015-03-15 18:03 ` Torsten Bögershausen
2015-03-15 18:12 ` Eric Sunshine
2015-03-15 20:09 ` Junio C Hamano
2015-03-15 21:12 ` Philip Oakley
2015-03-15 21:50 ` Junio C Hamano
2015-03-16 7:11 ` Alexander Kuleshov
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=1426427399-22423-1-git-send-email-kuleshovmail@gmail.com \
--to=kuleshovmail@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).