1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

fix: check if git is present in path (#769)

This commit is contained in:
Carlos Alexandro Becker 2018-08-20 23:18:43 -03:00 committed by GitHub
parent 3b4f48c2ff
commit 3678db8ade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 3 deletions

View File

@ -1,6 +1,9 @@
package git
import "fmt"
import (
"errors"
"fmt"
)
// ErrInvalidVersionFormat is return when the version isnt in a valid format
type ErrInvalidVersionFormat struct {
@ -31,8 +34,11 @@ func (e ErrWrongRef) Error() string {
// ErrNoTag happens if the underlying git repository doesn't contain any tags
// but no snapshot-release was requested.
var ErrNoTag = fmt.Errorf("git doesn't contain any tags. Either add a tag or use --snapshot")
var ErrNoTag = errors.New("git doesn't contain any tags. Either add a tag or use --snapshot")
// ErrNotRepository happens if you try to run goreleaser against a folder
// which is not a git repository.
var ErrNotRepository = fmt.Errorf("current folder is not a git repository")
var ErrNotRepository = errors.New("current folder is not a git repository")
// ErrNoGit happens when git is not present in PATH.
var ErrNoGit = errors.New("git not present in PATH")

View File

@ -2,6 +2,7 @@ package git
import (
"fmt"
"os/exec"
"regexp"
"strings"
@ -22,6 +23,9 @@ func (Pipe) String() string {
// Run the pipe
func (Pipe) Run(ctx *context.Context) error {
if _, err := exec.LookPath("git"); err != nil {
return ErrNoGit
}
info, err := getInfo(ctx)
if err != nil {
return err

View File

@ -215,3 +215,12 @@ func TestShortCommitHash(t *testing.T) {
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
assert.Len(t, ctx.Version, 7)
}
func TestGitNotInPath(t *testing.T) {
var path = os.Getenv("PATH")
defer func() {
assert.NoError(t, os.Setenv("PATH", path))
}()
assert.NoError(t, os.Setenv("PATH", ""))
assert.EqualError(t, Pipe{}.Run(context.New(config.Project{})), ErrNoGit.Error())
}