-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgit.go
46 lines (38 loc) · 829 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"os"
"strings"
"os/exec"
)
const maxGitRecursion = 32
func checkGitInPath() error {
if _, err := exec.LookPath("git"); err != nil {
return fmt.Errorf("cannot find git in PATH: %w", err)
}
return nil
}
func findGitDir() (string, error) {
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
output, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf(string(output))
}
return strings.TrimSpace(string(output)), nil
}
func commit(msg string, body bool, signOff bool) error {
args := append([]string{
"commit", "-m", msg,
}, os.Args[1:]...)
if body {
args = append(args, "-e")
}
if signOff {
args = append(args, "-s")
}
cmd := exec.Command("git", args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}