@@ -9,10 +9,17 @@ import (
99 "path/filepath"
1010)
1111
12+ type UpdateAction string
13+
14+ const (
15+ UpdateActionPull = "pull"
16+ UpdateActionFetch = "fetch"
17+ )
18+
1219type Config struct {
13- Root string `json:"root"`
14- Questions bool `json:"questions"`
15- PullAfterFetch bool `json:"pull_after_fetch "`
20+ Root string `json:"root"`
21+ Questions bool `json:"questions"`
22+ Action UpdateAction `json:"action "`
1623}
1724
1825var _ provider.Provider = & Local {}
@@ -72,7 +79,7 @@ func (l *Local) MigrateRepo(from *provider.Owner, to *provider.Owner, repo *prov
7279 return "" , err
7380 }
7481 }
75- err = gitFetchAndTryPull (repoPath , l .conf .PullAfterFetch )
82+ err = gitUpdateLocal (repoPath , l .conf .Action )
7683 if err != nil {
7784 return "fail" , err
7885 }
@@ -104,19 +111,17 @@ func gitClone(url, path string) error {
104111 return cmd .Run ()
105112}
106113
107- func gitFetchAndTryPull (path string , pullAfterFetch bool ) error {
108- log .Printf ("pulling %s" , path )
109- cmd := exec .Command ("git" , "fetch" , "--all" )
114+ func gitUpdateLocal (path string , action UpdateAction ) error {
115+ log .Printf ("action %s" , path )
116+ if action != UpdateActionPull && action != UpdateActionFetch {
117+ return fmt .Errorf ("unsupported action: %s" , action )
118+ }
119+ cmd := exec .Command ("git" , string (action ), "--all" )
110120 cmd .Dir = path
111121 err := cmd .Run ()
112122 if err != nil {
113123 return err
114124 }
115- if pullAfterFetch {
116- cmd = exec .Command ("git" , "pull" )
117- cmd .Dir = path
118- return cmd .Run ()
119- }
120125 return nil
121126}
122127
0 commit comments