-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlazygit.go
More file actions
57 lines (48 loc) · 1.04 KB
/
lazygit.go
File metadata and controls
57 lines (48 loc) · 1.04 KB
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
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strings"
)
func main() {
argsWithoutProg := os.Args[1:]
argsString := strings.Join(argsWithoutProg, " ")
if len(argsWithoutProg) < 2 {
fmt.Printf("lazygit: %s is not a valid lazygit command.\nUsage: lazygit commit_message", argsString)
return
}
cmd := exec.Command("git", "add", "-A")
log.Printf("git add -A")
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
cmd = exec.Command("git", "add", "-u")
log.Printf("git add -u")
err = cmd.Run()
if err != nil {
log.Fatal(err)
}
cmd = exec.Command("git", "commit", "-m", argsString)
log.Printf("git commit -m \"%s\"", argsString)
err = cmd.Run()
if err != nil {
log.Fatalf("Check if you have changes to commit. Error: %s", err)
}
cmd = exec.Command("git", "pull")
log.Printf("git pull")
err = cmd.Run()
if err != nil {
log.Fatal(err)
}
cmd = exec.Command("git", "push")
log.Printf("git push")
err = cmd.Run()
if err != nil {
log.Fatal(err)
}
fmt.Printf("All files successfully committed and pushed")
return
}