2017-03-25 20:36:21 -03:00
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
2017-04-15 14:00:49 -03:00
|
|
|
"os"
|
2021-03-24 08:55:13 -03:00
|
|
|
"os/exec"
|
2017-04-15 16:11:47 -03:00
|
|
|
"path/filepath"
|
2017-03-25 20:36:21 -03:00
|
|
|
"testing"
|
|
|
|
|
2020-01-31 19:38:56 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2017-07-23 16:27:46 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
2018-08-14 23:50:20 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2017-03-25 20:36:21 -03:00
|
|
|
)
|
|
|
|
|
2017-03-25 20:40:45 -03:00
|
|
|
func TestDescription(t *testing.T) {
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
2017-03-25 20:40:45 -03:00
|
|
|
}
|
|
|
|
|
2017-04-15 14:00:29 -03:00
|
|
|
func TestNotAGitFolder(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2021-03-24 08:55:13 -03:00
|
|
|
ctx := &context.Context{
|
2017-04-15 13:05:54 -03:00
|
|
|
Config: config.Project{},
|
|
|
|
}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), ErrNotRepository.Error())
|
2017-04-15 13:05:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSingleCommit(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2017-07-23 16:42:09 -03:00
|
|
|
testlib.GitInit(t)
|
2018-10-04 09:38:19 -03:00
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
2017-07-23 16:42:09 -03:00
|
|
|
testlib.GitCommit(t, "commit1")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
2021-03-24 08:55:13 -03:00
|
|
|
ctx := &context.Context{
|
2017-04-15 13:05:54 -03:00
|
|
|
Config: config.Project{},
|
|
|
|
}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
2021-11-24 20:01:56 -07:00
|
|
|
require.Equal(t, "v0.0.1", ctx.Git.Summary)
|
2021-12-05 23:23:15 -03:00
|
|
|
require.Equal(t, "commit1", ctx.Git.Subject)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAnnotatedTags(t *testing.T) {
|
|
|
|
testlib.Mktmp(t)
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
|
|
|
testlib.GitCommit(t, "commit1")
|
|
|
|
testlib.GitAnnotatedTag(t, "v0.0.1", "first version")
|
|
|
|
ctx := &context.Context{
|
|
|
|
Config: config.Project{},
|
|
|
|
}
|
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
|
|
|
require.Equal(t, "first version", ctx.Git.Subject)
|
|
|
|
require.Equal(t, "v0.0.1", ctx.Git.Summary)
|
2017-04-15 13:05:54 -03:00
|
|
|
}
|
|
|
|
|
2020-11-18 19:50:31 +01:00
|
|
|
func TestBranch(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2020-11-18 19:50:31 +01:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
|
|
|
testlib.GitCommit(t, "test-branch-commit")
|
|
|
|
testlib.GitTag(t, "test-branch-tag")
|
|
|
|
testlib.GitCheckoutBranch(t, "test-branch")
|
2021-03-24 08:55:13 -03:00
|
|
|
ctx := &context.Context{
|
2020-11-18 19:50:31 +01:00
|
|
|
Config: config.Project{},
|
|
|
|
}
|
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Equal(t, "test-branch", ctx.Git.Branch)
|
2021-11-24 20:01:56 -07:00
|
|
|
require.Equal(t, "test-branch-tag", ctx.Git.Summary)
|
2020-11-18 19:50:31 +01:00
|
|
|
}
|
|
|
|
|
2018-10-04 22:47:29 -03:00
|
|
|
func TestNoRemote(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2018-10-04 22:47:29 -03:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitCommit(t, "commit1")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
2021-03-24 08:55:13 -03:00
|
|
|
ctx := &context.Context{
|
2018-10-04 22:47:29 -03:00
|
|
|
Config: config.Project{},
|
|
|
|
}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), "couldn't get remote URL: fatal: No remote configured to list refs from.")
|
2018-10-04 22:47:29 -03:00
|
|
|
}
|
|
|
|
|
2017-04-15 13:05:54 -03:00
|
|
|
func TestNewRepository(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2017-07-23 16:42:09 -03:00
|
|
|
testlib.GitInit(t)
|
2021-03-24 08:55:13 -03:00
|
|
|
ctx := &context.Context{
|
2017-04-15 13:05:54 -03:00
|
|
|
Config: config.Project{},
|
|
|
|
}
|
2018-02-24 17:59:08 -03:00
|
|
|
// TODO: improve this error handling
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Contains(t, Pipe{}.Run(ctx).Error(), `fatal: ambiguous argument 'HEAD'`)
|
2017-04-15 13:05:54 -03:00
|
|
|
}
|
|
|
|
|
2017-04-29 12:49:22 +02:00
|
|
|
// TestNoTagsNoSnapshot covers the situation where a repository
|
|
|
|
// only contains simple commits and no tags. In this case you have
|
|
|
|
// to set the --snapshot flag otherwise an error is returned.
|
|
|
|
func TestNoTagsNoSnapshot(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2017-07-23 16:42:09 -03:00
|
|
|
testlib.GitInit(t)
|
2018-10-04 09:38:19 -03:00
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
2017-07-23 16:42:09 -03:00
|
|
|
testlib.GitCommit(t, "first")
|
2021-03-24 08:55:13 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2018-02-24 17:59:08 -03:00
|
|
|
ctx.Snapshot = false
|
2020-12-22 15:04:51 +01:00
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), `git doesn't contain any tags. Either add a tag or use --snapshot`)
|
2017-04-29 12:49:22 +02:00
|
|
|
}
|
|
|
|
|
2017-04-15 16:11:47 -03:00
|
|
|
func TestDirty(t *testing.T) {
|
2021-03-24 08:55:13 -03:00
|
|
|
folder := testlib.Mktmp(t)
|
2017-07-23 16:42:09 -03:00
|
|
|
testlib.GitInit(t)
|
2018-10-04 09:38:19 -03:00
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
2017-04-15 16:11:47 -03:00
|
|
|
dummy, err := os.Create(filepath.Join(folder, "dummy"))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
2021-04-25 11:34:40 -03:00
|
|
|
require.NoError(t, dummy.Close())
|
2017-07-23 16:42:09 -03:00
|
|
|
testlib.GitAdd(t)
|
|
|
|
testlib.GitCommit(t, "commit2")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
2021-04-25 13:00:51 -03:00
|
|
|
require.NoError(t, os.WriteFile(dummy.Name(), []byte("lorem ipsum"), 0o644))
|
2018-03-08 08:42:33 -03:00
|
|
|
t.Run("all checks up", func(t *testing.T) {
|
2021-03-24 08:55:13 -03:00
|
|
|
err := Pipe{}.Run(context.New(config.Project{}))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), "git is currently in a dirty state")
|
2018-03-08 08:42:33 -03:00
|
|
|
})
|
|
|
|
t.Run("skip validate is set", func(t *testing.T) {
|
|
|
|
ctx := context.New(config.Project{})
|
|
|
|
ctx.SkipValidate = true
|
|
|
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
|
|
|
})
|
|
|
|
t.Run("snapshot", func(t *testing.T) {
|
|
|
|
ctx := context.New(config.Project{})
|
|
|
|
ctx.Snapshot = true
|
2021-03-24 08:55:13 -03:00
|
|
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-04 02:06:53 +03:00
|
|
|
func TestRemoteURLContainsWithUsernameAndToken(t *testing.T) {
|
|
|
|
testlib.Mktmp(t)
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "https://gitlab-ci-token:SyYhsAghYFTvMoxw7GAg@gitlab.private.com/platform/base/poc/kink.git/releases/tag/v0.1.4")
|
|
|
|
testlib.GitAdd(t)
|
|
|
|
testlib.GitCommit(t, "commit2")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
ctx := context.New(config.Project{})
|
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoteURLContainsWithUsernameAndTokenWithInvalidURL(t *testing.T) {
|
|
|
|
testlib.Mktmp(t)
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "https://gitlab-ci-token:SyYhsAghYFTvMoxw7GAggitlab.com/platform/base/poc/kink.git/releases/tag/v0.1.4")
|
|
|
|
testlib.GitAdd(t)
|
|
|
|
testlib.GitCommit(t, "commit2")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
ctx := context.New(config.Project{})
|
|
|
|
require.Error(t, Pipe{}.Run(ctx))
|
|
|
|
}
|
|
|
|
|
2021-03-24 08:55:13 -03:00
|
|
|
func TestShallowClone(t *testing.T) {
|
|
|
|
folder := testlib.Mktmp(t)
|
|
|
|
require.NoError(
|
|
|
|
t,
|
|
|
|
exec.Command(
|
|
|
|
"git", "clone",
|
|
|
|
"--depth", "1",
|
|
|
|
"--branch", "v0.160.0",
|
|
|
|
"https://github.com/goreleaser/goreleaser",
|
|
|
|
folder,
|
|
|
|
).Run(),
|
|
|
|
)
|
|
|
|
t.Run("all checks up", func(t *testing.T) {
|
2021-03-24 23:15:23 -03:00
|
|
|
// its just a warning now
|
|
|
|
require.NoError(t, Pipe{}.Run(context.New(config.Project{})))
|
2021-03-24 08:55:13 -03:00
|
|
|
})
|
|
|
|
t.Run("skip validate is set", func(t *testing.T) {
|
|
|
|
ctx := context.New(config.Project{})
|
|
|
|
ctx.SkipValidate = true
|
|
|
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
|
|
|
})
|
|
|
|
t.Run("snapshot", func(t *testing.T) {
|
|
|
|
ctx := context.New(config.Project{})
|
|
|
|
ctx.Snapshot = true
|
2018-03-08 08:42:33 -03:00
|
|
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
|
|
|
})
|
2017-04-15 16:11:47 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTagIsNotLastCommit(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2017-07-23 16:42:09 -03:00
|
|
|
testlib.GitInit(t)
|
2018-10-04 09:38:19 -03:00
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
2017-07-23 16:42:09 -03:00
|
|
|
testlib.GitCommit(t, "commit3")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitCommit(t, "commit4")
|
2021-11-24 20:01:56 -07:00
|
|
|
ctx := &context.Context{
|
|
|
|
Config: config.Project{},
|
|
|
|
}
|
|
|
|
err := Pipe{}.Run(ctx)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), "git tag v0.0.1 was not made against commit")
|
2021-11-24 20:01:56 -07:00
|
|
|
require.Contains(t, ctx.Git.Summary, "v0.0.1-1-g") // commit not represented because it changes every test
|
2017-04-15 16:11:47 -03:00
|
|
|
}
|
|
|
|
|
2017-04-22 10:46:58 -03:00
|
|
|
func TestValidState(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2017-07-23 16:42:09 -03:00
|
|
|
testlib.GitInit(t)
|
2018-10-04 09:38:19 -03:00
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
2017-07-23 16:42:09 -03:00
|
|
|
testlib.GitCommit(t, "commit3")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitCommit(t, "commit4")
|
|
|
|
testlib.GitTag(t, "v0.0.2")
|
2021-03-24 08:55:13 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Equal(t, "v0.0.2", ctx.Git.CurrentTag)
|
|
|
|
require.Equal(t, "git@github.com:foo/bar.git", ctx.Git.URL)
|
2017-04-22 10:46:58 -03:00
|
|
|
}
|
|
|
|
|
2018-02-25 20:17:45 -03:00
|
|
|
func TestSnapshotNoTags(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2017-07-23 16:42:09 -03:00
|
|
|
testlib.GitInit(t)
|
2018-10-04 09:38:19 -03:00
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
2017-10-15 20:21:35 -02:00
|
|
|
testlib.GitAdd(t)
|
|
|
|
testlib.GitCommit(t, "whatever")
|
2021-03-24 08:55:13 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2018-02-24 17:59:08 -03:00
|
|
|
ctx.Snapshot = true
|
2018-03-08 08:42:33 -03:00
|
|
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Equal(t, fakeInfo.CurrentTag, ctx.Git.CurrentTag)
|
2021-11-24 09:12:24 -03:00
|
|
|
require.Empty(t, ctx.Git.PreviousTag)
|
2018-03-01 20:42:47 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSnapshotNoCommits(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2018-03-01 20:42:47 -03:00
|
|
|
testlib.GitInit(t)
|
2018-10-04 09:38:19 -03:00
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
2021-03-24 08:55:13 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2018-03-01 20:42:47 -03:00
|
|
|
ctx.Snapshot = true
|
2018-03-08 08:42:33 -03:00
|
|
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Equal(t, fakeInfo, ctx.Git)
|
2017-04-19 17:31:09 -03:00
|
|
|
}
|
2018-02-24 17:59:08 -03:00
|
|
|
|
2018-02-25 20:17:45 -03:00
|
|
|
func TestSnapshotWithoutRepo(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2021-03-24 08:55:13 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2018-02-25 20:17:45 -03:00
|
|
|
ctx.Snapshot = true
|
2018-03-08 08:42:33 -03:00
|
|
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Equal(t, fakeInfo, ctx.Git)
|
2018-02-25 20:17:45 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSnapshotDirty(t *testing.T) {
|
2021-03-24 08:55:13 -03:00
|
|
|
folder := testlib.Mktmp(t)
|
2018-02-25 20:17:45 -03:00
|
|
|
testlib.GitInit(t)
|
2018-10-04 09:38:19 -03:00
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
2018-02-25 20:17:45 -03:00
|
|
|
testlib.GitAdd(t)
|
|
|
|
testlib.GitCommit(t, "whatever")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
2021-04-25 13:00:51 -03:00
|
|
|
require.NoError(t, os.WriteFile(filepath.Join(folder, "foo"), []byte("foobar"), 0o644))
|
2021-03-24 08:55:13 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2018-02-25 20:17:45 -03:00
|
|
|
ctx.Snapshot = true
|
2018-03-08 08:42:33 -03:00
|
|
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
2021-11-24 20:01:56 -07:00
|
|
|
require.Equal(t, "v0.0.1", ctx.Git.Summary)
|
2018-02-25 20:17:45 -03:00
|
|
|
}
|
2018-03-02 21:20:27 +09:00
|
|
|
|
2018-08-20 23:18:43 -03:00
|
|
|
func TestGitNotInPath(t *testing.T) {
|
2021-03-24 08:55:13 -03:00
|
|
|
path := os.Getenv("PATH")
|
2018-08-20 23:18:43 -03:00
|
|
|
defer func() {
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, os.Setenv("PATH", path))
|
2018-08-20 23:18:43 -03:00
|
|
|
}()
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, os.Setenv("PATH", ""))
|
|
|
|
require.EqualError(t, Pipe{}.Run(context.New(config.Project{})), ErrNoGit.Error())
|
2018-08-20 23:18:43 -03:00
|
|
|
}
|
2020-01-31 19:38:56 +01:00
|
|
|
|
|
|
|
func TestTagFromCI(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2020-01-31 19:38:56 +01:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
|
|
|
testlib.GitCommit(t, "commit1")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitTag(t, "v0.0.2")
|
|
|
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
envs map[string]string
|
|
|
|
expected string
|
|
|
|
}{
|
2021-08-02 17:20:09 +01:00
|
|
|
{expected: "v0.0.2"},
|
2020-01-31 19:38:56 +01:00
|
|
|
{
|
|
|
|
envs: map[string]string{"GORELEASER_CURRENT_TAG": "v0.0.2"},
|
|
|
|
expected: "v0.0.2",
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
for name, value := range tc.envs {
|
|
|
|
require.NoError(t, os.Setenv(name, value))
|
|
|
|
}
|
|
|
|
|
2021-03-24 08:55:13 -03:00
|
|
|
ctx := &context.Context{
|
2020-01-31 19:38:56 +01:00
|
|
|
Config: config.Project{},
|
|
|
|
}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Equal(t, tc.expected, ctx.Git.CurrentTag)
|
2020-01-31 19:38:56 +01:00
|
|
|
|
|
|
|
for name := range tc.envs {
|
|
|
|
require.NoError(t, os.Setenv(name, ""))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-06 16:09:22 -04:00
|
|
|
|
2021-11-24 09:12:24 -03:00
|
|
|
func TestNoPreviousTag(t *testing.T) {
|
|
|
|
testlib.Mktmp(t)
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
|
|
|
testlib.GitCommit(t, "commit1")
|
|
|
|
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, "should be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPreviousTagFromCI(t *testing.T) {
|
|
|
|
testlib.Mktmp(t)
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
|
|
|
testlib.GitCommit(t, "commit1")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitCommit(t, "commit2")
|
|
|
|
testlib.GitTag(t, "v0.0.2")
|
|
|
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
envs map[string]string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{expected: "v0.0.1"},
|
|
|
|
{
|
|
|
|
envs: map[string]string{"GORELEASER_PREVIOUS_TAG": "v0.0.2"},
|
|
|
|
expected: "v0.0.2",
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tc.expected, func(t *testing.T) {
|
|
|
|
for name, value := range tc.envs {
|
|
|
|
require.NoError(t, os.Setenv(name, value))
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := &context.Context{
|
|
|
|
Config: config.Project{},
|
|
|
|
}
|
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Equal(t, tc.expected, ctx.Git.PreviousTag)
|
|
|
|
|
|
|
|
for name := range tc.envs {
|
|
|
|
require.NoError(t, os.Setenv(name, ""))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|