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"
|
2017-07-23 21:42:09 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-05-26 05:48:10 +02:00
|
|
|
// GitInit inits a new git project.
|
2017-07-23 21:42:09 +02:00
|
|
|
func GitInit(t *testing.T) {
|
2017-08-19 17:47:04 +02:00
|
|
|
out, err := fakeGit("init")
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, out, "Initialized empty Git repository")
|
|
|
|
assert.NoError(t, err)
|
2017-07-23 21:42:09 +02:00
|
|
|
}
|
|
|
|
|
2020-05-26 05:48:10 +02:00
|
|
|
// GitRemoteAdd adds the given url as remote.
|
2017-07-23 21:42:09 +02:00
|
|
|
func GitRemoteAdd(t *testing.T, url string) {
|
|
|
|
out, err := fakeGit("remote", "add", "origin", url)
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Empty(t, out)
|
2017-07-23 21:42:09 +02:00
|
|
|
}
|
|
|
|
|
2020-05-26 05:48:10 +02:00
|
|
|
// GitCommit creates a git commits.
|
2017-07-23 21:42:09 +02:00
|
|
|
func GitCommit(t *testing.T, msg string) {
|
|
|
|
out, err := fakeGit("commit", "--allow-empty", "-m", msg)
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, out, "master", msg)
|
2017-07-23 21:42:09 +02:00
|
|
|
}
|
|
|
|
|
2020-05-26 05:48:10 +02:00
|
|
|
// GitTag creates a git tag.
|
2017-07-23 21:42:09 +02:00
|
|
|
func GitTag(t *testing.T, tag string) {
|
|
|
|
out, err := fakeGit("tag", tag)
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Empty(t, out)
|
2017-07-23 21:42:09 +02:00
|
|
|
}
|
|
|
|
|
2020-05-26 05:48:10 +02:00
|
|
|
// GitAdd adds all files to stage.
|
2017-07-23 21:42:09 +02:00
|
|
|
func GitAdd(t *testing.T) {
|
2017-08-19 17:47:04 +02:00
|
|
|
out, err := fakeGit("add", "-A")
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Empty(t, out)
|
2017-07-23 21:42:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func fakeGit(args ...string) (string, error) {
|
|
|
|
var allArgs = []string{
|
|
|
|
"-c", "user.name='GoReleaser'",
|
|
|
|
"-c", "user.email='test@goreleaser.github.com'",
|
|
|
|
"-c", "commit.gpgSign=false",
|
2019-02-06 21:14:04 +02:00
|
|
|
"-c", "log.showSignature=false",
|
2017-07-23 21:42:09 +02:00
|
|
|
}
|
|
|
|
allArgs = append(allArgs, args...)
|
2017-08-19 17:47:04 +02:00
|
|
|
return git.Run(allArgs...)
|
2017-07-23 21:42:09 +02:00
|
|
|
}
|
2018-10-05 21:18:39 +02:00
|
|
|
|
|
|
|
// GitCheckoutBranch allows us to change the active branch that we're using.
|
|
|
|
func GitCheckoutBranch(t *testing.T, tag string) {
|
|
|
|
out, err := fakeGit("checkout", "-b", tag)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, out, tag)
|
|
|
|
}
|