git-sync-web 自动提交 2026-09-09 14:55:18

This commit is contained in:
tamakyi
2026-09-09 14:55:18 +08:00
parent d48bf772c7
commit a1ccd4fe6a
5 changed files with 523 additions and 192 deletions
+34 -2
View File
@@ -1361,6 +1361,31 @@ func (e *Engine) CommitFile(name, rel, message string) error {
return nil
}
// ResolveConflictFile 网页端解决冲突:写入内容 → 暂存 → (可选)结束合并/变基
// finish=true 且已无其它冲突文件时才真正结束,避免把带冲突标记的内容提交进去
func (e *Engine) ResolveConflictFile(name, rel, content string, finish bool) error {
s := e.get(name)
if s == nil {
return fmt.Errorf("配置不存在: %s", name)
}
if err := e.WriteFileContent(name, rel, content); err != nil {
return err
}
if _, err := gitRun(s.cfg.RepoPath, 30*time.Second, "add", "--", rel); err != nil {
return fmt.Errorf("git add 失败: %w", err)
}
e.logf(s, "info", "网页端冲突文件 %s 已暂存", rel)
if !finish {
return nil
}
rest, _ := conflictFiles(s.cfg.RepoPath)
if len(rest) > 0 {
e.pushStatus(s)
return fmt.Errorf("已暂存 %s;但仍有未解决的冲突文件:%s", rel, strings.Join(rest, ", "))
}
return e.ConflictResolve(name)
}
// DiffFile 单文件增删统计
type DiffFile struct {
Path string `json:"path"`
@@ -1375,10 +1400,13 @@ type DiffResult struct {
Text string `json:"text"`
Files []DiffFile `json:"files"`
VsRemote bool `json:"vs_remote"`
Word bool `json:"word"`
}
// WorkingDiff 返回工作区/暂存/全部/与远程的差异;rel 非空时只对比该文件
func (e *Engine) WorkingDiff(name, scope, rel string) (*DiffResult, error) {
// WorkingDiff 返回工作区/暂存/全部/与远程的差异
// rel 非空时只对比单个文件(已做路径安全校验)
// mode = "word" 时改用 --word-diff=plain,便于词级定位改动
func (e *Engine) WorkingDiff(name, scope, rel, mode string) (*DiffResult, error) {
s := e.get(name)
if s == nil {
return nil, fmt.Errorf("配置不存在: %s", name)
@@ -1402,6 +1430,10 @@ func (e *Engine) WorkingDiff(name, scope, rel string) (*DiffResult, error) {
default: // working(未暂存)
args = []string{"diff", "--no-color"}
}
// 词级差异:--word-diff=plain 用 [-x-] / {+x+} 标记行内改动
if mode == "word" {
args = append(args, "--word-diff=plain")
}
statArgs := append([]string{}, args...)
if scope == "remote" {
statArgs = []string{"diff", "--no-color", "--stat", remote + "/" + s.cfg.Branch, "HEAD"}