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

fix: running goreleaser against repo with no commits (#580)

* fix: running goreleaser against repo with no commits

* test: added more asserts
This commit is contained in:
Carlos Alexandro Becker 2018-03-01 20:42:47 -03:00 committed by GitHub
parent cb864dada3
commit ac7800699f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 6 deletions

View File

@ -34,19 +34,25 @@ func (Pipe) Run(ctx *context.Context) error {
return validate(ctx)
}
var fakeInfo = context.GitInfo{
CurrentTag: "v0.0.0",
Commit: "none",
}
func getInfo(ctx *context.Context) (context.GitInfo, error) {
if !git.IsRepo() && ctx.Snapshot {
log.Warn("running against a folder that is not a git repo")
return context.GitInfo{
CurrentTag: "v0.0.0",
Commit: "none",
}, nil
log.Warn("accepting to run without a git repo because this is a snapshot")
return fakeInfo, nil
}
if !git.IsRepo() {
return context.GitInfo{}, ErrNotRepository
}
info, err := getGitInfo(ctx)
if err != nil && ctx.Snapshot {
log.WithError(err).Warn("ignoring errors because this is a snapshot")
if info.Commit == "" {
info = fakeInfo
}
return info, nil
}
return info, err
@ -60,7 +66,8 @@ func getGitInfo(ctx *context.Context) (context.GitInfo, error) {
tag, err := getTag()
if err != nil {
return context.GitInfo{
Commit: commit,
Commit: commit,
CurrentTag: "v0.0.0",
}, ErrNoTag
}
return context.GitInfo{

View File

@ -151,6 +151,17 @@ func TestSnapshotNoTags(t *testing.T) {
var ctx = context.New(config.Project{})
ctx.Snapshot = true
assert.NoError(t, Pipe{}.Run(ctx))
assert.Equal(t, fakeInfo.CurrentTag, ctx.Git.CurrentTag)
}
func TestSnapshotNoCommits(t *testing.T) {
_, back := testlib.Mktmp(t)
defer back()
testlib.GitInit(t)
var ctx = context.New(config.Project{})
ctx.Snapshot = true
assert.NoError(t, Pipe{}.Run(ctx))
assert.Equal(t, fakeInfo, ctx.Git)
}
func TestSnapshotWithoutRepo(t *testing.T) {
@ -159,6 +170,7 @@ func TestSnapshotWithoutRepo(t *testing.T) {
var ctx = context.New(config.Project{})
ctx.Snapshot = true
assert.NoError(t, Pipe{}.Run(ctx))
assert.Equal(t, fakeInfo, ctx.Git)
}
func TestSnapshotDirty(t *testing.T) {