https://github.com/aligator/nogo
A .gitignore parsing lib in pure Go
https://github.com/aligator/nogo
files git gitignore go ignore lib parser
Last synced: 2 months ago
JSON representation
A .gitignore parsing lib in pure Go
- Host: GitHub
- URL: https://github.com/aligator/nogo
- Owner: aligator
- License: mit
- Created: 2021-11-21T13:39:21.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-30T14:58:23.000Z (about 3 years ago)
- Last Synced: 2025-06-28T04:38:05.652Z (12 months ago)
- Topics: files, git, gitignore, go, ignore, lib, parser
- Language: Go
- Homepage:
- Size: 95.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NoGo [](https://github.com/aligator/nogo/actions/workflows/test.yaml) [](https://github.com/aligator/nogo/actions/workflows/codeql-analysis.yml)
A .gitignore parser for Go.
## Features
* parsing .gitignore files
* loading file trees with several .gitignore files
* fs.WalkDir WalkDirFunc implementation (and afero.Walk (see below))
* customizable ignore filename (instead of .gitignore)
* full compatibility with git
As far as I could test it, it handles .gitignore files the same way as git.
If you find an inconsistency with git, please create a new Issue.
The goal is to provide the exact same .gitignore handling.
## Stability
Note that this lib is currently beta and therefore may introduce breaking changes.
However I don't think much will change.
## Usage
```go
n := nogo.New(nogo.DotGitRule)
if err := n.AddFromFS(wdfs, ".gitignore"); err != nil {
panic(err)
}
match := n.Match(toSearch, isDir)
fmt.Println(match)
```
There is also an alternative MatchBecause method which returns also
the causing rule if you need some context.
There exists a predefined rule to ignore any `.git` folder automatically.
```go
n := nogo.New(nogo.DotGitRule)
if err := n.AddFromFS(wdfs, ".gitignore"); err != nil {
panic(err)
}
```
## Walk
NoGo can be used with fs.WalkDir. [Just see the example walk.](example/walk/main.go)
If you need to use another Walk function, you can build your own wrapper using
the `NoGo.WalkFunc` function.
I intentionally did not include an afero walk to avoid a new dependency
just because of afero-compatibility. However, you can easily build your own.
You can find an example for afero in the documentation of `NoGo.WalkFunc`.