diff --git a/git/tag.go b/git/tag.go index bd54c01f6..d09fd0518 100644 --- a/git/tag.go +++ b/git/tag.go @@ -21,8 +21,10 @@ func getTag(ref string) (tag string, err error) { "--tags", "--abbrev=0", "--always", - ref, ) + if ref != "" { + cmd.Args = append(cmd.Args, ref) + } bts, err := cmd.CombinedOutput() if err != nil { return tag, errors.New(err.Error() + ": " + string(bts)) diff --git a/git/tag_test.go b/git/tag_test.go index aace09652..6b2296852 100644 --- a/git/tag_test.go +++ b/git/tag_test.go @@ -17,4 +17,11 @@ func TestPreviousTag(t *testing.T) { tag, err := PreviousTag("v0.0.1") assert.NoError(err) assert.NotEmpty(tag) -} \ No newline at end of file +} + +func TestInvalidRef(t *testing.T) { + assert := assert.New(t) + tag, err := PreviousTag("this-should-not-exist") + assert.Error(err) + assert.Empty(tag) +}