-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (47 loc) · 1.3 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"log"
"os"
"time"
)
func main() {
// disables adding, commitin and pushing, only logs the generated commit message
devMode := false
conf := getConfig()
if !CheckForGit(conf) {
log.Fatalln("[FATAL ERROR] 'git' executable not found, git is required to work properly - exiting.")
}
if len(os.Args) > 1 && os.Args[1] == "--debug" {
conf.DebugMode = true
} else if len(os.Args) > 1 && os.Args[1] == "--dev" {
devMode = true
}
if conf.DebugMode {
DebugLog(conf, "Debug mode enabled")
}
if !CheckIfGitRepo(conf) {
log.Fatalln("[FATAL ERROR] not a git repository - exiting.")
}
if devMode {
conf.DebugMode = true
DebugLog(conf, "Dev mode enabled, automatically enabled debug mode, adding, committing and pushing will be disabled.")
log.Println(generateCommitContent(conf))
os.Exit(0)
}
if conf.PullOnStart {
log.Println("pulling changes from remote...")
GitPull(conf)
}
log.Println("Watching for changes...")
for true {
if GitRepoHasChanges(conf) {
GitAdd(conf)
GitCommit(conf)
GitPush(conf)
log.Printf("All done, waiting for %d seconds before checking for changes again...", conf.BackupInterval)
} else {
log.Println("No changes to commit, waiting for next iteration...")
}
time.Sleep(time.Duration(conf.BackupInterval) * time.Second)
}
}