1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-09 13:36:56 +02:00

refactor: simplified code

This commit is contained in:
Carlos Alexandro Becker 2018-07-03 23:44:51 -07:00
parent 9d4be131cf
commit abe90e9f5f
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940

View File

@ -2,7 +2,6 @@
package git
import (
"bytes"
"errors"
"os/exec"
"strings"
@ -18,21 +17,17 @@ func IsRepo() bool {
// Run runs a git command and returns its output or errors
func Run(args ...string) (string, error) {
// TODO: use exex.CommandContext here and refactor.
/* #nosec */
var cmd = exec.Command("git", args...)
log.WithField("args", args).Debug("running git")
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
log.WithField("stdout", stdout.String()).
WithField("stderr", stderr.String()).
bts, err := cmd.CombinedOutput()
log.WithField("output", string(bts)).
Debug("git result")
if err != nil {
return "", errors.New(stderr.String())
return "", errors.New(string(bts))
}
return stdout.String(), nil
return string(bts), nil
}
// Clean the output