gsquash/git/cmd.go

27 lines
444 B
Go
Raw Normal View History

2023-12-05 20:03:27 +01:00
package git
import (
"log"
"os/exec"
"strings"
)
2023-12-05 20:03:27 +01:00
// Execute runs a git command and returns the stdout
func (g *Git) Execute(args ...string) (string, error) {
log.Println("git", strings.Join(args, " "))
2023-12-05 20:03:27 +01:00
cmd := exec.Command("git", args...)
if g.WorkingDir != "" {
cmd.Dir = g.WorkingDir
}
// Run and return stdout
out, err := cmd.Output()
if err != nil {
return "", err
}
return strings.TrimSuffix(string(out), "\n"), nil
2023-12-05 20:03:27 +01:00
}