27 lines
444 B
Go
27 lines
444 B
Go
package git
|
|
|
|
import (
|
|
"log"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
// Execute runs a git command and returns the stdout
|
|
func (g *Git) Execute(args ...string) (string, error) {
|
|
|
|
log.Println("git", strings.Join(args, " "))
|
|
|
|
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
|
|
}
|