gitignore

package
v0.0.0-...-f61237e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2024 License: MIT, MIT Imports: 4 Imported by: 0

README

gitignore

This is a small gitignore-matching library which is based on go-gitignore, adding a little bit of abstractions.

Installation
go get github.com/shravanasati/gap/gitignore
Usage
package main

import (
	"fmt"
	"github.com/shravanasati/gap/gitignore"
)

func main() {
	matcher, err := gitignore.NewGitignoreMatcher().FromFile("/path/to/your/gitignore")
	// you also have .FromReader(io.Reader) and .FromPatterns([]string)
	// these methods can be chained together, each will extend the internal list of patterns
	
	matcher, err := gitignore.NewGitignoreMatcher().
		FromPatterns([]string{"venv/"})
		FromReader(myTCPReader).

	fmt.Println(matcher.IsIgnored("venv/")) // true
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitignoreMatcher

type GitignoreMatcher struct {
	// contains filtered or unexported fields
}

Represents a GitignoreMatcher.

func NewGitignoreMatcher

func NewGitignoreMatcher() *GitignoreMatcher

Returns a pointer to the GitignoreMatcher with no patterns.

func (*GitignoreMatcher) Build

func (gm *GitignoreMatcher) Build() error

Build must be called before using the GitignoreMatcher. It initializes the patternmatcher.PatternMatcher struct with the given patterns.

func (*GitignoreMatcher) FromFile

func (gm *GitignoreMatcher) FromFile(filename string) (*GitignoreMatcher, error)

Adds the given patterns to the existing GitignoreMatcher by reading from the given file.

func (*GitignoreMatcher) FromPatterns

func (gm *GitignoreMatcher) FromPatterns(patterns []string) *GitignoreMatcher

Adds the given patterns to the existing GitignoreMatcher.

func (*GitignoreMatcher) FromReader

func (gm *GitignoreMatcher) FromReader(r io.Reader) (*GitignoreMatcher, error)

Adds the given patterns to the existing GitignoreMatcher by reading from the given reader.

func (*GitignoreMatcher) Matches

func (gm *GitignoreMatcher) Matches(someFilePath string) (bool, error)

Returns a boolean value indicating whether the given filepath would be ignored, as per the gitignore spec.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL