mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
fix: ignore git warnings (#1740)
* fix: ignore git warnings Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: added test case Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: failing test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: logs Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
parent
50073583dc
commit
5d8b6f046a
@ -2,6 +2,7 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"os/exec"
|
||||
"strings"
|
||||
@ -32,14 +33,24 @@ func RunEnv(env map[string]string, args ...string) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
stdout := bytes.Buffer{}
|
||||
stderr := bytes.Buffer{}
|
||||
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
log.WithField("args", args).Debug("running git")
|
||||
bts, err := cmd.CombinedOutput()
|
||||
log.WithField("output", string(bts)).
|
||||
err := cmd.Run()
|
||||
|
||||
log.WithField("stdout", stdout.String()).
|
||||
WithField("stderr", stderr.String()).
|
||||
Debug("git result")
|
||||
|
||||
if err != nil {
|
||||
return "", errors.New(string(bts))
|
||||
return "", errors.New(stderr.String())
|
||||
}
|
||||
return string(bts), nil
|
||||
|
||||
return stdout.String(), nil
|
||||
}
|
||||
|
||||
// Run runs a git command and returns its output or errors.
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/git"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -23,6 +24,22 @@ func TestGit(t *testing.T) {
|
||||
)
|
||||
}
|
||||
|
||||
func TestGitWarning(t *testing.T) {
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "foo")
|
||||
testlib.GitBranch(t, "tags/1.2.2")
|
||||
testlib.GitTag(t, "1.2.2")
|
||||
testlib.GitCommit(t, "foobar")
|
||||
testlib.GitBranch(t, "tags/1.2.3")
|
||||
testlib.GitTag(t, "1.2.3")
|
||||
|
||||
out, err := git.Run("describe", "--tags", "--abbrev=0", "tags/1.2.3^")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "1.2.2\n", out)
|
||||
}
|
||||
|
||||
func TestRepo(t *testing.T) {
|
||||
assert.True(t, git.IsRepo(), "goreleaser folder should be a git repo")
|
||||
|
||||
|
@ -48,6 +48,13 @@ func GitTag(t *testing.T, tag string) {
|
||||
assert.Empty(t, out)
|
||||
}
|
||||
|
||||
// GitBranch creates a git branch.
|
||||
func GitBranch(t *testing.T, branch string) {
|
||||
out, err := fakeGit("branch", branch)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, out)
|
||||
}
|
||||
|
||||
// GitAdd adds all files to stage.
|
||||
func GitAdd(t *testing.T) {
|
||||
out, err := fakeGit("add", "-A")
|
||||
@ -71,8 +78,8 @@ func fakeGit(args ...string) (string, error) {
|
||||
}
|
||||
|
||||
// GitCheckoutBranch allows us to change the active branch that we're using.
|
||||
func GitCheckoutBranch(t *testing.T, tag string) {
|
||||
out, err := fakeGit("checkout", "-b", tag)
|
||||
func GitCheckoutBranch(t *testing.T, name string) {
|
||||
out, err := fakeGit("checkout", "-b", name)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, out, tag)
|
||||
assert.Empty(t, out)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user