This commit is contained in:
Ian Gulliver
2026-10-20 22:15:33 -07:00
parent 627319a01f
commit 2bfa62449d
9 changed files with 45 additions and 57 deletions
+10 -15
View File
@@ -1,10 +1,8 @@
package git
import (
"bytes"
"errors"
"context"
"fmt"
"os/exec"
"strings"
)
@@ -14,23 +12,20 @@ func Ignored(worktree string, paths []string) (map[string]bool, error) {
return ignored, nil
}
cmd := exec.Command("git", "check-ignore", "--stdin", "-z")
cmd.Dir = worktree
cmd.Stdin = strings.NewReader(strings.Join(paths, "\x00") + "\x00")
stderr := &strings.Builder{}
cmd.Stderr = stderr
out, err := cmd.Output()
exit := &exec.ExitError{}
if errors.As(err, &exit) && exit.ExitCode() == 1 {
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 err != nil {
return nil, fmt.Errorf("git check-ignore: %w: %s", err, strings.TrimSpace(stderr.String()))
if code != 0 {
return nil, fmt.Errorf("git check-ignore: exit status %d: %s", code, stderr)
}
for _, p := range bytes.Split(out, []byte{0}) {
for _, p := range strings.Split(out, "\x00") {
if len(p) > 0 {
ignored[string(p)] = true
ignored[p] = true
}
}
return ignored, nil