git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* git ignore
@ 2008-12-16 22:43 Max Power
  2008-12-16 22:53 ` Linus Torvalds
  0 siblings, 1 reply; 7+ messages in thread
From: Max Power @ 2008-12-16 22:43 UTC (permalink / raw)
  To: git


So I understand how to use the .gitignore file to ignore specific
files/directories that I put in there... is there a way to ignore everything
BUT a given file extension? 
-- 
View this message in context: http://www.nabble.com/git-ignore-tp21043430p21043430.html
Sent from the git mailing list archive at Nabble.com.

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

* Re: git ignore
  2008-12-16 22:43 git ignore Max Power
@ 2008-12-16 22:53 ` Linus Torvalds
  2008-12-16 23:08   ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Linus Torvalds @ 2008-12-16 22:53 UTC (permalink / raw)
  To: Max Power; +Cc: git



On Tue, 16 Dec 2008, Max Power wrote:
> 
> So I understand how to use the .gitignore file to ignore specific
> files/directories that I put in there... is there a way to ignore everything
> BUT a given file extension? 

Something like

	*
	!*.jpg

to only save the jpegs in your pr0n collection?

The first rule says "ignore everything". The second one says "don't 
ignore *.jpg files".

Untested. 

		Linus

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

* Re: git ignore
  2008-12-16 22:53 ` Linus Torvalds
@ 2008-12-16 23:08   ` Junio C Hamano
  2008-12-18 17:11     ` [PATCH] test overlapping ignore patterns Michael J Gruber
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2008-12-16 23:08 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Max Power, git

Linus Torvalds <torvalds@linux-foundation.org> writes:

> On Tue, 16 Dec 2008, Max Power wrote:
>> 
>> So I understand how to use the .gitignore file to ignore specific
>> files/directories that I put in there... is there a way to ignore everything
>> BUT a given file extension? 
>
> Something like
>
> 	*
> 	!*.jpg
>
> to only save the jpegs in your pr0n collection?

Hmm, do people still keep p0rn collection in jpgs?  I somehow had an
impression that they moved to avis ;-)

> The first rule says "ignore everything". The second one says "don't 
> ignore *.jpg files".
>
> Untested. 

t3001-ls-files-others-exclude.sh has some tests but there is nothing that
explicitly tests overlapping patterns.  Perhaps it should (hint, hint...)

"man gitignore" documentation has an example to ignore all *.html files
but not foo.html using a similar construct, i.e.

	*.html
        !foo.html

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

* [PATCH] test overlapping ignore patterns
  2008-12-16 23:08   ` Junio C Hamano
@ 2008-12-18 17:11     ` Michael J Gruber
  2011-07-07 18:12       ` Stephen Haberman
  0 siblings, 1 reply; 7+ messages in thread
From: Michael J Gruber @ 2008-12-18 17:11 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

Add a test which checks that negated patterns such as "!foo.html" can
override previous patterns such as "*.html". This is documented
behaviour but had not been tested so far.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 t/t3001-ls-files-others-exclude.sh |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh
index 8666946..85aef12 100755
--- a/t/t3001-ls-files-others-exclude.sh
+++ b/t/t3001-ls-files-others-exclude.sh
@@ -140,4 +140,10 @@ test_expect_success 'trailing slash in exclude forces directory match (2)' '
 
 '
 
+test_expect_success 'negated exclude matches can override previous ones' '
+
+	git ls-files --others --exclude="a.*" --exclude="!a.1" >output &&
+	grep "^a.1" output
+'
+
 test_done
-- 
1.6.1.rc1

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

* Re: [PATCH] test overlapping ignore patterns
  2008-12-18 17:11     ` [PATCH] test overlapping ignore patterns Michael J Gruber
@ 2011-07-07 18:12       ` Stephen Haberman
  2011-07-08 18:01         ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Haberman @ 2011-07-07 18:12 UTC (permalink / raw)
  To: git


> Add a test which checks that negated patterns such as "!foo.html" can 
> override previous patterns such as "*.html". This is documented 
> behaviour but had not been tested so far. 

Negated excludes with a pattern does not seem to work with sub directories,
e.g. the following test fails for me.

The file /one/two/a.1 exists, and is initially excluded by *, but not
re-included by "!*.1" (where as /a.1 is re-included).

diff --git i/t/t3001-ls-files-others-exclude.sh
w/t/t3001-ls-files-others-exclude.sh
index c8fe978..e6c86ff 100755
--- i/t/t3001-ls-files-others-exclude.sh
+++ w/t/t3001-ls-files-others-exclude.sh
@@ -175,6 +175,12 @@ test_expect_success 'negated exclude matches can
override previous ones' '
  grep "^a.1" output
 '
 
+test_expect_success 'negated exclude matches can override previous ones 2'
'
+
+ git ls-files --others --exclude="*" --exclude="!*.1" >output &&
+ grep "^one/two/a.1" output
+'
+

(Replying to this old thread via nabble; hopefully it works.)

- Stephen


--
View this message in context: http://git.661346.n2.nabble.com/git-ignore-tp1665336p6559395.html
Sent from the git mailing list archive at Nabble.com.

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

* Re: [PATCH] test overlapping ignore patterns
  2011-07-07 18:12       ` Stephen Haberman
@ 2011-07-08 18:01         ` Junio C Hamano
  2011-07-08 18:39           ` Stephen Haberman
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2011-07-08 18:01 UTC (permalink / raw)
  To: Stephen Haberman; +Cc: git

Stephen Haberman <stephen@exigencecorp.com> writes:

> +test_expect_success 'negated exclude matches can override previous ones 2'
> '
> +
> + git ls-files --others --exclude="*" --exclude="!*.1" >output &&
> + grep "^one/two/a.1" output
> +'

Does this has anything to do with "negated overrides"?

Doesn't the first "*" tells us to not to look at the contents of one/
directory at all, so we that we do not have to waste time descending into
it?  We wouldn't even know what pathnames are underneath it, so "!*.1"
would not have any effect inside one/ at all, I think.

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

* Re: [PATCH] test overlapping ignore patterns
  2011-07-08 18:01         ` Junio C Hamano
@ 2011-07-08 18:39           ` Stephen Haberman
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Haberman @ 2011-07-08 18:39 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git


> Doesn't the first "*" tells us to not to look at the contents of one/
> directory at all, so we that we do not have to waste time descending
> into it?  We wouldn't even know what pathnames are underneath it, so
> "!*.1" would not have any effect inside one/ at all, I think.

If that's the way the feature should work, that's fine.

I came across this thread via google referencing Linus's post from 2008
which mentioned versioning only jpg files. I want to do the same sort of
thing, but with a directory hierarchy.

If I say "exclude *.jpg" in my root .gitignore file, that applies into
sub directories, so I just assumed "exclude !*.jpg" would also apply to
sub directories.

Am I missing another way to accomplish this?

I understand from an implementation perspective, skipping all
subdirectories when you see "exlude *" is a smart thing to do, but
perhaps it should only be done if there are no negative excludes that
could bring items back into play?

Thanks,
Stephen

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

end of thread, other threads:[~2011-07-08 18:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-16 22:43 git ignore Max Power
2008-12-16 22:53 ` Linus Torvalds
2008-12-16 23:08   ` Junio C Hamano
2008-12-18 17:11     ` [PATCH] test overlapping ignore patterns Michael J Gruber
2011-07-07 18:12       ` Stephen Haberman
2011-07-08 18:01         ` Junio C Hamano
2011-07-08 18:39           ` Stephen Haberman

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).