git-sync-web 自动提交 2026-09-09 11:53:34

This commit is contained in:
tamakyi
2026-09-09 11:53:35 +08:00
parent 2dd4a46ad6
commit 05d6f1bc84
3 changed files with 98 additions and 10 deletions
+8
View File
@@ -26,6 +26,7 @@ type RepoConfig struct {
RetryCount int `json:"retry_count"`
RetryInterval int `json:"retry_interval"`
ConflictStrategy string `json:"conflict_strategy"`
PushStrategy string `json:"push_strategy"`
AutoCommit bool `json:"auto_commit"`
Cron string `json:"cron"`
}
@@ -106,6 +107,7 @@ func loadRepoConfig(dir, name string) (*RepoConfig, error) {
c.RetryCount = atoiOr(m["RETRY_COUNT"], 0)
c.RetryInterval = atoiOr(m["RETRY_INTERVAL"], 0)
c.ConflictStrategy = orDefault(m["CONFLICT_STRATEGY"], "merge")
c.PushStrategy = orDefault(m["PUSH_STRATEGY"], "manual")
c.AutoCommit = strings.EqualFold(m["AUTO_COMMIT"], "1") || strings.EqualFold(m["AUTO_COMMIT"], "true")
c.Cron = strings.TrimSpace(m["CRON"])
if remotes := strings.TrimSpace(m["REMOTES"]); remotes != "" {
@@ -147,6 +149,7 @@ func saveRepoConfig(dir string, c *RepoConfig) error {
fmt.Fprintf(&b, "RETRY_COUNT=%s\n", q(strconv.Itoa(c.RetryCount)))
fmt.Fprintf(&b, "RETRY_INTERVAL=%s\n", q(strconv.Itoa(c.RetryInterval)))
fmt.Fprintf(&b, "CONFLICT_STRATEGY=%s\n", q(c.ConflictStrategy))
fmt.Fprintf(&b, "PUSH_STRATEGY=%s\n", q(c.PushStrategy))
ac := "0"
if c.AutoCommit {
ac = "1"
@@ -197,6 +200,11 @@ func validateRepoConfig(cfgDir string, c *RepoConfig, isCreate bool) error {
default:
return fmt.Errorf("冲突策略必须是 merge/rebase/abort")
}
switch c.PushStrategy {
case "manual", "rebase", "force":
default:
return fmt.Errorf("推送策略必须是 manual/rebase/force")
}
if c.Interval < 5 {
c.Interval = 60
}