Re: git ignore

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: git ignore

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:47

Linus Torvalds [off-list ref] writes:
On Tue, 16 Dec 2008, Max Power wrote:
quoted
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

[PATCH] test overlapping ignore patterns

From: Michael J Gruber <hidden>
Date: 2016-06-15 22:45:47

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 <redacted>
---
 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

Re: [PATCH] test overlapping ignore patterns

From: Stephen Haberman <hidden>
Date: 2016-06-15 22:51:33

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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help