1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

fix: show git error on debug (#710)

Right now, if git fails, it doesn't matter if debug is enabled, because it won't print both stdout and stderr.
This commit is contained in:
Carlos Alexandro Becker 2018-07-04 01:38:53 -07:00 committed by GitHub
commit 47b6bd5f50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,6 @@
package git
import (
"bytes"
"errors"
"os/exec"
"strings"
@ -18,18 +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
if err := cmd.Run(); err != nil {
return "", errors.New(stderr.String())
bts, err := cmd.CombinedOutput()
log.WithField("output", string(bts)).
Debug("git result")
if err != nil {
return "", errors.New(string(bts))
}
log.WithField("output", stdout.String()).Debug("git result")
return stdout.String(), nil
return string(bts), nil
}
// Clean the output