Re: [PATCH] gitattributes.txt: mention exceptions to gitignore rules

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

Re: [PATCH] gitattributes.txt: mention exceptions to gitignore rules

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:50:19

Nguyễn Thái Ngọc Duy  [off-list ref] writes:
 2011/1/4 Marcin Wiśnicki [off-list ref]:
 > I think that for the time being at least the manual page must change to
 > reflect reality.

 Looks like changes will be more than just a few lines because path_matches()
 needs to learn about directories (iow less likely to get fixed right away).
 So, yes, good idea.
Not really.  I'd rather see a handful of test cases added to t0003 to help
interested parties to see what is broken and what is not.

Quoting from Marcin's other message, assuming that "Patterns" are stored
in either .gitattributes at the top level or .git/info/attributes:
Example for file: d1/d2/f1.c

Patterns that match:
  *.c
No slashes, so it should match anywhere (correct).
  d1/d2/*
With slashes, so this is anchored at the toplevel of the working tree, and
the path should match (correct).
  /d1/d2/*
The same as above;, the leading '/' is only to make it explicit that it is
anchored at the level
  */d2/*
Should match.
  */*/*
Should match.
Patterns that do not match but should:
  d2/*
This shouldn't match unless it appears in d1/.gitattributes.

The presense of '/' makes the pattern anchored to the directory it appear
in, and .git/info/attributes is taken as being at the top level.
  d2/
  d2
These shouldn't for the same reason.
  d1/d2
  /d1/d2
We somehow don't do leading path match like we do for gitignore, but I do
not think this was intended.  My gut feeling is that these should match.

The thinking back, when we wrote the code, could have been that, unlike
gitignore that maintains only one bit (either "ignored" or "not"),
attributes are richer and giving the same attribute (say "whitespace
checking criteria") to files inside a directory and the containing
directory itself was nonsensical.  But if that was the reason, it is
faulty, as we do not track directories anyway.

Wouldn't it be sufficient to teach attr.c:path_matches() that a pattern
could also match with leading path?  That would automatically cover the
case where a pattern is terminated with a slash, as pattern "d/e/" would
never match path "d/e" but does match "d/e/f"?

Re: [PATCH] gitattributes.txt: mention exceptions to gitignore rules

From: Marcin Wiśnicki <hidden>
Date: 2016-06-15 22:50:19

On Tue, 04 Jan 2011 11:17:14 -0800, Junio C Hamano wrote:
quoted
Patterns that do not match but should:
  d2/*
This shouldn't match unless it appears in d1/.gitattributes.

The presense of '/' makes the pattern anchored to the directory it
appear in, and .git/info/attributes is taken as being at the top level.
After more carefully re-reading gitignore(5) I think that now I get it.

I presume that is is not possible to match certain pattern occurring 
*anywhere* in the path.

Would it be possible to extend pattern format to include double-star 
wildcard that matches anything including slashes ?

Like: **/whatever/**

Many tools (in java at least) and libraries support such extension to 
globs. Unfortunately standard fnmatch(3) that's used by git is not one of 
them, but glibc's implementation looks portable and self-contained so it 
could be included and modified.

quoted
  d2/
  d2
These shouldn't for the same reason.
quoted
  d1/d2
  /d1/d2
We somehow don't do leading path match like we do for gitignore, but I
do not think this was intended.  My gut feeling is that these should
match.

The thinking back, when we wrote the code, could have been that, unlike
gitignore that maintains only one bit (either "ignored" or "not"),
attributes are richer and giving the same attribute (say "whitespace
checking criteria") to files inside a directory and the containing
directory itself was nonsensical.  But if that was the reason, it is
faulty, as we do not track directories anyway.

Wouldn't it be sufficient to teach attr.c:path_matches() that a pattern
could also match with leading path?  That would automatically cover the
case where a pattern is terminated with a slash, as pattern "d/e/" would
never match path "d/e" but does match "d/e/f"?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help