1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-05 13:15:26 +02:00

refactor: remove unused git.RunEnv (#2706)

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker 2021-11-28 00:22:44 -03:00 committed by GitHub
parent b8f61718f3
commit e8fca30104
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 53 deletions

View File

@ -16,8 +16,8 @@ func IsRepo() bool {
return err == nil && strings.TrimSpace(out) == "true"
}
// RunEnv runs a git command with the specified env vars and returns its output or errors.
func RunEnv(env map[string]string, args ...string) (string, error) {
// Run runs a git command and returns its output or errors.
func Run(args ...string) (string, error) {
// TODO: use exex.CommandContext here and refactor.
extraArgs := []string{
"-c", "log.showSignature=false",
@ -26,13 +26,6 @@ func RunEnv(env map[string]string, args ...string) (string, error) {
/* #nosec */
cmd := exec.Command("git", args...)
if env != nil {
cmd.Env = []string{}
for k, v := range env {
cmd.Env = append(cmd.Env, k+"="+v)
}
}
stdout := bytes.Buffer{}
stderr := bytes.Buffer{}
@ -53,11 +46,6 @@ func RunEnv(env map[string]string, args ...string) (string, error) {
return stdout.String(), nil
}
// Run runs a git command and returns its output or errors.
func Run(args ...string) (string, error) {
return RunEnv(nil, args...)
}
// Clean the output.
func Clean(output string, err error) (string, error) {
output = strings.ReplaceAll(strings.Split(output, "\n")[0], "'", "")

View File

@ -5,7 +5,6 @@ import (
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/require"
@ -335,21 +334,3 @@ func TestPreviousTagFromCI(t *testing.T) {
})
}
}
func TestCommitDate(t *testing.T) {
// round to seconds since this is expressed in a Unix timestamp
commitDate := time.Now().AddDate(-1, 0, 0).Round(1 * time.Second)
testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
testlib.GitCommitWithDate(t, "commit1", commitDate)
testlib.GitTag(t, "v0.0.1")
ctx := &context.Context{
Config: config.Project{},
}
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
require.Empty(t, ctx.Git.PreviousTag)
require.True(t, commitDate.Equal(ctx.Git.CommitDate), "commit date does not match expected")
}

View File

@ -2,7 +2,6 @@ package testlib
import (
"testing"
"time"
"github.com/goreleaser/goreleaser/internal/git"
"github.com/stretchr/testify/require"
@ -38,19 +37,7 @@ func GitRemoteAddWithName(tb testing.TB, remote, url string) {
// GitCommit creates a git commits.
func GitCommit(tb testing.TB, msg string) {
tb.Helper()
GitCommitWithDate(tb, msg, time.Time{})
}
// GitCommitWithDate creates a git commit with a commit date.
func GitCommitWithDate(tb testing.TB, msg string, commitDate time.Time) {
tb.Helper()
env := (map[string]string)(nil)
if !commitDate.IsZero() {
env = map[string]string{
"GIT_COMMITTER_DATE": commitDate.Format(time.RFC1123Z),
}
}
out, err := fakeGitEnv(env, "commit", "--allow-empty", "-m", msg)
out, err := fakeGit("commit", "--allow-empty", "-m", msg)
require.NoError(tb, err)
require.Contains(tb, out, "main", msg)
}
@ -79,7 +66,7 @@ func GitAdd(tb testing.TB) {
require.Empty(tb, out)
}
func fakeGitEnv(env map[string]string, args ...string) (string, error) {
func fakeGit(args ...string) (string, error) {
allArgs := []string{
"-c", "user.name='GoReleaser'",
"-c", "user.email='test@goreleaser.github.com'",
@ -87,11 +74,7 @@ func fakeGitEnv(env map[string]string, args ...string) (string, error) {
"-c", "log.showSignature=false",
}
allArgs = append(allArgs, args...)
return git.RunEnv(env, allArgs...)
}
func fakeGit(args ...string) (string, error) {
return fakeGitEnv(nil, args...)
return git.Run(allArgs...)
}
// GitCheckoutBranch allows us to change the active branch that we're using.