Files
byre/internal/git/ignore.go
T
2026-10-20 22:15:33 -07:00

33 lines
665 B
Go

package git
import (
"context"
"fmt"
"strings"
)
func Ignored(worktree string, paths []string) (map[string]bool, error) {
ignored := map[string]bool{}
if len(paths) == 0 {
return ignored, nil
}
out, stderr, code, err := runCodeInput(context.Background(), worktree, nil, strings.NewReader(strings.Join(paths, "\x00")+"\x00"), "check-ignore", "--stdin", "-z")
if err != nil {
return nil, err
}
if code == 1 {
return ignored, nil
}
if code != 0 {
return nil, fmt.Errorf("git check-ignore: exit status %d: %s", code, stderr)
}
for _, p := range strings.Split(out, "\x00") {
if len(p) > 0 {
ignored[p] = true
}
}
return ignored, nil
}