1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00

Merge branch 'master' into mattstratton/add-custom-release-title

This commit is contained in:
Matt Stratton 2017-10-16 13:57:04 -05:00 committed by GitHub
commit 8f71cf33a0
3 changed files with 20 additions and 7 deletions

View File

@ -4,8 +4,15 @@ package git
import (
"errors"
"os/exec"
"strings"
)
// IsRepo returns true if current folder is a git repository
func IsRepo() bool {
out, err := Run("rev-parse", "--is-inside-work-tree")
return err == nil && strings.TrimSpace(out) == "true"
}
// Run runs a git command and returns its output or errors
func Run(args ...string) (output string, err error) {
var cmd = exec.Command("git", args...)

View File

@ -1,6 +1,7 @@
package git
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
@ -20,3 +21,10 @@ func TestGit(t *testing.T) {
err.Error(),
)
}
func TestRepo(t *testing.T) {
assert.True(t, IsRepo(), "goreleaser folder should be a git repo")
assert.NoError(t, os.Chdir(os.TempDir()))
assert.False(t, IsRepo(), os.TempDir()+" folder should be a git repo")
}

View File

@ -1,25 +1,23 @@
package defaults
import (
"os"
"os/exec"
"strings"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/internal/git"
"github.com/pkg/errors"
)
// remoteRepo gets the repo name from the Git config.
func remoteRepo() (result config.Repo, err error) {
if _, err = os.Stat(".git"); os.IsNotExist(err) {
return result, errors.Wrap(err, "current folder is not a git repository")
if !git.IsRepo() {
return result, errors.New("current folder is not a git repository")
}
cmd := exec.Command("git", "config", "--get", "remote.origin.url")
bts, err := cmd.CombinedOutput()
out, err := git.Run("config", "--get", "remote.origin.url")
if err != nil {
return result, errors.Wrap(err, "repository doesn't have an `origin` remote")
}
return extractRepoFromURL(string(bts)), nil
return extractRepoFromURL(out), nil
}
func extractRepoFromURL(s string) config.Repo {