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 specified in the ignore files.
This option can be useful in a case when we have a directory with some *.ext files which have changes and we want to commit all files besides one for now. It can be too annoying to touch .gitignore for this. Helped-by: Eric Sunshine <sunsh...@sunshineco.com> Helped-by: Torsten Bögershausen <tbo...@web.de> Helped-by: Philip Oakley <philipoak...@iee.org> Signed-off-by: Alexander Kuleshov <kuleshovm...@gmail.com> --- builtin/add.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/builtin/add.c b/builtin/add.c index 3390933..e165fbc 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -244,6 +244,8 @@ static int ignore_removal_cb(const struct option *opt, const char *arg, int unse return 0; } +static struct string_list exclude_list = STRING_LIST_INIT_NODUP; + static struct option builtin_add_options[] = { OPT__DRY_RUN(&show_only, N_("dry run")), OPT__VERBOSE(&verbose, N_("be verbose")), @@ -255,6 +257,8 @@ 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")), + OPT_STRING_LIST(0, "exclude", &exclude_list, N_("pattern"), + N_("do not add files matching pattern to index")), { OPTION_CALLBACK, 0, "ignore-removal", &addremove_explicit, NULL /* takes no arguments */, N_("ignore paths removed in the working tree (same as --no-all)"), @@ -305,6 +309,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) int add_new_files; int require_pathspec; char *seen = NULL; + struct exclude_list *el; git_config(add_config, NULL); @@ -379,8 +384,14 @@ int cmd_add(int argc, const char **argv, const char *prefix) /* Set up the default git porcelain excludes */ memset(&dir, 0, sizeof(dir)); if (!ignored_too) { + int i; 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 +457,6 @@ finish: die(_("Unable to write new index file")); } + string_list_clear(&exclude_list, 0); return exit_status; } -- 2.3.3.472.g20ceeac.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html