Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 416348

Summary: Double star pattern in gitignore is not handled correctly
Product: [Technology] JGit Reporter: Andrey Loskutov <loskutov>
Component: JGitAssignee: Project Inbox <egit.core-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: a.krey, david.humeniuk, florianskarten, hendy, matthias.sohn, olim, ovrabec, robin, sanders.philip
Version: 3.1Keywords: helpwanted
Target Milestone: 3.6   
Hardware: All   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=440732
Whiteboard:
Bug Depends on:    
Bug Blocks: 439447    
Attachments:
Description Flags
Trial mod to handle ** none

Description Andrey Loskutov CLA 2013-09-02 07:48:33 EDT
According to [1], command line git supports ** patterns in .gitignore files, but jgit seems not to support it (or supports only partially).

To reproduce, use git 1.8.4 or newer.

AS IS:

1 Create a repository with folder "firstProject/a/b/generated" and add few files/directories there.
2 Create .gitignore file at the firstProject directory with following content:
-----------
**/a/**/generated/
-----------
3 run "git status" or "jgit status"

Git reports no untracked files at all, jgit reports every file under firstProject/a/b/generated/ as "untracked"

Interestingly, jgit seems partially support ** pattern:

changing the pattern above to 
-----------
a/**/generated/
-----------

or 

-----------
**a/**/generated/
-----------

"fixes" the jgit problem. BTW the last example is not equivalent to the original ignore, as "firstProject/a/" is now marked as untracked by command line git (but not by jgit!).

Additionally, if we move the .gitignore file is located up to the repository root, jgit behavior changes so that **/a/**/generated/ pattern works but a/**/generated/ pattern doesn't work anymore. Command line git again works as expected.

TO BE:

Please add *full* support for ** pattern in gitignore files, independently where they are located.

P.S.


[1] http://git-blame.blogspot.de/2013/08/git-184.html
Comment 1 Andrey Loskutov CLA 2013-09-02 07:54:02 EDT
Small correction: I've used command line git 1.8.2 and not 1.8.4 (looks like ** pattern was supported even before 1.8.4, but I found only the referenced page with mention of ** pattern).
Comment 2 Andreas Krey CLA 2013-09-02 08:53:54 EDT
To make that more concise: jgit interprets a ** in a .gitignore pattern just like single * (so **/gen/**/ignore is treated the same as */gen/*/ignore).

But C git does do this differently since 1.8.2, and it would be expected that jgit follows C git's behaviour. ** there means zero or more directories, and is valid only with a / following and either at the start of a pattern of with a preceeding slash, so '**ab/cd' or similar isn't valid and currently does the same as '*ab/cd'.

A fix, well, actually following C git, would be much appreciated.
Comment 3 Andreas Krey CLA 2013-10-22 05:33:18 EDT
Created attachment 236755 [details]
Trial mod to handle **

I've done a trial to get the /**/ pattern recognized, but what (little) I did so far has some unexpected effects. I can't yet claim to understand that code, and I'd like some pointers how to implement this.

What happens now is that with **/gen/**/ignore in .gitignore of all the files

#       a/b/c/gen/e/f/g/ignore
#       a/b/c/gen/e/f/ignore
#       a/b/c/gen/e/ignore
#       a/b/c/gen/ignore
#       a/b/gen/e/f/g/ignore
#       a/b/gen/e/f/ignore
#       a/b/gen/e/ignore
#       a/b/gen/ignore
#       a/gen/e/f/g/ignore
#       a/gen/e/f/ignore
#       a/gen/e/ignore
#       a/gen/ignore
#       ab/c/gen/e/f/g/ignore
#       ab/c/gen/e/f/ignore
#       ab/c/gen/e/ignore
#       ab/c/gen/ignore
#       abc/gen/e/f/g/ignore
#       abc/gen/e/f/ignore
#       abc/gen/e/ignore
#       abc/gen/ignore
#       gen/e/f/g/ignore
#       gen/e/f/ignore
#       gen/e/ignore
#       gen/ignore

only the last one (gen/ignore) does not get ignored, which is the only one where both ** match an empty list of path components, and I don't understand yet how I manage to cause that action at a distance. (I would expect it to miss any case where either **/ matches an empty string, not just the case where both are empty.)
Comment 4 Andreas Krey CLA 2013-10-22 07:45:15 EDT
(In reply to Andreas Krey from comment #3)
...
> yet how I manage to cause that action at a distance. (I would expect it to
> miss any case where either **/ matches an empty string, not just the case
> where both are empty.)

Self-update: Actually, the 'gen/' part is ignored completely, the **/gen/**/ignore matches everything that ends in '/ignore'.
Comment 5 Robin Stocker CLA 2013-10-27 18:24:18 EDT
Hey Andreas, nice that you're looking into this. I would recommend adding your list of test cases to FileNameMatcherTest (including tests that should not match) and then working out the solution. Isolate the cases that don't yet work and debug them to find out why. (Not sure if you're already doing this.)

If you shared the test code, others could to take a look at it, but it might spoil the fun of puzzling it out ;).

I also put the original author of this (Florian Köberle) on CC, but I'm not sure if he's still active.
Comment 6 Robin Stocker CLA 2014-01-25 08:33:29 EST
Andreas: Any updates on this?
Comment 7 Robin Rosenberg CLA 2014-02-07 17:32:47 EST
*** Bug 427713 has been marked as a duplicate of this bug. ***
Comment 8 Andrey Loskutov CLA 2014-08-11 03:29:38 EDT
Gerrit review (proposal, not! final version): https://git.eclipse.org/r/31366
Comment 9 Robin Stocker CLA 2014-10-21 06:09:49 EDT
*** Bug 439447 has been marked as a duplicate of this bug. ***
Comment 10 Matthias Sohn CLA 2014-10-27 14:39:04 EDT
(In reply to Andrey Loskutov from comment #8)
> Gerrit review (proposal, not! final version): https://git.eclipse.org/r/31366

merged as 2f5a08798eb29e8141c452c0dc2622bc8fe90dd0
Comment 11 Andrey Loskutov CLA 2015-02-07 17:45:31 EST
*** Bug 456852 has been marked as a duplicate of this bug. ***