Skip to content

Commit 9bb8cb3

Browse files
committed
feat: 在配置中添加PullAfterFetch字段,并更新git拉取逻辑以支持条件拉取
1 parent b32f3b2 commit 9bb8cb3

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

provider/local/local.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import (
1010
)
1111

1212
type Config struct {
13-
Root string `json:"root"`
14-
Questions bool `json:"questions"`
13+
Root string `json:"root"`
14+
Questions bool `json:"questions"`
15+
PullAfterFetch bool `json:"pull_after_fetch"`
1516
}
1617

1718
var _ provider.Provider = &Local{}
@@ -71,7 +72,7 @@ func (l *Local) MigrateRepo(from *provider.Owner, to *provider.Owner, repo *prov
7172
return "", err
7273
}
7374
}
74-
err = gitPull(repoPath)
75+
err = gitFetchAndTryPull(repoPath, l.conf.PullAfterFetch)
7576
if err != nil {
7677
return "fail", err
7778
}
@@ -103,11 +104,20 @@ func gitClone(url, path string) error {
103104
return cmd.Run()
104105
}
105106

106-
func gitPull(path string) error {
107+
func gitFetchAndTryPull(path string, pullAfterFetch bool) error {
107108
log.Printf("pulling %s", path)
108-
cmd := exec.Command("git", "pull")
109+
cmd := exec.Command("git", "fetch", "--all")
109110
cmd.Dir = path
110-
return cmd.Run()
111+
err := cmd.Run()
112+
if err != nil {
113+
return err
114+
}
115+
if pullAfterFetch {
116+
cmd = exec.Command("git", "pull")
117+
cmd.Dir = path
118+
return cmd.Run()
119+
}
120+
return nil
111121
}
112122

113123
func question(message string) bool {

0 commit comments

Comments
 (0)