mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-26 04:22:05 +02:00
Merge pull request #531 from goreleaser/git
fix: git: if exit is 0, ignore stderr
This commit is contained in:
commit
7952d82082
@ -2,6 +2,7 @@
|
|||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
@ -16,16 +17,19 @@ func IsRepo() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run runs a git command and returns its output or errors
|
// 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 */
|
/* #nosec */
|
||||||
var cmd = exec.Command("git", args...)
|
var cmd = exec.Command("git", args...)
|
||||||
log.WithField("args", args).Debug("running git")
|
log.WithField("args", args).Debug("running git")
|
||||||
bts, err := cmd.CombinedOutput()
|
var stdout bytes.Buffer
|
||||||
if err != nil {
|
var stderr bytes.Buffer
|
||||||
return "", errors.New(string(bts))
|
cmd.Stdout = &stdout
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return "", errors.New(stderr.String())
|
||||||
}
|
}
|
||||||
log.WithField("output", string(bts)).Debug("result")
|
log.WithField("output", stdout.String()).Debug("git result")
|
||||||
return string(bts), err
|
return stdout.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean the output
|
// Clean the output
|
||||||
|
@ -33,5 +33,4 @@ func TestClean(t *testing.T) {
|
|||||||
out, err := Clean("asdasd 'ssadas'\nadasd", nil)
|
out, err := Clean("asdasd 'ssadas'\nadasd", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "asdasd ssadas", out)
|
assert.Equal(t, "asdasd ssadas", out)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user