Skip to content

Subrepository's gitignore negation rules overrides root repository gitignore (in some cases) #3133

@maxkorp

Description

@maxkorp

Bit of an oddball problem. I suspect #2746 Might be related. Found the issue using nodegit, but I've dug through the code and it's definitely happening at the libgit2 level.

I have a project which clones another project. We'll call them parent and child. Both being git repositories, they each have a gitignore. The parent explicitly ignores the subrepository path, without a trailing slash.

parent's gitignore (relative path to root of parent: ./.gitignore)

someSubDir/child

child's gitignore (relative path to root of parent: ./someSubDir/child/.gitignore)

/otherDir/**/*.json
!/otherDir/input/*.json

if i call git_index_add_all in the parent, using a wildcard pathspec (['*'] essentially) the entire contents of someSubDir/child/otherDir get added, unlike git add ..

Removing the negated dir in the sub repo fixes it (hence why i pointed out that PR).
Appending a / to the directory in the parent gitignore fixes it.
Removing the leading / on the child or adding one to the parent has no effect. Git cli in general ignores anything to do with the subrepo in this case. I suspect the lack of a trailing slash is the culprit here, allowing the child .gitignore to even be interpreted at all (it should just be out of the picture, if it's ignored no?)

Workaround is to get the status and add everything in the status to the index (or the pathspec). Not ideal, but it works in the meantime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions