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:
parent
b8f61718f3
commit
e8fca30104
@ -16,8 +16,8 @@ func IsRepo() bool {
|
|||||||
return err == nil && strings.TrimSpace(out) == "true"
|
return err == nil && strings.TrimSpace(out) == "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunEnv runs a git command with the specified env vars and returns its output or errors.
|
// Run runs a git command and returns its output or errors.
|
||||||
func RunEnv(env map[string]string, args ...string) (string, error) {
|
func Run(args ...string) (string, error) {
|
||||||
// TODO: use exex.CommandContext here and refactor.
|
// TODO: use exex.CommandContext here and refactor.
|
||||||
extraArgs := []string{
|
extraArgs := []string{
|
||||||
"-c", "log.showSignature=false",
|
"-c", "log.showSignature=false",
|
||||||
@ -26,13 +26,6 @@ func RunEnv(env map[string]string, args ...string) (string, error) {
|
|||||||
/* #nosec */
|
/* #nosec */
|
||||||
cmd := exec.Command("git", args...)
|
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{}
|
stdout := bytes.Buffer{}
|
||||||
stderr := bytes.Buffer{}
|
stderr := bytes.Buffer{}
|
||||||
|
|
||||||
@ -53,11 +46,6 @@ func RunEnv(env map[string]string, args ...string) (string, error) {
|
|||||||
return stdout.String(), nil
|
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.
|
// Clean the output.
|
||||||
func Clean(output string, err error) (string, error) {
|
func Clean(output string, err error) (string, error) {
|
||||||
output = strings.ReplaceAll(strings.Split(output, "\n")[0], "'", "")
|
output = strings.ReplaceAll(strings.Split(output, "\n")[0], "'", "")
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"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")
|
|
||||||
}
|
|
||||||
|
@ -2,7 +2,6 @@ package testlib
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/internal/git"
|
"github.com/goreleaser/goreleaser/internal/git"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -38,19 +37,7 @@ func GitRemoteAddWithName(tb testing.TB, remote, url string) {
|
|||||||
// GitCommit creates a git commits.
|
// GitCommit creates a git commits.
|
||||||
func GitCommit(tb testing.TB, msg string) {
|
func GitCommit(tb testing.TB, msg string) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
GitCommitWithDate(tb, msg, time.Time{})
|
out, err := fakeGit("commit", "--allow-empty", "-m", msg)
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
require.NoError(tb, err)
|
require.NoError(tb, err)
|
||||||
require.Contains(tb, out, "main", msg)
|
require.Contains(tb, out, "main", msg)
|
||||||
}
|
}
|
||||||
@ -79,7 +66,7 @@ func GitAdd(tb testing.TB) {
|
|||||||
require.Empty(tb, out)
|
require.Empty(tb, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fakeGitEnv(env map[string]string, args ...string) (string, error) {
|
func fakeGit(args ...string) (string, error) {
|
||||||
allArgs := []string{
|
allArgs := []string{
|
||||||
"-c", "user.name='GoReleaser'",
|
"-c", "user.name='GoReleaser'",
|
||||||
"-c", "user.email='test@goreleaser.github.com'",
|
"-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",
|
"-c", "log.showSignature=false",
|
||||||
}
|
}
|
||||||
allArgs = append(allArgs, args...)
|
allArgs = append(allArgs, args...)
|
||||||
return git.RunEnv(env, allArgs...)
|
return git.Run(allArgs...)
|
||||||
}
|
|
||||||
|
|
||||||
func fakeGit(args ...string) (string, error) {
|
|
||||||
return fakeGitEnv(nil, args...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GitCheckoutBranch allows us to change the active branch that we're using.
|
// GitCheckoutBranch allows us to change the active branch that we're using.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user