-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (68 loc) · 2.03 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"os"
"os/exec"
"regexp"
"strings"
)
var (
regNothingToCommit = regexp.MustCompile("nothing to commit")
)
func isInGit(wd string) bool {
cmd := exec.Command("git", "rev-parse")
cmd.Dir = wd
output, err := cmd.CombinedOutput()
return len(output) == 0 && err == nil
}
func printErrorTitle() {
fmt.Println("███████╗██████╗ ██████╗ ██████╗ ██████╗ ")
fmt.Println("██╔════╝██╔══██╗██╔══██╗██╔═══██╗██╔══██╗")
fmt.Println("█████╗ ██████╔╝██████╔╝██║ ██║██████╔╝")
fmt.Println("██╔══╝ ██╔══██╗██╔══██╗██║ ██║██╔══██╗")
fmt.Println("███████╗██║ ██║██║ ██║╚██████╔╝██║ ██║")
fmt.Println("╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝")
}
func runCmd(wd, app string, args ...string) bool {
cmd := exec.Command(app, args...)
cmd.Dir = wd
output, err := cmd.CombinedOutput()
if err != nil {
if regNothingToCommit.Match(output) {
fmt.Println("Nothing to commit...")
return true
}
printErrorTitle()
fmt.Println("GIT had this to say: " + err.Error())
fmt.Println("=========================================")
fmt.Printf("%s", output)
fmt.Println("=========================================")
return false
}
return true
}
func main() {
cwd, _ := os.Getwd()
if !isInGit(cwd) {
printErrorTitle()
fmt.Println("This is not a git repo :(")
return
}
message := "Updates..."
if len(os.Args) > 1 {
words := os.Args[1:]
message = strings.Join(words, " ")
}
if !runCmd(cwd, "git", "add", "-A") {
return
}
if !runCmd(cwd, "git", "commit", "-am"+message) {
return
}
if !runCmd(cwd, "git", "pull") {
return
}
if !runCmd(cwd, "git", "push") {
return
}
}