-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgitexec.go
37 lines (33 loc) · 823 Bytes
/
gitexec.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
package gitcomm
import (
"os/exec"
"strings"
)
// GitExec function performs git workflow
func GitExec(addAll, show bool, msg string) {
if addAll {
gitColorCmd("add", "-A")
}
gitColorCmd("add", "-u")
gitColorCmd("commit", "-m", msg)
if show {
gitColorCmd("show", "-s")
}
}
// CheckForUncommited function checks if there are changes that need commit
func CheckForUncommited() bool {
cmd := exec.Command("git", "status", "--porcelain")
out, err := cmd.CombinedOutput()
CheckIfError(err)
return len(out) != 0
}
// CheckIsGitDir function checks is dir inside git worktree
func CheckIsGitDir() bool {
cmd := exec.Command("git", "rev-parse", "--is-inside-work-tree")
out, err := cmd.Output()
isGitDir := strings.TrimSpace(string(out))
if err == nil && isGitDir == "true" {
return true
}
return false
}