diff --git a/chglog_test.go b/chglog_test.go index ad2be0b..1828fa8 100644 --- a/chglog_test.go +++ b/chglog_test.go @@ -95,9 +95,63 @@ func TestGeneratorNotFoundCommits(t *testing.T) { }, }) + buf := &bytes.Buffer{} + err := gen.Generate(buf, "foo") + assert.Error(err) + assert.Equal("", buf.String()) +} + +func TestGeneratorNotFoundCommitsOne(t *testing.T) { + assert := assert.New(t) + testName := "not_found" + + setup(testName, func(git gitcmd.Client) { + git.Exec("commit", "--allow-empty", "--date", "Mon Jan 1 00:00:00 2018 +0000", "-m", "chore(*): First commit") + }) + + gen := NewGenerator(&Config{ + Bin: "git", + WorkingDir: filepath.Join(testRepoRoot, testName), + Template: filepath.Join(cwd, "testdata", testName+".md"), + Info: &Info{ + RepositoryURL: "/~https://github.com/git-chglog/git-chglog", + }, + Options: &Options{ + CommitFilters: map[string][]string{}, + CommitSortBy: "Scope", + CommitGroupBy: "Type", + CommitGroupSortBy: "Title", + CommitGroupTitleMaps: map[string]string{}, + HeaderPattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$", + HeaderPatternMaps: []string{ + "Type", + "Scope", + "Subject", + }, + IssuePrefix: []string{ + "#", + "gh-", + }, + RefActions: []string{}, + MergePattern: "^Merge pull request #(\\d+) from (.*)$", + MergePatternMaps: []string{ + "Ref", + "Source", + }, + RevertPattern: "^Revert \"([\\s\\S]*)\"$", + RevertPatternMaps: []string{ + "Header", + }, + NoteKeywords: []string{ + "BREAKING CHANGE", + }, + }, + }) + buf := &bytes.Buffer{} err := gen.Generate(buf, "foo") assert.Contains(err.Error(), "\"foo\" was not found") + assert.Error(err) assert.Equal("", buf.String()) } diff --git a/tag_reader.go b/tag_reader.go index 7c8aa62..5cb3584 100644 --- a/tag_reader.go +++ b/tag_reader.go @@ -1,6 +1,7 @@ package chglog import ( + "fmt" "regexp" "strconv" "strings" @@ -33,7 +34,7 @@ func (r *tagReader) ReadAll() ([]*Tag, error) { tags := []*Tag{} if err != nil { - return tags, err + return tags, fmt.Errorf("failed to get git-tag: %s", err.Error()) } lines := strings.Split(out, "\n")