NewGitIgnoreCache creates a cache that supports nested .gitignore files. root should be the project root directory.
(root string)
| 22 | // NewGitIgnoreCache creates a cache that supports nested .gitignore files. |
| 23 | // root should be the project root directory. |
| 24 | func NewGitIgnoreCache(root string) *GitIgnoreCache { |
| 25 | absRoot, _ := filepath.Abs(root) |
| 26 | c := &GitIgnoreCache{ |
| 27 | root: absRoot, |
| 28 | cache: make(map[string]*ignore.GitIgnore), |
| 29 | patterns: make(map[string][]string), |
| 30 | visited: make(map[string]struct{}), |
| 31 | } |
| 32 | c.tryLoadGitignore(absRoot) |
| 33 | return c |
| 34 | } |
| 35 | |
| 36 | // tryLoadGitignore attempts to load a .gitignore from dir if not already visited. |
| 37 | // Only adds to cache if a valid .gitignore exists. |