-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.go
More file actions
74 lines (66 loc) · 1.71 KB
/
git.go
File metadata and controls
74 lines (66 loc) · 1.71 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"os/exec"
"strings"
)
func gitClone(url, dest string) error {
cmd := exec.Command("git", "clone", url, dest)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("git clone failed: %s\n%s", err, out)
}
return nil
}
func gitAdd(repoPath string) error {
cmd := exec.Command("git", "-C", repoPath, "add", "-A")
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("git add failed: %s\n%s", err, out)
}
return nil
}
func gitCommit(repoPath, msg string) error {
cmd := exec.Command("git", "-C", repoPath, "commit", "-m", msg)
out, err := cmd.CombinedOutput()
if err != nil {
// "nothing to commit" is not an error for us
if strings.Contains(string(out), "nothing to commit") {
return nil
}
return fmt.Errorf("git commit failed: %s\n%s", err, out)
}
return nil
}
func gitPush(repoPath string) error {
cmd := exec.Command("git", "-C", repoPath, "push")
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("git push failed: %s\n%s", err, out)
}
return nil
}
func gitPull(repoPath string) error {
cmd := exec.Command("git", "-C", repoPath, "pull")
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("git pull failed: %s\n%s", err, out)
}
return nil
}
func gitHasChanges(repoPath string) bool {
cmd := exec.Command("git", "-C", repoPath, "status", "--porcelain")
out, err := cmd.Output()
if err != nil {
return false
}
return strings.TrimSpace(string(out)) != ""
}
func gitStatusOutput(repoPath string) (string, error) {
cmd := exec.Command("git", "-C", repoPath, "status", "--porcelain")
out, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("git status failed: %s", err)
}
return string(out), nil
}