git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5/5] git-add: add ignored files when asked explicitly.
@ 2006-12-25 11:13 Junio C Hamano
  2006-12-25 13:47 ` Johannes Schindelin
  0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2006-12-25 11:13 UTC (permalink / raw)
  To: git

One thing many people found confusing about git-add was that a
file whose name matches an ignored pattern could not be added to
the index.  With this, such a file can be added by explicitly
spelling its name to git-add.

Fileglobs and recursive behaviour do not add ignored files to
the index.  That is, if a pattern '*.o' is in .gitignore, and
two files foo.o, bar/baz.o are in the working tree:

    $ git add foo.o
    $ git add '*.o'
    $ git add bar

Only the first form adds foo.o to the index.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 Documentation/git-add.txt |   11 ++++++++---
 builtin-add.c             |   11 ++++++++++-
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index d86c0e7..a8ed459 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -25,8 +25,9 @@ the commit.
 The 'git status' command can be used to obtain a summary of what is included
 for the next commit.
 
-This command only adds non-ignored files, to add ignored files use
-"git update-index --add".
+This command can be used to add ignored files, but they have to be
+explicitly and exactly specified from the command line.  File globbing
+and recursive behaviour do not add ignored files.
 
 Please see gitlink:git-commit[1] for alternative ways to add content to a
 commit.
@@ -35,7 +36,11 @@ commit.
 OPTIONS
 -------
 <file>...::
-	Files to add content from.
+	Files to add content from.  Fileglobs (e.g. `*.c`) can
+	be given to add all matching files.  Also a
+	leading directory name (e.g. `dir` to add `dir/file1`
+	and `dir/file2`) can be given to add all files in the
+	directory, recursively.
 
 -n::
         Don't actually add the file(s), just show if they exist.
diff --git a/builtin-add.c b/builtin-add.c
index f306f82..389c106 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -25,7 +25,14 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
 	i = dir->nr;
 	while (--i >= 0) {
 		struct dir_entry *entry = *src++;
-		if (!match_pathspec(pathspec, entry->name, entry->len, prefix, seen)) {
+		int how = match_pathspec(pathspec, entry->name, entry->len,
+					 prefix, seen);
+		/*
+		 * ignored entries can be added with exact match,
+		 * but not with glob nor recursive.
+		 */
+		if (!how ||
+		    (entry->ignored_entry && how != MATCHED_EXACTLY)) {
 			free(entry);
 			continue;
 		}
@@ -54,6 +61,8 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)
 
 	/* Set up the default git porcelain excludes */
 	memset(dir, 0, sizeof(*dir));
+	if (pathspec)
+		dir->show_both = 1;
 	dir->exclude_per_dir = ".gitignore";
 	path = git_path("info/exclude");
 	if (!access(path, R_OK))
-- 
1.4.4.3.g50da

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

* Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.
  2006-12-25 11:13 [PATCH 5/5] git-add: add ignored files when asked explicitly Junio C Hamano
@ 2006-12-25 13:47 ` Johannes Schindelin
  2006-12-25 17:27   ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: Johannes Schindelin @ 2006-12-25 13:47 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Hi,

On Mon, 25 Dec 2006, Junio C Hamano wrote:

>     $ git add foo.o
>     $ git add '*.o'

Most people do

	$ git add *.o

instead, where bash expands the expression. Maybe this new behaviour 
should be hidden between a "-f" option?

Ciao,
Dscho

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

* Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.
  2006-12-25 13:47 ` Johannes Schindelin
@ 2006-12-25 17:27   ` Junio C Hamano
  2006-12-25 18:39     ` [PATCH] git-add: warn when adding an ignored file with an explicit request Junio C Hamano
                       ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Junio C Hamano @ 2006-12-25 17:27 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> On Mon, 25 Dec 2006, Junio C Hamano wrote:
>
>>     $ git add foo.o
>>     $ git add '*.o'
>
> Most people do
>
> 	$ git add *.o
>
> instead, where bash expands the expression. Maybe this new behaviour 
> should be hidden between a "-f" option?

When would anybody do "git add *.o"?

A more plausible situation is that you have '*.o' in .gitignore
because you do not want to keep track of object files generated
from your source, but your project needs to keep track of one
third-party object file that you do not have the source to, and
helping that situation is what this patch is about.

An alternative is to use the mechanism I added here to _detect_
the attempt to add an ignored file with explicitly spelled out
pathspec, and issue an info message that says something like:

	Path 'xyzzy/filfre.o' is not being ignored by one of
	your .gitignore files.  If you really want to add it,
	please add this entry to .gitignore file:

        !/xyzzy/filfre.o

One advantage of this is that it would help guiding the user in
the right direction, giving a reusable piece of knowledge,
without changing the behaviour of the command (what is refused
is refused).  But I can already see people's complaints: if the
tool knows how to fix that situation why forces the user to do
so?

Although the reason why the alternative does not do so is "The
user earlier said *.o files are uninteresting but came back with
a conflicting request to add xyzzy/filfre.o, which could be a
mistake.  We ask for a confirmation", which is very sensible,
another alternative would be to add the path anyway and issue an
warning, like this:

	$ ls xyzzy
        filfre.c	filfre.o
	$ git add xyzzy/filfre.?
	added ignored path xyzzy/filfre.o

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

* [PATCH] git-add: warn when adding an ignored file with an explicit request.
  2006-12-25 17:27   ` Junio C Hamano
@ 2006-12-25 18:39     ` Junio C Hamano
  2006-12-25 22:24       ` Jakub Narebski
  2006-12-25 19:57     ` [PATCH 5/5] git-add: add ignored files when asked explicitly Nicolas Pitre
                       ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2006-12-25 18:39 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git

We allow otherwise ignored paths to be added to the index by
spelling its path out on the command line, but we would warn the
user about them when we do so.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * This is on top of what I sent out last night.

 builtin-add.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/builtin-add.c b/builtin-add.c
index 822075a..c54c694 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -37,6 +37,9 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
 			free(entry);
 			continue;
 		}
+		if (entry->ignored_entry)
+			fprintf(stderr, "warning: '%s' is an ignored path.\n",
+				entry->name);
 		*dst++ = entry;
 	}
 	dir->nr = dst - dir->entries;
-- 
1.4.4.3.g71b5

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

* Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.
  2006-12-25 17:27   ` Junio C Hamano
  2006-12-25 18:39     ` [PATCH] git-add: warn when adding an ignored file with an explicit request Junio C Hamano
@ 2006-12-25 19:57     ` Nicolas Pitre
  2006-12-26 15:34     ` Johannes Schindelin
  2007-01-04 13:58     ` Andreas Ericsson
  3 siblings, 0 replies; 11+ messages in thread
From: Nicolas Pitre @ 2006-12-25 19:57 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, git

On Mon, 25 Dec 2006, Junio C Hamano wrote:

> An alternative is to use the mechanism I added here to _detect_
> the attempt to add an ignored file with explicitly spelled out
> pathspec, and issue an info message that says something like:
> 
> 	Path 'xyzzy/filfre.o' is not being ignored by one of
> 	your .gitignore files.  If you really want to add it,
> 	please add this entry to .gitignore file:
> 
>         !/xyzzy/filfre.o

What about this instead:

	Path 'xyzzy/filfre.o' should be ignored according to one of
	your .gitignore files.  If you really want to add it, you must
	use the -f flag.


Nicolas

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

* Re: [PATCH] git-add: warn when adding an ignored file with an explicit request.
  2006-12-25 18:39     ` [PATCH] git-add: warn when adding an ignored file with an explicit request Junio C Hamano
@ 2006-12-25 22:24       ` Jakub Narebski
  2006-12-26 16:19         ` Johannes Schindelin
  0 siblings, 1 reply; 11+ messages in thread
From: Jakub Narebski @ 2006-12-25 22:24 UTC (permalink / raw)
  To: git

Junio C Hamano wrote:

> We allow otherwise ignored paths to be added to the index by
> spelling its path out on the command line, but we would warn the
> user about them when we do so.

I'm for warning user that the file to be added is ignored file and
telling how to make an exception in .gitignore _AND_ that -f option
can be used to bypass that check. And adding ignored path as above
with -f option.

But otherwise: nice series of patches.

P.S. Were all the patches sent as replies to introductory letter?
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

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

* Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.
  2006-12-25 17:27   ` Junio C Hamano
  2006-12-25 18:39     ` [PATCH] git-add: warn when adding an ignored file with an explicit request Junio C Hamano
  2006-12-25 19:57     ` [PATCH 5/5] git-add: add ignored files when asked explicitly Nicolas Pitre
@ 2006-12-26 15:34     ` Johannes Schindelin
  2006-12-26 19:05       ` Junio C Hamano
  2007-01-04 13:58     ` Andreas Ericsson
  3 siblings, 1 reply; 11+ messages in thread
From: Johannes Schindelin @ 2006-12-26 15:34 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Hi,

On Mon, 25 Dec 2006, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > On Mon, 25 Dec 2006, Junio C Hamano wrote:
> >
> >>     $ git add foo.o
> >>     $ git add '*.o'
> >
> > Most people do
> >
> > 	$ git add *.o
> >
> > instead, where bash expands the expression. Maybe this new behaviour 
> > should be hidden between a "-f" option?
> 
> When would anybody do "git add *.o"?

Not exactly "git add *.o", but when I see in git-status that there are 
only a couple of files which are untracked, and I want them added, I 
lazily do "git add *".

Ciao,
Dscho

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

* Re: [PATCH] git-add: warn when adding an ignored file with an explicit request.
  2006-12-25 22:24       ` Jakub Narebski
@ 2006-12-26 16:19         ` Johannes Schindelin
  0 siblings, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2006-12-26 16:19 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git

Hi,

On Mon, 25 Dec 2006, Jakub Narebski wrote:

> P.S. Were all the patches sent as replies to introductory letter?

I actually don't like that convention at all. It makes for a _huge_ thread 
of unrelated discussions, since most of the time the series is _exactly_ 
because the patches are somewhat independent (otherwise you could not 
separate them).

Ciao,
Dscho

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

* Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.
  2006-12-26 15:34     ` Johannes Schindelin
@ 2006-12-26 19:05       ` Junio C Hamano
  2006-12-26 22:48         ` Johannes Schindelin
  0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2006-12-26 19:05 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

>> > Most people do
>> >
>> > 	$ git add *.o
>> >
>> > instead, where bash expands the expression. Maybe this new behaviour 
>> > should be hidden between a "-f" option?
>> 
>> When would anybody do "git add *.o"?
>
> Not exactly "git add *.o", but when I see in git-status that there are 
> only a couple of files which are untracked, and I want them added, I 
> lazily do "git add *".

I changed it to warn and refuse and made it only add under -f
flag.

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

* Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.
  2006-12-26 19:05       ` Junio C Hamano
@ 2006-12-26 22:48         ` Johannes Schindelin
  0 siblings, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2006-12-26 22:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Hi,

On Tue, 26 Dec 2006, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> >> > Most people do
> >> >
> >> > 	$ git add *.o
> >> >
> >> > instead, where bash expands the expression. Maybe this new behaviour 
> >> > should be hidden between a "-f" option?
> >> 
> >> When would anybody do "git add *.o"?
> >
> > Not exactly "git add *.o", but when I see in git-status that there are 
> > only a couple of files which are untracked, and I want them added, I 
> > lazily do "git add *".
> 
> I changed it to warn and refuse and made it only add under -f
> flag.

Thanks!

Ciao,
Dscho

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

* Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.
  2006-12-25 17:27   ` Junio C Hamano
                       ` (2 preceding siblings ...)
  2006-12-26 15:34     ` Johannes Schindelin
@ 2007-01-04 13:58     ` Andreas Ericsson
  3 siblings, 0 replies; 11+ messages in thread
From: Andreas Ericsson @ 2007-01-04 13:58 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, git

Junio C Hamano wrote:
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
>> On Mon, 25 Dec 2006, Junio C Hamano wrote:
>>
>>>     $ git add foo.o
>>>     $ git add '*.o'
>> Most people do
>>
>> 	$ git add *.o
>>
>> instead, where bash expands the expression. Maybe this new behaviour 
>> should be hidden between a "-f" option?
> 
> When would anybody do "git add *.o"?
> 

Make that "git add *.c" then, in a directory normally containing a lot 
of generated C-files.

> 
> An alternative is to use the mechanism I added here to _detect_
> the attempt to add an ignored file with explicitly spelled out
> pathspec, and issue an info message that says something like:
> 
> 	Path 'xyzzy/filfre.o' is not being ignored by one of
> 	your .gitignore files.  If you really want to add it,
> 	please add this entry to .gitignore file:
> 
>         !/xyzzy/filfre.o
> 

Sounds very sensible to me, although I assume you meant "path 
xyzzy/filfre.o is being ignored" (ie, "is not being ignored" (sic) was a 
typo).


> One advantage of this is that it would help guiding the user in
> the right direction, giving a reusable piece of knowledge,
> without changing the behaviour of the command (what is refused
> is refused).  But I can already see people's complaints: if the
> tool knows how to fix that situation why forces the user to do
> so?
> 
> Although the reason why the alternative does not do so is "The
> user earlier said *.o files are uninteresting but came back with
> a conflicting request to add xyzzy/filfre.o, which could be a
> mistake.  We ask for a confirmation", which is very sensible,

Very sensible indeed. If you tell a cabdriver "go-left-go-right" (very 
fast) he'll (hopefully) stop and ask you where you really wanted to go.

> another alternative would be to add the path anyway and issue an
> warning, like this:
> 
> 	$ ls xyzzy
>         filfre.c	filfre.o
> 	$ git add xyzzy/filfre.?
> 	added ignored path xyzzy/filfre.o
> 

I like the "you did something weird. Education served" option better.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

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

end of thread, other threads:[~2007-01-04 13:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-25 11:13 [PATCH 5/5] git-add: add ignored files when asked explicitly Junio C Hamano
2006-12-25 13:47 ` Johannes Schindelin
2006-12-25 17:27   ` Junio C Hamano
2006-12-25 18:39     ` [PATCH] git-add: warn when adding an ignored file with an explicit request Junio C Hamano
2006-12-25 22:24       ` Jakub Narebski
2006-12-26 16:19         ` Johannes Schindelin
2006-12-25 19:57     ` [PATCH 5/5] git-add: add ignored files when asked explicitly Nicolas Pitre
2006-12-26 15:34     ` Johannes Schindelin
2006-12-26 19:05       ` Junio C Hamano
2006-12-26 22:48         ` Johannes Schindelin
2007-01-04 13:58     ` Andreas Ericsson

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