-
Notifications
You must be signed in to change notification settings - Fork 717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gitignore has different behavior to git's gitignore #108
Comments
#107 Pretty sure that this should fix it. |
@ZerGo0 cool, do you plan a new release in near future with this fix? |
I submitted it as a pull request, it's up to the maintainers here to merge it, it's a 1 line change. |
@ZerGo0 ah okay, sorry. i thought you are one of the maintainers. This is maybe off-topic, but do you know how I can apply your patch to the dependency in the go mod file? I would like to test it with my code |
That's pretty simple, navigate to your GOPATH:
Then just navigate to %GOPATH%\src\github.com\go-git\go-git\plumbing\format\gitignore\pattern.go and then change the line as shown in the pull request: https://github.com/go-git/go-git/pull/107/files |
the path doesn't exist on my machine. My project is managed with go.mod. I tried using
but with this change, the error persists |
@ZerGo0 I've successfully tested your code and I can say it doesn't work. When entering the SimpleMatch function I have the following variables:
In git this would match on the file foo.tar.gz and it would get excluded. Instead it returns false and there is no match for it. |
@ZerGo0 I mean, what your fix is doing is actually just replacing linebreaks, so what has this to do with the issue stated here? :D |
I know that in your test you only have 1 line, but if your .gitignore file has more than 1 line then it seems like it doesn't take into account that behind each line is a linebreak. This results in a false for the SimpleMatch function since Edit: These issues are probably related to each other, I haven't done a lot of debugging since I wanted to get some own stuff working first and this did the job just fine for me. All patterns should probably be filtered right when they get saved in the variable instead of each pattern match function. |
@ZerGo0 ah thanks for your explanation. As for my use case: I don't have a gitignore file I pass the pattern directly as string. So there should be no newline or \n character. The problem is that go-git uses a simple So actually to match |
I've also hit this issue. Before I found this issue, I wrote a test to check whether something wasn't working right (having checked the compatibility matrix which says that gitignore is compatible). Here it is, in case it's useful in a PR:
|
I've tested the above with the latest master, it still doesn't work, although |
Short note: If you are just looking for a gitignore implementation that behaves exactly like the git one, have a look on my go-pathspec package: https://github.com/shibumi/go-pathspec It's a fork of the old go-pathspec package. I am cleaning it up right now and it fulfills my desired test cases |
We have also run into this issue, wondering if we have workaround already? |
Because go-git doesn't handle .gitignore well (go-git/go-git#108), gut will preferably use git rather than go-git if it's installed
@pjbgf not sure when it was fixed, but I'm pretty sure this works correctly now |
@AriehSchneier thanks for the heads-up. I ran the test provided by @mrpotes above and it worked fine, so I will be closing this issue. |
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 useparse.go
to exclude theparse.go
file. This is not the case for go-git's gitignore. If I just specifyparse.go
it will not match on an absolute path likeinternal/util/parse.go
or/tmp/internal/util/parse.go
.You can verify this behavior via:
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:
This should actually match (like in the real gitignore), and the path should get excluded.
The text was updated successfully, but these errors were encountered: