@@ -16,6 +16,8 @@ import (
16
16
)
17
17
18
18
var (
19
+ pull = flag .Bool ("pull" , true , "automatically pull changes" )
20
+ push = flag .Bool ("push" , true , "automatically push changes" )
19
21
author = flag .String ("author" , "gitomatic" , "author name for git commits" )
20
22
email = flag .
String (
"email" ,
"[email protected] " ,
"email address for git commits" )
21
23
interval = flag .String ("interval" , "1m" , "how often to check for changes" )
@@ -137,65 +139,69 @@ func main() {
137
139
fatal ("cannot access repository: %s\n " , err )
138
140
}
139
141
140
- err = gitPull (r , w , auth )
141
- if err != nil {
142
- fatal ("cannot pull from repository: %s\n " , err )
142
+ if * pull {
143
+ err = gitPull (r , w , auth )
144
+ if err != nil {
145
+ fatal ("cannot pull from repository: %s\n " , err )
146
+ }
143
147
}
144
148
145
- status , err := w .Status ()
146
- if err != nil {
147
- fatal ("cannot retrieve git status: %s\n " , err )
148
- }
149
+ if * push {
150
+ status , err := w .Status ()
151
+ if err != nil {
152
+ fatal ("cannot retrieve git status: %s\n " , err )
153
+ }
149
154
150
- changes := 0
151
- msg := ""
152
- for path , s := range status {
153
- switch s .Worktree {
154
- case git .Untracked :
155
- log .Printf ("New file detected: %s\n " , path )
156
- err := gitAdd (w , path )
157
- if err != nil {
158
- fatal ("cannot add file: %s\n " , err )
155
+ changes := 0
156
+ msg := ""
157
+ for path , s := range status {
158
+ switch s .Worktree {
159
+ case git .Untracked :
160
+ log .Printf ("New file detected: %s\n " , path )
161
+ err := gitAdd (w , path )
162
+ if err != nil {
163
+ fatal ("cannot add file: %s\n " , err )
164
+ }
165
+
166
+ msg += fmt .Sprintf ("Add %s.\n " , path )
167
+ changes ++
168
+
169
+ case git .Modified :
170
+ log .Printf ("Modified file detected: %s\n " , path )
171
+ err := gitAdd (w , path )
172
+ if err != nil {
173
+ fatal ("cannot add file: %s\n " , err )
174
+ }
175
+
176
+ msg += fmt .Sprintf ("Update %s.\n " , path )
177
+ changes ++
178
+
179
+ case git .Deleted :
180
+ log .Printf ("Deleted file detected: %s\n " , path )
181
+ err := gitRemove (w , path )
182
+ if err != nil {
183
+ fatal ("cannot remove file: %s\n " , err )
184
+ }
185
+
186
+ msg += fmt .Sprintf ("Remove %s.\n " , path )
187
+ changes ++
188
+
189
+ default :
190
+ log .Printf ("%s %s %s\n " , string (s .Worktree ), string (s .Staging ), path )
159
191
}
192
+ }
160
193
161
- msg += fmt .Sprintf ("Add %s.\n " , path )
162
- changes ++
163
-
164
- case git .Modified :
165
- log .Printf ("Modified file detected: %s\n " , path )
166
- err := gitAdd (w , path )
194
+ if changes == 0 {
195
+ log .Println ("No changes detected." )
196
+ } else {
197
+ err = gitCommit (w , msg )
167
198
if err != nil {
168
- fatal ("cannot add file : %s\n " , err )
199
+ fatal ("cannot commit : %s\n " , err )
169
200
}
170
-
171
- msg += fmt .Sprintf ("Update %s.\n " , path )
172
- changes ++
173
-
174
- case git .Deleted :
175
- log .Printf ("Deleted file detected: %s\n " , path )
176
- err := gitRemove (w , path )
201
+ err = gitPush (r , auth )
177
202
if err != nil {
178
- fatal ("cannot remove file : %s\n " , err )
203
+ fatal ("cannot push : %s\n " , err )
179
204
}
180
-
181
- msg += fmt .Sprintf ("Remove %s.\n " , path )
182
- changes ++
183
-
184
- default :
185
- log .Printf ("%s %s %s\n " , string (s .Worktree ), string (s .Staging ), path )
186
- }
187
- }
188
-
189
- if changes == 0 {
190
- log .Println ("No changes detected." )
191
- } else {
192
- err = gitCommit (w , msg )
193
- if err != nil {
194
- fatal ("cannot commit: %s\n " , err )
195
- }
196
- err = gitPush (r , auth )
197
- if err != nil {
198
- fatal ("cannot push: %s\n " , err )
199
205
}
200
206
}
201
207
0 commit comments