analyze: use git ls-files -z
This unblock support for non-ascii characters.
Coded with my bare hands.
diff --git a/claudetool/onstart/analyze.go b/claudetool/onstart/analyze.go
index 7ffade0..e63b380 100644
--- a/claudetool/onstart/analyze.go
+++ b/claudetool/onstart/analyze.go
@@ -3,6 +3,7 @@
import (
"bufio"
+ "bytes"
"cmp"
"context"
"fmt"
@@ -41,7 +42,7 @@
// TODO: do a filesystem walk instead?
// There's a balance: git ls-files skips node_modules etc,
// but some guidance files might be locally .gitignored.
- cmd := exec.Command("git", "ls-files")
+ cmd := exec.Command("git", "ls-files", "-z")
cmd.Dir = repoPath
r, w := io.Pipe() // stream and scan rather than buffer
@@ -66,6 +67,7 @@
defer r.Close()
scanner := bufio.NewScanner(r)
+ scanner.Split(scanZero)
for scanner.Scan() {
file := scanner.Text()
file = strings.TrimSpace(file)
@@ -208,3 +210,19 @@
return result
}
+
+func scanZero(data []byte, atEOF bool) (advance int, token []byte, err error) {
+ if atEOF && len(data) == 0 {
+ return 0, nil, nil
+ }
+ if i := bytes.IndexByte(data, 0); i >= 0 {
+ // We have a full NUL line.
+ return i + 1, data[0:i], nil
+ }
+ // If we're at EOF, we have a final, non-terminated line. Return it.
+ if atEOF {
+ return len(data), data, nil
+ }
+ // Request more data.
+ return 0, nil, nil
+}