...
1# go-gitignore [](https://travis-ci.org/monochromegane/go-gitignore)
2
3A fast gitignore matching library for Go.
4
5This library use simple tree index for matching, so keep fast if gitignore file has many pattern.
6
7## Usage
8
9```go
10gitignore, _ := gitignore.NewGitIgnore("/path/to/gitignore")
11
12path := "/path/to/file"
13isDir := false
14gitignore.Match(path, isDir)
15```
16
17### Specify base directory
18
19go-gitignore treat `path` as a base directory.
20If you want to specify other base (e.g. current directory and Global gitignore), you can like the following.
21
22```go
23gitignore, _ := gitignore.NewGitIgnore("/home/you/.gitignore", ".")
24```
25
26### From io.Reader
27
28go-gitignore can initialize from io.Reader.
29
30```go
31gitignore, _ := gitignore.NewGitIgnoreFromReader(base, reader)
32```
33
34## Simple tree index
35
36go-gitignore parse gitignore file, and generate a simple tree index for matching like the following.
37
38```
39.
40├── accept
41│ ├── absolute
42│ │ └── depth
43│ │ ├── initial
44│ │ └── other
45│ └── relative
46│ └── depth
47│ ├── initial
48│ └── other
49└── ignore
50 ├── absolute
51 │ └── depth
52 │ ├── initial
53 │ └── other
54 └── relative
55 └── depth
56 ├── initial
57 └── other
58```
59
60## Features
61
62- Support absolute path (/path/to/ignore)
63- Support relative path (path/to/ignore)
64- Support accept pattern (!path/to/accept)
65- Support directory pattern (path/to/directory/)
66- Support glob pattern (path/to/\*.txt)
67
68*note: glob pattern*
69
70go-gitignore use [filepath.Match](https://golang.org/pkg/path/filepath/#Match) for matching meta char pattern, so not support recursive pattern (path/`**`/file).
71
72## Installation
73
74```sh
75$ go get github.com/monochromegane/go-gitignore
76```
77
78## Contribution
79
801. Fork it
812. Create a feature branch
823. Commit your changes
834. Rebase your local changes against the master branch
845. Run test suite with the `go test ./...` command and confirm that it passes
856. Run `gofmt -s`
867. Create new Pull Request
87
88## License
89
90[MIT](https://github.com/monochromegane/go-gitignore/blob/master/LICENSE)
91
92## Author
93
94[monochromegane](https://github.com/monochromegane)
95
View as plain text