Skip to content

idelchi/go-gitignore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gitignore

GitHub release Go Reference Go Report Card Build Status License: MIT

.gitignore pattern matching for Go.

Translated from the original c code, and validated against a large number of cases, including fuzzy testing, all cross-checked with git check-ignore to ensure behavior matches Git.

Installation

go get github.com/idelchi/go-gitignore

Usage

package main

import (
    "fmt"

    gitignore "github.com/idelchi/go-gitignore"
)

func main() {
    // Pass patterns to construct the gitignorer
    gi := gitignore.New("*.log", "build/", "!important.log")

    // Pass a path as well as a boolean indicating if it's a directory or not
    fmt.Println(gi.Ignored("app.log", false))        // true
    fmt.Println(gi.Ignored("important.log", false))  // false
    fmt.Println(gi.Ignored("build/file.txt", false)) // true
}

Use .Match(...) to retrieve both ignore status and the pattern that matched.

Limitations

  • Expects relative input paths. Absolute paths are treated as non-ignored, regardless of if they resolve to the current workspace.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages