mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
…
|
||
---|---|---|
.. | ||
.travis.yml | ||
depth_holder.go | ||
full_scan_patterns.go | ||
gitignore.go | ||
index_scan_patterns.go | ||
initial_holder.go | ||
LICENSE | ||
match.go | ||
pattern.go | ||
patterns.go | ||
README.md | ||
util.go |
go-gitignore
A fast gitignore matching library for Go.
This library use simple tree index for matching, so keep fast if gitignore file has many pattern.
Usage
gitignore, _ := gitignore.NewGitIgnore("/path/to/gitignore")
path := "/path/to/file"
isDir := false
gitignore.Match(path, isDir)
Specify base directory
go-gitignore treat path
as a base directory.
If you want to specify other base (e.g. current directory and Global gitignore), you can like the following.
gitignore, _ := gitignore.NewGitIgnore("/home/you/.gitignore", ".")
From io.Reader
go-gitignore can initialize from io.Reader.
gitignore, _ := gitignore.NewGitIgnoreFromReader(base, reader)
Simple tree index
go-gitignore parse gitignore file, and generate a simple tree index for matching like the following.
.
├── accept
│ ├── absolute
│ │ └── depth
│ │ ├── initial
│ │ └── other
│ └── relative
│ └── depth
│ ├── initial
│ └── other
└── ignore
├── absolute
│ └── depth
│ ├── initial
│ └── other
└── relative
└── depth
├── initial
└── other
Features
- Support absolute path (/path/to/ignore)
- Support relative path (path/to/ignore)
- Support accept pattern (!path/to/accept)
- Support directory pattern (path/to/directory/)
- Support glob pattern (path/to/*.txt)
note: glob pattern
go-gitignore use filepath.Match for matching meta char pattern, so not support recursive pattern (path/**
/file).
Installation
$ go get github.com/monochromegane/go-gitignore
Contribution
- Fork it
- Create a feature branch
- Commit your changes
- Rebase your local changes against the master branch
- Run test suite with the
go test ./...
command and confirm that it passes - Run
gofmt -s
- Create new Pull Request