Exemplo n.º 1
0
// IgnoresAllFiles takes in a slice of filepaths and checks to see if
// all files are matched by the project's Ignore regular expressions.
func (p *Project) IgnoresAllFiles(files []string) bool {
	if len(p.Ignore) == 0 || len(files) == 0 {
		return false
	}
	// CompileIgnoreLines has a silly API: it always returns a nil error.
	ignorer, _ := ignore.CompileIgnoreLines(p.Ignore...)
	for _, f := range files {
		if !ignorer.MatchesPath(f) {
			return false
		}
	}
	return true
}
Exemplo n.º 2
0
// BuildFileList returns a list of files that match the given list of expressions
// rooted at the given startPath. The expressions correspond to gitignore ignore
// expressions: anything that would be matched - and therefore ignored by git - is included
// in the returned list of file paths. BuildFileList does not follow symlinks as
// it uses filpath.Walk, which does not follow symlinks.
func BuildFileList(startPath string, expressions ...string) ([]string, error) {
	ignorer, err := ignore.CompileIgnoreLines(expressions...)
	if err != nil {
		return nil, err
	}
	fb := &fileListBuilder{
		fileNames: []string{},
		ignorer:   ignorer,
	}
	err = filepath.Walk(startPath, fb.walkFunc)
	if err != nil {
		return nil, err
	}
	return fb.fileNames, nil
}