Files
task/internal/fingerprint/glob.go
Valentin Maerten 37d6b7155f rename: gitignore -> use_gitignore for clarity
Rename the Taskfile/task option from `gitignore` to `use_gitignore`
to avoid ambiguity (could be read as "ignore git" vs "use .gitignore").
Consistent with Biome's `useIgnoreFile` naming convention.
2026-04-20 22:06:01 +02:00

66 lines
1.2 KiB
Go

package fingerprint
import (
"os"
"path/filepath"
"sort"
"github.com/go-task/task/v3/internal/execext"
"github.com/go-task/task/v3/internal/filepathext"
"github.com/go-task/task/v3/taskfile/ast"
)
func Globs(dir string, globs []*ast.Glob, useGitignore bool) ([]string, error) {
resultMap := make(map[string]bool)
for _, g := range globs {
matches, err := glob(dir, g.Glob)
if err != nil {
continue
}
for _, match := range matches {
resultMap[match] = !g.Negate
}
}
if useGitignore {
resultMap = filterGitignored(resultMap, dir)
}
return collectKeys(resultMap), nil
}
func glob(dir string, g string) ([]string, error) {
g = filepathext.SmartJoin(dir, g)
fs, err := execext.ExpandFields(g)
if err != nil {
return nil, err
}
results := make(map[string]bool, len(fs))
for _, f := range fs {
info, err := os.Stat(f)
if err != nil {
return nil, err
}
if info.IsDir() {
continue
}
results[f] = true
}
return collectKeys(results), nil
}
func collectKeys(m map[string]bool) []string {
keys := make([]string, 0, len(m))
for k, v := range m {
if v {
// Normalize path separators for consistent sorting across platforms
keys = append(keys, filepath.ToSlash(k))
}
}
sort.Strings(keys)
return keys
}