You've already forked agentic-coding-workflow
git 逻辑
This commit is contained in:
@@ -3,6 +3,8 @@ package git
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GitError 是 git 子进程返回非零或超时时的统一错误形式。Stderr 已截断 ≤2000 字符;
|
||||
@@ -15,7 +17,27 @@ type GitError struct {
|
||||
}
|
||||
|
||||
func (e *GitError) Error() string {
|
||||
return fmt.Sprintf("git %v: exit %d: %s", e.Args, e.ExitCode, e.Stderr)
|
||||
// 对 Args 中形如 scheme://user:pass@host 的 URL 脱敏,避免 PAT 明文
|
||||
// 写进 last_sync_error / audit。
|
||||
redacted := make([]string, len(e.Args))
|
||||
for i, a := range e.Args {
|
||||
redacted[i] = redactURLUserinfo(a)
|
||||
}
|
||||
return fmt.Sprintf("git %v: exit %d: %s", redacted, e.ExitCode, e.Stderr)
|
||||
}
|
||||
|
||||
// redactURLUserinfo 剥离形如 scheme://user[:pass]@host 中的 userinfo,
|
||||
// 输出 scheme://host...。非 URL 字符串或解析失败时原样返回。
|
||||
func redactURLUserinfo(s string) string {
|
||||
if !strings.Contains(s, "://") {
|
||||
return s
|
||||
}
|
||||
u, err := url.Parse(s)
|
||||
if err != nil || u.User == nil {
|
||||
return s
|
||||
}
|
||||
u.User = nil
|
||||
return u.String()
|
||||
}
|
||||
|
||||
func (e *GitError) Unwrap() error { return e.Cause }
|
||||
|
||||
Reference in New Issue
Block a user