customgitignore

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseGitIgnores

func ParseGitIgnores(path string, recursive bool) ([]gitignore.Pattern, string, error)

ParseGitIgnores takes a dir and processes .gitignore files from it.

This uses go-git under the hood and returns a slice of go-git's gitignore.Pattern structs.

Because this function finds the enclosing git repo, it returns that as its second argument, which may be `path`, or a parent of `path`, or "" if there's no enclosing git repo.

Because it detects the root of any enclosing git repo if path doesn't exist the root, it returns this repoPath or "" if there is none.

It also returns the path to the root of the git-repo, or "" if this path isn't within a git repo, allowing a caller to know how .gitignore files were parsed.

The actual parsing is intended to be similar to how tools like rg work, but means that `path` may not necessarily be the root of a git repo, and can produce these parsing behaviours:

`path` is a plain dir:

  • .gitignore files are ignored

`path` is a file:

  • find the file's dir and then run the following rules...

`path` is a dir at the root of a git-repo, with recursive flag:

  • read all .gitignore files in repo
  • read .git/info/exclude for repo

`path` is a dir at the root of a git-repo, without recursive flag:

  • only read .gitignore files in repo-root
  • read .git/info/exclude for repo

`path` is a dir within a git-repo, with recursive flag:

  • read .gitignore in start dir
  • read all .gitignore files in child-dirs
  • read all .gitignore files in parent dirs up to and including repo-root (but only dirs that are an ancestor)

`path` is a dir within, a git-repo, without recursive flag:

  • read .gitignore in start dir
  • read all .gitignore files in parent dirs up to and including repo-root (but only dirs that are an ancestor)
  • read .git/info/exclude for repo

NOTE: the dir you're passing in directly could be a dir that is ignored (targeted by a parent's .gitignore or the per-repo exclude file); in this case, the dir's .gitignore file is still processed, but not its sub-dirs.

In all cases any dirs matched by a previously read .gitignore are skipped, unless it's the path (ie directly supplied by the user).

func ReadPatterns

func ReadPatterns(fs billy.Filesystem, path []string) (ps []gitignore.Pattern, err error)

ReadPatterns reads the .git/info/exclude and then the gitignore patterns recursively traversing through the directory structure. The result is in the ascending order of priority (last higher).

func ReadPatternsIgnoringDirs

func ReadPatternsIgnoringDirs(fs billy.Filesystem, path []string, accumulatedPs []gitignore.Pattern) (ps []gitignore.Pattern, err error)

ReadPatternsIgnoringDirs keeps track of the patterns it has read so far, and does not parse directories these match for efficiency.

Optionally a list of existing patterns to ignore can be supplied.

Types

This section is empty.

Jump to

Keyboard shortcuts

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