Audit of 627319a
This commit is contained in:
+10
-15
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user