github.com/tomsquest/goreleaser@v0.34.3-0.20171008022654-7d6ef4d338b3/internal/testlib/git.go (about)

     1  package testlib
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/goreleaser/goreleaser/internal/git"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  // GitInit inits a new git project
    11  func GitInit(t *testing.T) {
    12  	out, err := fakeGit("init")
    13  	assert.NoError(t, err)
    14  	assert.Contains(t, out, "Initialized empty Git repository")
    15  	assert.NoError(t, err)
    16  }
    17  
    18  // GitRemoteAdd adds the given url as remote
    19  func GitRemoteAdd(t *testing.T, url string) {
    20  	out, err := fakeGit("remote", "add", "origin", url)
    21  	assert.NoError(t, err)
    22  	assert.Empty(t, out)
    23  }
    24  
    25  // GitCommit creates a git commits
    26  func GitCommit(t *testing.T, msg string) {
    27  	out, err := fakeGit("commit", "--allow-empty", "-m", msg)
    28  	assert.NoError(t, err)
    29  	assert.Contains(t, out, "master", msg)
    30  }
    31  
    32  // GitTag creates a git tag
    33  func GitTag(t *testing.T, tag string) {
    34  	out, err := fakeGit("tag", tag)
    35  	assert.NoError(t, err)
    36  	assert.Empty(t, out)
    37  }
    38  
    39  // GitAdd adds all files to stage
    40  func GitAdd(t *testing.T) {
    41  	out, err := fakeGit("add", "-A")
    42  	assert.NoError(t, err)
    43  	assert.Empty(t, out)
    44  }
    45  
    46  func fakeGit(args ...string) (string, error) {
    47  	var allArgs = []string{
    48  		"-c", "user.name='GoReleaser'",
    49  		"-c", "user.email='test@goreleaser.github.com'",
    50  		"-c", "commit.gpgSign=false",
    51  	}
    52  	allArgs = append(allArgs, args...)
    53  	return git.Run(allArgs...)
    54  }