Skip to content

gitignore has different behavior to git's gitignore #108

@shibumi

Description

@shibumi

Hi,
I don't know if you are aware of this, but the gitignore implementation is slightly different to the original gitignore implementation regarding absolute paths.

Imagine I have a repository and I have the following filepath internal/util/parse.go. In the original gitignore file I can just use parse.go to exclude the parse.go file. This is not the case for go-git's gitignore. If I just specify parse.go it will not match on an absolute path like internal/util/parse.go or /tmp/internal/util/parse.go.

You can verify this behavior via:

mkdir -p /tmp/test/internal/util
touch /tmp/test/internal/util/parse.go
cd /tmp/test/
git init
echo "parse.go" > .gitignore

If you check the status of the repository via git status you will see, that the parse.go file in /tmp/test/internal/util/parse.go is being excluded.

This is not the case for go-git. For example in our project: https://github.com/in-toto/in-toto-golang/blob/92c7c374bb0f3b9b55c54c20bc933b9be94d8477/in_toto/runlib.go#L77

We are using the gitignore matcher and we try to match on the following:

// path = "/tmp/in_toto_test_dir711641952/foo.tar.gz
// regex is: "foo.tar.gz"
match := m.Match([]string{path}, fileInfo.IsDir())

This should actually match (like in the real gitignore), and the path should get excluded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions