-
Notifications
You must be signed in to change notification settings - Fork 538
how to ignore files by global gitignore? #603
Comments
now I can understand how to parse gitconfig, get core.excludesfile. But I cannot understand how to check ignored files. my
changed file paths are only |
After some investigations, I confirmed
and looking into that,
Is it expected behavior? |
Wrote sample code to show my expected behavior, and filepath.Match() behavior. func main() {
p := gitignore.ParsePattern("tags", nil)
res := p.Match([]string{"doc/tags"}, false)
fmt.Println("expected 1 = Exclude but got 0 = NoMatch:", res)
match, _ := filepath.Match("tags", "doc/tags")
fmt.Println("this is false:", match)
} |
@mcuadros @osklyar Should I send pull request? or am I wrong? --- pattern.go 2017-09-23 12:51:41.396008300 +0900
+++ vendor/gopkg.in/src-d/go-git.v4/plumbing/format/gitignore/pattern.go 2017-09-23 12:52:39.995802400 +0900
@@ -89,7 +89,7 @@
func (p *pattern) simpleNameMatch(path []string, isDir bool) bool {
for i, name := range path {
- if match, err := filepath.Match(p.pattern[0], name); err != nil {
+ if match, err := filepath.Match(p.fixPattern(name), name); err != nil {
return false
} else if !match {
continue
@@ -102,6 +102,19 @@
return false
}
+// Pattern which does not contain slash matches files in all subdirectories.
+//
+// pattern: "file"
+// path: "file", "path/to/file"
+func (p *pattern) fixPattern(path string) string {
+ pat := p.pattern[0]
+ if strings.Contains(pat, "/") {
+ return pat
+ }
+ dir, _ := filepath.Split(path)
+ return filepath.Join(dir, pat)
+}
+
func (p *pattern) globMatch(path []string, isDir bool) bool {
matched := false
canTraverse := false |
I am sorry, but I do not quite understand what ignore pattern matching has to do with the presence of change in the repository. At best it maybe need to be applied to a different set of files, that is changed only, but the algorithm itself should not know if anything was changed or not. I also do not quite understand how your fix solves the above, that is your use case. Do write a comprehensive test that covers the expected behaviour and goes ok with your fix while failing without. This, I would expect, you could submit as a PR. |
Sorry, what else need to be applied? |
I want to check if a repository has dirty worktree.
but
Worktree.Status()
lists up ignored files by global gitignore ($HOME/.gitconfig
'score.excludesfile
).I read COMPATIBILITY.md and it says:
so maybe I have to parse
$HOME/.gitconfig
manually, and getcore.excludesfile
, and check ignore files one by one.but how?
The text was updated successfully, but these errors were encountered: