threads / discuss / 46101

Wrong gitattributes documentation?

Subject: Wrong gitattributes documentation?

## tl;dr

4 messages between Jun 2, 2017 and Jun 3, 2017.

replies: 3people: 2as markdown or json

Rene Pasing· Jun 2, 2017, 17:12 UTC · lore
Hi all,
I have noticed a strange behaviour when using git-lfs.

If I understood correctly, git-lfs adds patterns to .gitattributes, for which git then calls lfs for any matches with this pattern.

The problem is, the documentation[1] says: "The rules how the pattern matches paths are the same as in .gitignore files; see gitignore[5].", so when I have a pattern like '/images/', it should match on all files+folders under /images, even the directory itself, right? Or when I'd use '/images/*', it should match on all files+folders under /images, right?

This does not seem to be the case. Nothing is done by lfs when using '/images/', and when using '/images/*', it only takes into account files which are directly in /images (so it doesnt take into account subdirectories).

The only solution to this (until now) is to use '/images/**/*', which seems to do exactly what I want (lfs gets executed for all files+folders under /images).

Is this expected behaviour? If yes, then the documentation of gitattributes seems incorrect to me. If not, can this be considered as a bug?

I found several complaints about this to git-lfs (or other projects relying on gitattributes), e.g. [2], but I didn't find anything about this regarding gitattributes itself.

Thanks for answers Regards Rene

PS: $ git --version
git version 2.1.4

[1] = https://git-scm.com/docs/gitattributes [2] = https://github.com/git-lfs/git-lfs/issues/2068

Junio C Hamano· Jun 3, 2017, 00:01 UTC · re: Rene Pasing · lore

Re: Wrong gitattributes documentation?

Rene Pasing <rene@pasing.net> writes:
Show 8 quoted lines
> The problem is, the documentation[1] says: "The rules how the pattern
> matches paths are the same as in .gitignore files; see gitignore[5].",
> so when I have a pattern like '/images/', it should match on all
> files+folders under /images, even the directory itself, right?
>
> Or when
> I'd use '/images/*', it should match on all files+folders under
> /images, right?

My reading of "PATTERN FORMAT" section in "git help ignore" says it shouldn't.

 - If the pattern does not contain a slash '/', Git treats it as
   a shell glob pattern and checks for a match against the
   pathname relative to the location of the `.gitignore` file
   (relative to the toplevel of the work tree if not from a
   `.gitignore` file).
 - Otherwise, Git treats the pattern as a shell glob suitable
   for consumption by fnmatch(3) with the FNM_PATHNAME flag:
   wildcards in the pattern will not match a / in the pathname.
   For example, "Documentation/{asterisk}.html" matches
   "Documentation/git.html" but not "Documentation/ppc/ppc.html"
   or "tools/perf/Documentation/perf.html".
Your "/images/*" is the "Otherwise" case, isn't it?
Rene Pasing· Jun 3, 2017, 01:10 UTC · re: Junio C Hamano · lore

Re: Wrong gitattributes documentation?

On 06/03/2017 02:01 AM, Junio C Hamano wrote:
> Your "/images/*" is the "Otherwise" case, isn't it?

Yes, true. I forgot to mention in my first mail that I also tried '/images/', which had the same (=none) effect as '/images/*', sorry about the confusion.

Rene Pasing· Jun 3, 2017, 01:20 UTC · re: Junio C Hamano · lore

Re: Wrong gitattributes documentation?

On 06/03/2017 02:01 AM, Junio C Hamano wrote:
> Your "/images/*" is the "Otherwise" case, isn't it?
Ok, sorry, didn't read your answer thoroughly enough the first time.

The problem is, when I have an entry in .gitignore like this: /images

Then git will ignore that whole directory (and all of its subfolders etc.). Git will just ignore everything in the tree starting with that pathname.

But when I use the same pattern ('/images') in .gitattributes I would expect (due to the documentation) that git-lfs will be called for all files+subfolders+subfolderfiles and even the folder itself (this is what I understand from 'The rules how the pattern matches paths are the same as in .gitignore files').

This does not seem to be the case!
Sorry again for the confusion.

← back to recent threads