git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3 v2] add: introduce new --exclude option
@ 2015-03-15 19:06 Alexander Kuleshov
  2015-03-15 19:06 ` [PATCH 2/3 v2] Documentation/git-add.txt: describe " Alexander Kuleshov
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Alexander Kuleshov @ 2015-03-15 19:06 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org, Alexander Kuleshov

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 <sunshine@sunshineco.com>
Helped-by: Torsten Bögershausen <tboegi@web.de>
Helped-by: Philip Oakley <philipoakley@iee.org>
Signed-off-by: Alexander Kuleshov <kuleshovmail@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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3 v2] Documentation/git-add.txt: describe --exclude option
  2015-03-15 19:06 [PATCH 1/3 v2] add: introduce new --exclude option Alexander Kuleshov
@ 2015-03-15 19:06 ` Alexander Kuleshov
  2015-03-16  0:36   ` Eric Sunshine
  2015-03-15 19:07 ` [PATCH 3/3 v2] t3700-add: added test for " Alexander Kuleshov
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Alexander Kuleshov @ 2015-03-15 19:06 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org, Alexander Kuleshov

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
 Documentation/git-add.txt | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index f2eb907..fee97ed 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -9,7 +9,7 @@ SYNOPSIS
 --------
 [verse]
 'git add' [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p]
-	  [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]]
+	  [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]] [--exclude=<pattern>]
 	  [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing]
 	  [--] [<pathspec>...]
 
@@ -164,6 +164,10 @@ for "git add --no-all <pathspec>...", i.e. ignored removed files.
 	be ignored, no matter if they are already present in the work
 	tree or not.
 
+--exclude=<pattern>::
+	Also ignore files matching <pattern>, a .gitignore-like
+	pattern. Option can be used multiply times.
+
 \--::
 	This option can be used to separate command-line options from
 	the list of files, (useful when filenames might be mistaken
-- 
2.3.3.472.g20ceeac.dirty

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3 v2] t3700-add: added test for --exclude option
  2015-03-15 19:06 [PATCH 1/3 v2] add: introduce new --exclude option Alexander Kuleshov
  2015-03-15 19:06 ` [PATCH 2/3 v2] Documentation/git-add.txt: describe " Alexander Kuleshov
@ 2015-03-15 19:07 ` Alexander Kuleshov
  2015-03-16  0:35   ` Eric Sunshine
  2015-03-15 20:48 ` [PATCH 1/3 v2] add: introduce new " Philip Oakley
  2015-03-16  0:56 ` Eric Sunshine
  3 siblings, 1 reply; 7+ messages in thread
From: Alexander Kuleshov @ 2015-03-15 19:07 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org, Alexander Kuleshov

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
 t/t3700-add.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index f7ff1f5..6f71c67 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -332,4 +332,22 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out
 	test_i18ncmp expect.err actual.err
 '
 
+test_expect_success 'Test that "git add --exclude" works' '
+	>foo &&
+	>bar &&
+	git add --exclude=bar . &&
+	! (git ls-files | grep bar)
+	(git ls-files | grep foo)
+'
+
+test_expect_success 'Test multiply --exclude' '
+	>foo &&
+	>bar &&
+	>"b a z" &&
+	git add --exclude="bar" --exclude="b a z" . &&
+	(git ls-files | grep foo)
+	! (git ls-files | grep "b a z")
+	! (git ls-files | grep "baz")
+'
+
 test_done
-- 
2.3.3.472.g20ceeac.dirty

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3 v2] add: introduce new --exclude option
  2015-03-15 19:06 [PATCH 1/3 v2] add: introduce new --exclude option Alexander Kuleshov
  2015-03-15 19:06 ` [PATCH 2/3 v2] Documentation/git-add.txt: describe " Alexander Kuleshov
  2015-03-15 19:07 ` [PATCH 3/3 v2] t3700-add: added test for " Alexander Kuleshov
@ 2015-03-15 20:48 ` Philip Oakley
  2015-03-16  0:56 ` Eric Sunshine
  3 siblings, 0 replies; 7+ messages in thread
From: Philip Oakley @ 2015-03-15 20:48 UTC (permalink / raw)
  To: Alexander Kuleshov, Junio C Hamano; +Cc: git, Alexander Kuleshov

From: "Alexander Kuleshov" <kuleshovmail@gmail.com>
>
> Helped-by: Eric Sunshine <sunshine@sunshineco.com>
> Helped-by: Torsten Bögershausen <tboegi@web.de>
> Helped-by: Philip Oakley <philipoakley@iee.org>

While the kudo points are nice to have, I wouldn't say my minor 
contribution was worthy of the extra Helped-by.

I'd be happy for it to be dropped if you have any rewrites.

> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---
--
Philip 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3 v2] t3700-add: added test for --exclude option
  2015-03-15 19:07 ` [PATCH 3/3 v2] t3700-add: added test for " Alexander Kuleshov
@ 2015-03-16  0:35   ` Eric Sunshine
  0 siblings, 0 replies; 7+ messages in thread
From: Eric Sunshine @ 2015-03-16  0:35 UTC (permalink / raw)
  To: Alexander Kuleshov; +Cc: Junio C Hamano, git@vger.kernel.org

On Sun, Mar 15, 2015 at 3:07 PM, Alexander Kuleshov
<kuleshovmail@gmail.com> wrote:
> t3700-add: added test for --exclude option

s/added/add/

> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---
> diff --git a/t/t3700-add.sh b/t/t3700-add.sh
> index f7ff1f5..6f71c67 100755
> --- a/t/t3700-add.sh
> +++ b/t/t3700-add.sh
> @@ -332,4 +332,22 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out
>         test_i18ncmp expect.err actual.err
>  '
>
> +test_expect_success 'Test that "git add --exclude" works' '

Rather than inventing a new title style, try to match the style of the
existing tests titles in this file.

> +       >foo &&
> +       >bar &&
> +       git add --exclude=bar . &&
> +       ! (git ls-files | grep bar)

Broken &&-chain.

> +       (git ls-files | grep foo)

Unnecessary additional git-ls-files invocation. You could just save
the output to a file and then process that file.

> +'
> +
> +test_expect_success 'Test multiply --exclude' '

s/multiply/multiple/

Ditto: Match existing title style.

> +       >foo &&
> +       >bar &&
> +       >"b a z" &&
> +       git add --exclude="bar" --exclude="b a z" . &&
> +       (git ls-files | grep foo)
> +       ! (git ls-files | grep "b a z")
> +       ! (git ls-files | grep "baz")

Broken &&-chain throughout.

Ditto: Unnecessary git-ls-files invocations.

> +'
> +
>  test_done
> --
> 2.3.3.472.g20ceeac.dirty

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3 v2] Documentation/git-add.txt: describe --exclude option
  2015-03-15 19:06 ` [PATCH 2/3 v2] Documentation/git-add.txt: describe " Alexander Kuleshov
@ 2015-03-16  0:36   ` Eric Sunshine
  0 siblings, 0 replies; 7+ messages in thread
From: Eric Sunshine @ 2015-03-16  0:36 UTC (permalink / raw)
  To: Alexander Kuleshov; +Cc: Junio C Hamano, git@vger.kernel.org

On Sun, Mar 15, 2015 at 3:06 PM, Alexander Kuleshov
<kuleshovmail@gmail.com> wrote:
> Helped-by: Eric Sunshine <sunshine@sunshineco.com>
> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---
> diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
> index f2eb907..fee97ed 100644
> --- a/Documentation/git-add.txt
> +++ b/Documentation/git-add.txt
> @@ -9,7 +9,7 @@ SYNOPSIS
>  --------
>  [verse]
>  'git add' [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p]
> -         [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]]
> +         [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]] [--exclude=<pattern>]
>           [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing]
>           [--] [<pathspec>...]
>
> @@ -164,6 +164,10 @@ for "git add --no-all <pathspec>...", i.e. ignored removed files.
>         be ignored, no matter if they are already present in the work
>         tree or not.
>
> +--exclude=<pattern>::
> +       Also ignore files matching <pattern>, a .gitignore-like
> +       pattern. Option can be used multiply times.

s/multiply/multiple/

> +
>  \--::
>         This option can be used to separate command-line options from
>         the list of files, (useful when filenames might be mistaken
> --
> 2.3.3.472.g20ceeac.dirty

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3 v2] add: introduce new --exclude option
  2015-03-15 19:06 [PATCH 1/3 v2] add: introduce new --exclude option Alexander Kuleshov
                   ` (2 preceding siblings ...)
  2015-03-15 20:48 ` [PATCH 1/3 v2] add: introduce new " Philip Oakley
@ 2015-03-16  0:56 ` Eric Sunshine
  3 siblings, 0 replies; 7+ messages in thread
From: Eric Sunshine @ 2015-03-16  0:56 UTC (permalink / raw)
  To: Alexander Kuleshov; +Cc: Junio C Hamano, git@vger.kernel.org

On Sun, Mar 15, 2015 at 3:06 PM, Alexander Kuleshov
<kuleshovmail@gmail.com> wrote:
> 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.

Won't this lead to unintuitive behavior? The 'excludes' mechanism does
not unconditionally ignore; instead, it ignores _untracked_ files.
Consider file "foo" which is already tracked. Make a temporary change
to "foo" which you don't intend to commit. Since "foo" is tracked, the
command 'git add . --exclude=foo' will still add "foo" to the index,
despite the use of --exclude. Most people would probably find such
behavior surprising and undesirable.

The negative pathspec mentioned by Junio[1], on the other hand, does
not suffer this shortcoming.

More below.

[1]: http://thread.gmane.org/gmane.comp.version-control.git/265493/focus=265518

> Helped-by: Eric Sunshine <sunshine@sunshineco.com>
> Helped-by: Torsten Bögershausen <tboegi@web.de>
> Helped-by: Philip Oakley <philipoakley@iee.org>
> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---
> 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;

This variable is only used within the 'if (!ignored_too)' block below,
so its declaration should be moved there.

>         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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-03-16  0:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-15 19:06 [PATCH 1/3 v2] add: introduce new --exclude option Alexander Kuleshov
2015-03-15 19:06 ` [PATCH 2/3 v2] Documentation/git-add.txt: describe " Alexander Kuleshov
2015-03-16  0:36   ` Eric Sunshine
2015-03-15 19:07 ` [PATCH 3/3 v2] t3700-add: added test for " Alexander Kuleshov
2015-03-16  0:35   ` Eric Sunshine
2015-03-15 20:48 ` [PATCH 1/3 v2] add: introduce new " Philip Oakley
2015-03-16  0:56 ` Eric Sunshine

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).