Skip to content

Commit

Permalink
fix: Fix error message when Tag can not be acquired
Browse files Browse the repository at this point in the history
  • Loading branch information
wadackel committed Feb 23, 2018
1 parent 96562bc commit b01be88
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
54 changes: 54 additions & 0 deletions chglog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
3 changes: 2 additions & 1 deletion tag_reader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chglog

import (
"fmt"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit b01be88

Please sign in to comment.