Repository: goreleaser/goreleaser
Pull request #1740 (2020-08-11 21:34:41)

fix: ignore git warnings
should avoid issues like https://github.com/goreleaser/goreleaser/issues/1734, although I'm not sure how to reproduce it (and therefore write a test for it).

vercel[bot]: 
This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).
To see the status of your deployment, click below or on the icon next to each commit.

  🔍 Inspect: https://vercel.com/goreleaser/goreleaser/aatjapp90
  ✅ Preview: *In Progress*
		
caarlos0: found a reproducible, added a test.
codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1740?src=pr&el=h1) Report
> Merging [#1740](https://codecov.io/gh/goreleaser/goreleaser/pull/1740?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/bc940a90529ac9f6cf42c41081ae14a6534dcf2d&el=desc) will **increase** coverage by `0.03%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/1740/graphs/tree.svg?width=650&height=150&src=pr&token=3bJvv6b7hN)](https://codecov.io/gh/goreleaser/goreleaser/pull/1740?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1740      +/-   ##
==========================================
+ Coverage   82.42%   82.46%   +0.03%     
==========================================
  Files          72       72              
  Lines        4143     4152       +9     
==========================================
+ Hits         3415     3424       +9     
  Misses        608      608              
  Partials      120      120              
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/1740?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [internal/git/git.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1740/diff?src=pr&el=tree#diff-aW50ZXJuYWwvZ2l0L2dpdC5nbw==) | `100.00% <100.00%> (ø)` | |
| [internal/testlib/git.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1740/diff?src=pr&el=tree#diff-aW50ZXJuYWwvdGVzdGxpYi9naXQuZ28=) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1740?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1740?src=pr&el=footer). Last update [bc940a9...686b2f3](https://codecov.io/gh/goreleaser/goreleaser/pull/1740?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/go.mod b/go.mod
index b38c5893..95fa26df 100644
--- a/go.mod
+++ b/go.mod
@@ -23,7 +23,7 @@ require (
 	github.com/spf13/cobra v1.0.0
 	github.com/stretchr/testify v1.6.1
 	github.com/ulikunitz/xz v0.5.7
-	github.com/xanzy/go-gitlab v0.35.0
+	github.com/xanzy/go-gitlab v0.35.1
 	gocloud.dev v0.20.0
 	golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
 	golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
diff --git a/go.sum b/go.sum
index 5fd1a735..b6bad483 100644
--- a/go.sum
+++ b/go.sum
@@ -652,8 +652,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
 github.com/valyala/fasthttp v1.12.0/go.mod h1:229t1eWu9UXTPmoUkbpN/fctKPBY4IJoFXQnxHGXy6E=
 github.com/valyala/quicktemplate v1.5.1/go.mod h1:v7yYWpBEiutDyNfVaph6oC/yKwejzVyTX/2cwwHxyok=
 github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
-github.com/xanzy/go-gitlab v0.35.0 h1:4CdE2FcOj5WxFkILL0s82+6I8/t0ZleEECm/42E1/30=
-github.com/xanzy/go-gitlab v0.35.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
+github.com/xanzy/go-gitlab v0.35.1 h1:jJSgT0NxjCvrSZf7Gvn2NxxV9xAYkTjYrKW8XwWhrfY=
+github.com/xanzy/go-gitlab v0.35.1/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
 github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
 github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
 github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
diff --git a/internal/git/git.go b/internal/git/git.go
index 4e721018..fb86b7c2 100644
--- a/internal/git/git.go
+++ b/internal/git/git.go
@@ -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.


Test patch:
diff --git a/internal/git/git_test.go b/internal/git/git_test.go
index 2e3d0a5f..170b1128 100644
--- a/internal/git/git_test.go
+++ b/internal/git/git_test.go
@@ -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")
 
diff --git a/internal/testlib/git.go b/internal/testlib/git.go
index 4407c472..a950224f 100644
--- a/internal/testlib/git.go
+++ b/internal/testlib/git.go
@@ -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)
 }