2020-07-09 16:40:37 -04:00
|
|
|
package git_test
|
2017-08-19 12:47:04 -03:00
|
|
|
|
|
|
|
import (
|
2017-10-16 15:43:26 -02:00
|
|
|
"os"
|
2017-08-19 12:47:04 -03:00
|
|
|
"testing"
|
|
|
|
|
2020-07-09 16:40:37 -04:00
|
|
|
"github.com/goreleaser/goreleaser/internal/git"
|
2020-08-14 10:12:55 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
2020-10-06 09:48:04 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-08-19 12:47:04 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGit(t *testing.T) {
|
2020-07-09 16:40:37 -04:00
|
|
|
out, err := git.Run("status")
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, out)
|
2017-08-19 12:47:04 -03:00
|
|
|
|
2020-07-09 16:40:37 -04:00
|
|
|
out, err = git.Run("command-that-dont-exist")
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Error(t, err)
|
|
|
|
require.Empty(t, out)
|
|
|
|
require.Equal(
|
2017-09-26 19:24:49 -03:00
|
|
|
t,
|
2017-08-19 12:47:04 -03:00
|
|
|
"git: 'command-that-dont-exist' is not a git command. See 'git --help'.\n",
|
|
|
|
err.Error(),
|
|
|
|
)
|
|
|
|
}
|
2017-10-16 15:43:26 -02:00
|
|
|
|
2020-08-14 10:12:55 -03:00
|
|
|
func TestGitWarning(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2020-08-14 10:12:55 -03:00
|
|
|
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^")
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "1.2.2\n", out)
|
2020-08-14 10:12:55 -03:00
|
|
|
}
|
|
|
|
|
2017-10-16 15:43:26 -02:00
|
|
|
func TestRepo(t *testing.T) {
|
2020-10-06 09:48:04 -03:00
|
|
|
require.True(t, git.IsRepo(), "goreleaser folder should be a git repo")
|
2017-10-16 15:43:26 -02:00
|
|
|
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, os.Chdir(os.TempDir()))
|
|
|
|
require.False(t, git.IsRepo(), os.TempDir()+" folder should be a git repo")
|
2017-10-16 15:43:26 -02:00
|
|
|
}
|
2017-10-15 20:47:52 -02:00
|
|
|
|
|
|
|
func TestClean(t *testing.T) {
|
2020-07-09 16:40:37 -04:00
|
|
|
out, err := git.Clean("asdasd 'ssadas'\nadasd", nil)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "asdasd ssadas", out)
|
2018-02-25 20:17:45 -03:00
|
|
|
|
2020-07-09 16:40:37 -04:00
|
|
|
out, err = git.Clean(git.Run("command-that-dont-exist"))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Error(t, err)
|
|
|
|
require.Empty(t, out)
|
|
|
|
require.Equal(
|
2018-02-25 20:17:45 -03:00
|
|
|
t,
|
|
|
|
"git: 'command-that-dont-exist' is not a git command. See 'git --help'.",
|
|
|
|
err.Error(),
|
|
|
|
)
|
2017-10-15 20:47:52 -02:00
|
|
|
}
|