1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/testlib/git.go

96 lines
2.4 KiB
Go
Raw Normal View History

2017-07-23 21:42:09 +02:00
package testlib
import (
"testing"
2017-08-19 17:47:04 +02:00
"github.com/goreleaser/goreleaser/internal/git"
"github.com/stretchr/testify/require"
2017-07-23 21:42:09 +02:00
)
// GitInit inits a new git project.
func GitInit(tb testing.TB) {
tb.Helper()
out, err := fakeGit("init")
require.NoError(tb, err)
require.Contains(tb, out, "Initialized empty Git repository")
require.NoError(tb, err)
GitCheckoutBranch(tb, "main")
_, _ = fakeGit("branch", "-D", "master")
2017-07-23 21:42:09 +02:00
}
// GitRemoteAdd adds the given url as remote.
func GitRemoteAdd(tb testing.TB, url string) {
tb.Helper()
2017-07-23 21:42:09 +02:00
out, err := fakeGit("remote", "add", "origin", url)
require.NoError(tb, err)
require.Empty(tb, out)
2017-07-23 21:42:09 +02:00
}
// GitRemoteAddWithName adds the given url as remote with given name.
func GitRemoteAddWithName(tb testing.TB, remote, url string) {
tb.Helper()
out, err := fakeGit("remote", "add", remote, url)
require.NoError(tb, err)
require.Empty(tb, out)
}
// GitCommit creates a git commits.
func GitCommit(tb testing.TB, msg string) {
tb.Helper()
out, err := fakeGit("commit", "--allow-empty", "-m", msg)
require.NoError(tb, err)
require.Contains(tb, out, "main", msg)
2017-07-23 21:42:09 +02:00
}
// GitTag creates a git tag.
func GitTag(tb testing.TB, tag string) {
tb.Helper()
2017-07-23 21:42:09 +02:00
out, err := fakeGit("tag", tag)
require.NoError(tb, err)
require.Empty(tb, out)
2017-07-23 21:42:09 +02:00
}
// GitAnnotatedTag creates an annotated tag.
func GitAnnotatedTag(tb testing.TB, tag, message string) {
tb.Helper()
out, err := fakeGit("tag", "-a", tag, "-m", message)
require.NoError(tb, err)
require.Empty(tb, out)
}
// GitBranch creates a git branch.
func GitBranch(tb testing.TB, branch string) {
tb.Helper()
out, err := fakeGit("branch", branch)
require.NoError(tb, err)
require.Empty(tb, out)
}
// GitAdd adds all files to stage.
func GitAdd(tb testing.TB) {
tb.Helper()
2017-08-19 17:47:04 +02:00
out, err := fakeGit("add", "-A")
require.NoError(tb, err)
require.Empty(tb, out)
2017-07-23 21:42:09 +02:00
}
func fakeGit(args ...string) (string, error) {
allArgs := []string{
2017-07-23 21:42:09 +02:00
"-c", "user.name='GoReleaser'",
"-c", "user.email='test@goreleaser.github.com'",
"-c", "commit.gpgSign=false",
"-c", "tag.gpgSign=false",
"-c", "log.showSignature=false",
2017-07-23 21:42:09 +02:00
}
allArgs = append(allArgs, args...)
return git.Run(allArgs...)
2017-07-23 21:42:09 +02:00
}
// GitCheckoutBranch allows us to change the active branch that we're using.
func GitCheckoutBranch(tb testing.TB, name string) {
tb.Helper()
out, err := fakeGit("checkout", "-b", name)
require.NoError(tb, err)
require.Empty(tb, out)
}