From 6e94482a232cfd92a078b90fe794642c48dc2dba Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 30 Jan 2017 23:46:28 -0200 Subject: [PATCH] git status if fail closes #108 --- .travis.yml | 5 +---- pipeline/source/source.go | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 719bef157..6ab716011 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,6 @@ install: make setup script: - make ci after_success: - - test -n "$TRAVIS_TAG" && gem install fpm - - git status -sb - - test -n "$TRAVIS_TAG" && go run main.go - - git status -sb + - test -n "$TRAVIS_TAG" && gem install fpm && go run main.go notifications: email: false diff --git a/pipeline/source/source.go b/pipeline/source/source.go index 1d3acb729..2caad4cdf 100644 --- a/pipeline/source/source.go +++ b/pipeline/source/source.go @@ -4,17 +4,28 @@ package source import ( - "errors" "os/exec" "github.com/goreleaser/goreleaser/context" ) // ErrDirty happens when the repo has uncommitted/unstashed changes -var ErrDirty = errors.New("git is currently in a dirty state, commit or stash your changes to continue") +type ErrDirty struct { + status string +} + +func (e ErrDirty) Error() string { + return "git is currently in a dirty state: " + e.status +} // ErrWrongRef happens when the HEAD reference is different from the tag being built -var ErrWrongRef = errors.New("current tag ref is different from HEAD ref, checkout the latest tag to continue") +type ErrWrongRef struct { + status string +} + +func (e ErrWrongRef) Error() string { + return "current tag ref is different from HEAD ref: " + e.status +} // Pipe to make sure we are in the latest Git tag as source. type Pipe struct{} @@ -29,12 +40,28 @@ func (p Pipe) Description() string { func (p Pipe) Run(ctx *context.Context) error { cmd := exec.Command("git", "diff-index", "--quiet", "HEAD", "--") if err := cmd.Run(); err != nil { - return ErrDirty + status, err := status() + if err != nil { + return err + } + return ErrDirty{status} } cmd = exec.Command("git", "describe", "--exact-match", "--tags", "--match", ctx.Git.CurrentTag) if err := cmd.Run(); err != nil { - return ErrWrongRef + status, err := status() + if err != nil { + return err + } + return ErrWrongRef{status} } return nil } + +func status() (string, error) { + bts, err := exec.Command("git", "status", "-sb").CombinedOutput() + if err != nil { + return "", err + } + return "\n\n" + string(bts), nil +}