@@ -9,10 +9,17 @@ import (
9
9
"path/filepath"
10
10
)
11
11
12
+ type UpdateAction string
13
+
14
+ const (
15
+ UpdateActionPull = "pull"
16
+ UpdateActionFetch = "fetch"
17
+ )
18
+
12
19
type 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 "`
16
23
}
17
24
18
25
var _ provider.Provider = & Local {}
@@ -72,7 +79,7 @@ func (l *Local) MigrateRepo(from *provider.Owner, to *provider.Owner, repo *prov
72
79
return "" , err
73
80
}
74
81
}
75
- err = gitFetchAndTryPull (repoPath , l .conf .PullAfterFetch )
82
+ err = gitUpdateLocal (repoPath , l .conf .Action )
76
83
if err != nil {
77
84
return "fail" , err
78
85
}
@@ -104,19 +111,17 @@ func gitClone(url, path string) error {
104
111
return cmd .Run ()
105
112
}
106
113
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" )
110
120
cmd .Dir = path
111
121
err := cmd .Run ()
112
122
if err != nil {
113
123
return err
114
124
}
115
- if pullAfterFetch {
116
- cmd = exec .Command ("git" , "pull" )
117
- cmd .Dir = path
118
- return cmd .Run ()
119
- }
120
125
return nil
121
126
}
122
127
0 commit comments