Bug 580381 - .git/info/exclude wrongly takes precedence over root .gitignore for nested files
Summary: .git/info/exclude wrongly takes precedence over root .gitignore for nested files
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 6.2   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: 6.3   Edit
Assignee: Thomas Wolf CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-07-14 21:25 EDT by Matus Faro CLA
Modified: 2022-07-16 04:24 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matus Faro CLA 2022-07-14 21:25:14 EDT
SUMMARY:

The order of precedence is incorrect and does not match git's documentation:
https://git-scm.com/docs/gitignore

Specifically, the .git/info/exclude should have a lower precedence over any .gitignore files. However this is not the case when a .gitignore file is present under a directory inside a repo.

SETUP:

mydir/myfile:
"""
This is my test file
"""

.git/info/exclude:
"""
mydir/myfile
"""

.gitignore
"""
!mydir/myfile
"""

EXPECTED:

myfile should not be ignored

ACTUAL:

myfile is ignored

LIKELY PROBLEM:

WorkingTreeIterator.RootIgnoreNode.load():

In this method, we load the CWD's ".gitignore" file, then the "exclude" file(s) which seems reasonable. However, in WorkingTreeIterator, we check the IgnoreNode for the current path (mydir/), then the parent's IgnoreNode (.) causing this sequence of precedence from highest to lowest:

mydir/.gitignore
.git/info/exclude (Wrong, should not be checked now)
.gitignore
.git/info/exclude
Comment 1 Thomas Wolf CLA 2022-07-15 11:52:57 EDT
I can confirm this bug, but the "likely problem" is off. (There is not even a "mydir/.gitignore" in the test setup.)

JGit correctly loads and considers the info/exclude only once.

The problem is that inside RootIgnoreNode, it appends all rules to the same list. It behaves as if there was no info/exclude but only a single .gitignore with entries

  !mydir/myfile
  mydir/myfile

and ends up ignoring the file. This needs to be split really into different nodes in a hierarchy.
Comment 2 Eclipse Genie CLA 2022-07-15 15:01:23 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/194738