git-sync-web 自动提交 2026-09-09 12:49:43

This commit is contained in:
tamakyi
2026-09-09 12:49:44 +08:00
parent d4f10ab574
commit b921569b72
+15 -1
View File
@@ -1405,11 +1405,12 @@ func (e *Engine) WorkingDiff(name, scope string) (*DiffResult, error) {
statArgs = append(statArgs, "--stat")
}
if statOut, serr := gitRun(s.cfg.RepoPath, 30*time.Second, statArgs...); serr == nil {
statOut = stripWarnings(statOut)
res.Stat = statOut
res.Files = parseStatFiles(statOut)
}
if textOut, terr := gitRun(s.cfg.RepoPath, 60*time.Second, args...); terr == nil {
res.Text = textOut
res.Text = stripWarnings(textOut)
} else {
res.Text = terr.Error()
}
@@ -1419,6 +1420,19 @@ func (e *Engine) WorkingDiff(name, scope string) (*DiffResult, error) {
return res, nil
}
// stripWarnings 去掉 git 在 stderr 输出的环境告警(如 autocrlf 提示),避免污染差异展示
func stripWarnings(s string) string {
lines := strings.Split(s, "\n")
out := make([]string, 0, len(lines))
for _, l := range lines {
if strings.HasPrefix(l, "warning:") {
continue
}
out = append(out, l)
}
return strings.Join(out, "\n")
}
// parseStatFiles 解析 `git diff --stat` 输出为单文件增删统计
func parseStatFiles(stat string) []DiffFile {
var files []DiffFile