Repository: goreleaser/goreleaser
Pull request #1747 (2020-08-12 21:42:17)

fix: windows shellwords
closes #1466


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/lff413ku0
  ✅ Preview: *In Progress*
		
codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1747?src=pr&el=h1) Report
> Merging [#1747](https://codecov.io/gh/goreleaser/goreleaser/pull/1747?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/9012f61d411ac43cb3abeefd9b806aa856244b3a&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

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

```diff
@@           Coverage Diff           @@
##           master    #1747   +/-   ##
=======================================
  Coverage   82.42%   82.42%           
=======================================
  Files          72       72           
  Lines        4143     4143           
=======================================
  Hits         3415     3415           
  Misses        608      608           
  Partials      120      120           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1747?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/1747?src=pr&el=footer). Last update [9012f61...987cf59](https://codecov.io/gh/goreleaser/goreleaser/pull/1747?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..db74620c 100644
--- a/go.mod
+++ b/go.mod
@@ -23,9 +23,12 @@ 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
 	gopkg.in/yaml.v2 v2.3.0
 )
+
+// https://github.com/mattn/go-shellwords/pull/39
+replace github.com/mattn/go-shellwords => github.com/caarlos0/go-shellwords v1.0.11
diff --git a/go.sum b/go.sum
index 5fd1a735..8321f787 100644
--- a/go.sum
+++ b/go.sum
@@ -139,6 +139,8 @@ github.com/bombsimon/wsl/v3 v3.1.0 h1:E5SRssoBgtVFPcYWUOFJEcgaySgdtTNYzsSKDOY7ss
 github.com/bombsimon/wsl/v3 v3.1.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2Pm1FNZIc=
 github.com/caarlos0/ctrlc v1.0.0 h1:2DtF8GSIcajgffDFJzyG15vO+1PuBWOMUdFut7NnXhw=
 github.com/caarlos0/ctrlc v1.0.0/go.mod h1:CdXpj4rmq0q/1Eb44M9zi2nKB0QraNKuRGYGrrHhcQw=
+github.com/caarlos0/go-shellwords v1.0.11 h1:AwPv3JZPpE2YVS51HQ8IYt1Hobtmzlzw4K6ygDOsDrc=
+github.com/caarlos0/go-shellwords v1.0.11/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
 github.com/campoy/unique v0.0.0-20180121183637-88950e537e7e h1:V9a67dfYqPLAvzk5hMQOXYJlZ4SLIXgyKIE+ZiHzgGQ=
 github.com/campoy/unique v0.0.0-20180121183637-88950e537e7e/go.mod h1:9IOqJGCPMSc6E5ydlp5NIonxObaeu/Iub/X03EKPVYo=
 github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e h1:hHg27A0RSSp2Om9lubZpiMgVbvn39bsUmW9U5h0twqc=
@@ -467,8 +469,6 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
 github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
 github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
 github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
-github.com/mattn/go-shellwords v1.0.10 h1:Y7Xqm8piKOO3v10Thp7Z36h4FYFjt5xB//6XvOrs2Gw=
-github.com/mattn/go-shellwords v1.0.10/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
 github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
 github.com/mattn/go-zglob v0.0.3 h1:6Ry4EYsScDyt5di4OI6xw1bYhOqfE5S33Z1OPy+d+To=
 github.com/mattn/go-zglob v0.0.3/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo=
@@ -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)
 }