git-sync-web 自动提交 2026-09-09 18:09:14
This commit is contained in:
@@ -179,15 +179,14 @@ func (e *Engine) SavePendingSummary(name, text string) error {
|
|||||||
return os.WriteFile(e.pendingPath(name), []byte(t+"\n"), 0o644)
|
return os.WriteFile(e.pendingPath(name), []byte(t+"\n"), 0o644)
|
||||||
}
|
}
|
||||||
|
|
||||||
// autoSummary 在没有任何人工摘要时,依据本次改动自动生成一句话摘要(仅本地记录用)。
|
// statusFiles 返回工作区相对改动文件列表(用于自动摘要;须在 git add 之前调用)。
|
||||||
func (e *Engine) autoSummary(repoPath string) string {
|
func (e *Engine) statusFiles(repoPath string) []string {
|
||||||
out, err := gitRun(repoPath, 15*time.Second, "status", "--porcelain")
|
out, err := gitRun(repoPath, 15*time.Second, "status", "--porcelain")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "自动提交"
|
return nil
|
||||||
}
|
}
|
||||||
lines := strings.Split(strings.TrimSpace(out), "\n")
|
|
||||||
var files []string
|
var files []string
|
||||||
for _, ln := range lines {
|
for _, ln := range strings.Split(strings.TrimSpace(out), "\n") {
|
||||||
ln = strings.TrimSpace(ln)
|
ln = strings.TrimSpace(ln)
|
||||||
if ln == "" {
|
if ln == "" {
|
||||||
continue
|
continue
|
||||||
@@ -201,6 +200,12 @@ func (e *Engine) autoSummary(repoPath string) string {
|
|||||||
files = append(files, p)
|
files = append(files, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return files
|
||||||
|
}
|
||||||
|
|
||||||
|
// autoSummary 在没有任何人工摘要时,依据本次改动自动生成一句话摘要(仅本地记录用)。
|
||||||
|
// files 须为提交前的改动文件列表(见 statusFiles)。
|
||||||
|
func (e *Engine) autoSummary(files []string) string {
|
||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
return "自动提交(无改动文件)"
|
return "自动提交(无改动文件)"
|
||||||
}
|
}
|
||||||
@@ -728,6 +733,10 @@ func (e *Engine) syncOnce(s *repoState, trigger string) {
|
|||||||
if pend != "" {
|
if pend != "" {
|
||||||
cmsg = pend
|
cmsg = pend
|
||||||
}
|
}
|
||||||
|
var autoFiles []string
|
||||||
|
if pend == "" {
|
||||||
|
autoFiles = e.statusFiles(cfg.RepoPath)
|
||||||
|
}
|
||||||
if _, cerr := gitRun(cfg.RepoPath, 120*time.Second, "commit", "-m", cmsg); cerr != nil {
|
if _, cerr := gitRun(cfg.RepoPath, 120*time.Second, "commit", "-m", cmsg); cerr != nil {
|
||||||
e.setFail(s, "自动提交失败: "+cerr.Error())
|
e.setFail(s, "自动提交失败: "+cerr.Error())
|
||||||
return
|
return
|
||||||
@@ -735,7 +744,7 @@ func (e *Engine) syncOnce(s *repoState, trigger string) {
|
|||||||
if sha, serr := gitRun(cfg.RepoPath, 10*time.Second, "rev-parse", "--short", "HEAD"); serr == nil {
|
if sha, serr := gitRun(cfg.RepoPath, 10*time.Second, "rev-parse", "--short", "HEAD"); serr == nil {
|
||||||
sum := cmsg
|
sum := cmsg
|
||||||
if pend == "" {
|
if pend == "" {
|
||||||
sum = e.autoSummary(cfg.RepoPath)
|
sum = e.autoSummary(autoFiles)
|
||||||
}
|
}
|
||||||
e.RecordCommit(s.cfg.Name, sha, sum)
|
e.RecordCommit(s.cfg.Name, sha, sum)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user