mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
Merge branch 'master' into mattstratton/add-custom-release-title
This commit is contained in:
commit
8f71cf33a0
@ -4,8 +4,15 @@ package git
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"os/exec"
|
"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
|
// Run runs a git command and returns its output or errors
|
||||||
func Run(args ...string) (output string, err error) {
|
func Run(args ...string) (output string, err error) {
|
||||||
var cmd = exec.Command("git", args...)
|
var cmd = exec.Command("git", args...)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -20,3 +21,10 @@ func TestGit(t *testing.T) {
|
|||||||
err.Error(),
|
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")
|
||||||
|
}
|
||||||
|
@ -1,25 +1,23 @@
|
|||||||
package defaults
|
package defaults
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/config"
|
"github.com/goreleaser/goreleaser/config"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/git"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// remoteRepo gets the repo name from the Git config.
|
// remoteRepo gets the repo name from the Git config.
|
||||||
func remoteRepo() (result config.Repo, err error) {
|
func remoteRepo() (result config.Repo, err error) {
|
||||||
if _, err = os.Stat(".git"); os.IsNotExist(err) {
|
if !git.IsRepo() {
|
||||||
return result, errors.Wrap(err, "current folder is not a git repository")
|
return result, errors.New("current folder is not a git repository")
|
||||||
}
|
}
|
||||||
cmd := exec.Command("git", "config", "--get", "remote.origin.url")
|
out, err := git.Run("config", "--get", "remote.origin.url")
|
||||||
bts, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, errors.Wrap(err, "repository doesn't have an `origin` remote")
|
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 {
|
func extractRepoFromURL(s string) config.Repo {
|
||||||
|
Loading…
Reference in New Issue
Block a user