forked from kryptco/kr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.go
30 lines (27 loc) · 698 Bytes
/
git.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
package kr
import (
"fmt"
"os"
"os/exec"
"strings"
)
func GlobalGitUserId() (id string, err error) {
oldPath := os.Getenv("PATH")
if !strings.Contains(oldPath, "/usr/local/bin") || !strings.Contains(oldPath, "/usr/bin") {
os.Setenv("PATH", "/usr/bin:/usr/local/bin:"+oldPath)
}
name, err := exec.Command("git", "config", "--global", "user.name").Output()
if err != nil {
return
}
email, err := exec.Command("git", "config", "--global", "user.email").Output()
if err != nil {
return
}
id = fmt.Sprintf("%s <%s>", strings.TrimSpace(string(name)), strings.TrimSpace(string(email)))
return
}
func HasGPG() bool {
err := exec.Command("gpg", "--help").Run()
return err == nil
}