-
Notifications
You must be signed in to change notification settings - Fork 757
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
worktree.Status()
not respecting .gitignore
#500
Comments
cc - @mcuadros |
I was trying to follow along here because I had a similar theory. package main
import "fmt"
func recurse(a []string) []string {
if len(a) == 3 {
return a
}
return recurse(append(a, "test"))
}
func main() {
a := []string{"a"}
b := recurse(a)
fmt.Println(a, b)
} My assumption was that because Go slices are pass-by-value that
The return value of append will be a slice that points to the newly allocated array. |
Please check this issue golang/go#52152 for examples. |
As suggested in the issue golang/go#52152 there is nothing that can be done from the go side. |
@acumino , I have no association with this repo, but I think a PR would be welcome. Do you have a fork with your copy-based workaround? I've run into the issue where there's a large directory (~300M of contents) that is in the .gitignore file. The worktree.Status() call takes anywhere from 1.6s (with repeated calls so that the kernel is caching the directory contents I'm guessing), to 15s, For comparison, the I'm guessing respecting the .gitignore would be a non-trivial performance improvement. |
@acumino another issue I spot on |
plumbing: gitignore, fix incorrect parsing. Fixes #500
Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
Fix of - go-git/go-git#500
* Remove deprecated `AnalyzerPlugin` * Update go-apidiff Fix of - go-git/go-git#500 * Update skaffold
* Remove deprecated `AnalyzerPlugin` * Update go-apidiff Fix of - go-git/go-git#500 * Update skaffold
It brings the fix for go-git/go-git#500
Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
plumbing: gitignore, fix incorrect parsing. Fixes go-git#500
When we have multi nested directory and the
.gitignore
file is inside that. Thewroktree.Status()
is not respectingpatterns
inside.gitignore
that can cause the git status to dirty.How to reproduce
Check this repo https://github.com/acumino/git-status. When we run
$ go run ./test.go
which is basically checking the status and returning an error ifstatus
is not clean.It throws an error and ideally it should not.
Explanation
The issue is happening because
append()
is being used for theslice
in recursion at line64
.go-git/plumbing/format/gitignore/dir.go
Lines 49 to 76 in c785af3
The passed value of
fs
is being changed with appends and is being used asdomain
herego-git/plumbing/format/gitignore/pattern.go
Line 42 in c785af3
So when this
fs
is updated next time with append it is causing overwrite to previously writtendomain
values leading to previously addedpattern
's domain to overwritten. So git status basically at the end store wrong pattern to ignore, leading to dirty git status.An explanation of how slices are passed in function and are used internally
golang
https://stackoverflow.com/questions/39993688/are-slices-passed-by-value.Solution
Instead to passing
append(path, fi.Name())
inReadPatterns()
every times a new copy of slice should be passed.The text was updated successfully, but these errors were encountered: