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

fixed first release log

This commit is contained in:
Carlos Alexandro Becker 2017-04-23 16:33:44 -03:00
parent 3c9a8abb6e
commit 0382ef24f3
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 55 additions and 5 deletions

View File

@ -93,11 +93,20 @@ func getChangelog(tag string) (string, error) {
if err != nil {
return "", err
}
return git("log", "--pretty=oneline", "--abbrev-commit", prev+".."+tag)
if !prev.Tag {
return gitLog(prev.SHA, tag)
}
return gitLog(fmt.Sprintf("%v..%v", prev.SHA, tag))
}
func gitLog(refs ...string) (string, error) {
var args = []string{"log", "--pretty=oneline", "--abbrev-commit"}
args = append(args, refs...)
return git(args...)
}
func getInfo() (tag, commit string, err error) {
tag, err = cleanGit("describe", "--tags", "--abbrev=0", "--always")
tag, err = cleanGit("describe", "--tags", "--abbrev=0")
if err != nil {
return
}
@ -105,10 +114,21 @@ func getInfo() (tag, commit string, err error) {
return
}
func previous(tag string) (previous string, err error) {
previous, err = cleanGit("describe", "--tags", "--abbrev=0", "--always", tag+"^")
func previous(tag string) (r ref, err error) {
var previous string
var istag = true
previous, err = cleanGit("describe", "--tags", "--abbrev=0", tag+"^")
if err != nil {
istag = false
previous, err = cleanGit("rev-list", "--max-parents=0", "HEAD")
}
return
return ref{
Tag: istag,
SHA: previous,
}, err
}
type ref struct {
Tag bool
SHA string
}

View File

@ -2,6 +2,7 @@ package git
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"testing"
@ -144,16 +145,45 @@ func TestChangelog(t *testing.T) {
gitCommit(t, "added feature 1")
gitCommit(t, "fixed bug 2")
gitTag(t, "v0.0.2")
s, _ := git("log", "--oneline")
log.Println("\n" + s)
var ctx = &context.Context{
Config: config.Project{},
}
assert.NoError(Pipe{}.Run(ctx))
assert.Equal("v0.0.2", ctx.Git.CurrentTag)
assert.Contains(ctx.ReleaseNotes, "## Changelog")
assert.NotContains(ctx.ReleaseNotes, "first")
assert.Contains(ctx.ReleaseNotes, "added feature 1")
assert.Contains(ctx.ReleaseNotes, "fixed bug 2")
}
func TestChangelogOfFirstRelease(t *testing.T) {
var assert = assert.New(t)
_, back := createAndChdir(t)
defer back()
gitInit(t)
var msgs = []string{
"initial commit",
"another one",
"one more",
"and finally this one",
}
for _, msg := range msgs {
gitCommit(t, msg)
}
gitTag(t, "v0.0.1")
var ctx = &context.Context{
Config: config.Project{},
}
assert.NoError(Pipe{}.Run(ctx))
assert.Equal("v0.0.1", ctx.Git.CurrentTag)
assert.Contains(ctx.ReleaseNotes, "## Changelog")
for _, msg := range msgs {
assert.Contains(ctx.ReleaseNotes, msg)
}
}
func TestCustomReleaseNotes(t *testing.T) {
var assert = assert.New(t)
_, back := createAndChdir(t)