1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00

Merge pull request #531 from goreleaser/git

fix: git: if exit is 0, ignore stderr
This commit is contained in:
Carlos Alexandro Becker 2018-01-28 12:21:01 -02:00 committed by GitHub
commit 7952d82082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -2,6 +2,7 @@
package git
import (
"bytes"
"errors"
"os/exec"
"strings"
@ -16,16 +17,19 @@ func IsRepo() bool {
}
// Run runs a git command and returns its output or errors
func Run(args ...string) (output string, err error) {
func Run(args ...string) (string, error) {
/* #nosec */
var cmd = exec.Command("git", args...)
log.WithField("args", args).Debug("running git")
bts, err := cmd.CombinedOutput()
if err != nil {
return "", errors.New(string(bts))
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())
}
log.WithField("output", string(bts)).Debug("result")
return string(bts), err
log.WithField("output", stdout.String()).Debug("git result")
return stdout.String(), nil
}
// Clean the output

View File

@ -33,5 +33,4 @@ func TestClean(t *testing.T) {
out, err := Clean("asdasd 'ssadas'\nadasd", nil)
assert.NoError(t, err)
assert.Equal(t, "asdasd ssadas", out)
}