Skip to content

Commit

Permalink
fix: revert to default log order
Browse files Browse the repository at this point in the history
This works for all tested scenarios.
  • Loading branch information
smlx committed Feb 12, 2021
1 parent 21d3c7f commit 1c53db7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -37,7 +37,7 @@ func nextVersion(path string) (string, error) {
return "v0.1.0", nil
}
// walk commit hashes back from HEAD
commits, err := r.Log(&git.LogOptions{Order: git.LogOrderDFSPost})
commits, err := r.Log(&git.LogOptions{})
if err != nil {
return "", fmt.Errorf("couldn't get commits: %w", err)
}
Expand Down
55 changes: 54 additions & 1 deletion main_test.go
Expand Up @@ -63,6 +63,59 @@ func TestNextVersion(t *testing.T) {
"no existing tags chore": {gitCmds: [][]string{
{"commit", "--allow-empty", "-m", "chore: boring change"},
}, expect: "v0.1.0"},
"on a branch": {gitCmds: [][]string{
{"tag", "v0.1.0"},
{"checkout", "-b", "new-branch"},
{"commit", "--allow-empty", "-m", "fix: minor change"},
}, expect: "v0.1.1"},
"tag on a branch": {gitCmds: [][]string{
{"tag", "v0.1.0"},
{"checkout", "-b", "new-branch"},
{"commit", "--allow-empty", "-m", "fix: minor change"},
{"tag", "v0.1.1"},
{"checkout", "main"},
{"commit", "--allow-empty", "-m", "feat: minor change"},
}, expect: "v0.2.0"},
"on a branch again": {gitCmds: [][]string{
{"tag", "v0.1.0"},
{"checkout", "-b", "new-branch"},
{"commit", "--allow-empty", "-m", "fix: minor change"},
{"tag", "v0.1.1"},
{"checkout", "main"},
{"commit", "--allow-empty", "-m", "feat: minor change"},
{"tag", "v0.2.0"},
{"commit", "--allow-empty", "-m", "fix: minor change"},
}, expect: "v0.2.1"},
"back on a branch": {gitCmds: [][]string{
{"tag", "v0.1.0"},
{"checkout", "-b", "new-branch"},
{"commit", "--allow-empty", "-m", "fix: minor change"},
{"tag", "v0.1.1"},
{"checkout", "main"},
{"commit", "--allow-empty", "-m", "feat: minor change"},
{"tag", "v0.2.0"},
{"checkout", "new-branch"},
{"commit", "--allow-empty", "-m", "fix: minor change"},
}, expect: "v0.1.2"},
"main after merge": {gitCmds: [][]string{
{"tag", "v0.1.0"},
{"checkout", "-b", "new-branch"},
{"commit", "--allow-empty", "-m", "chore: boring change"},
{"commit", "--allow-empty", "-m", "fix: minor change"},
{"commit", "--allow-empty", "-m", "chore: boring change"},
{"checkout", "main"},
{"merge", "--commit", "new-branch"},
}, expect: "v0.1.1"},
"branch after merge": {gitCmds: [][]string{
{"tag", "v0.1.0"},
{"checkout", "-b", "new-branch"},
{"commit", "--allow-empty", "-m", "fix: minor change"},
{"checkout", "main"},
{"merge", "--commit", "new-branch"},
{"tag", "v0.1.2"},
{"checkout", "-b", "new-branch-2"},
{"commit", "--allow-empty", "-m", "feat: major change"},
}, expect: "v0.2.0"},
}
for name, tc := range testCases {
t.Run(name, func(tt *testing.T) {
Expand All @@ -73,7 +126,7 @@ func TestNextVersion(t *testing.T) {
}
// init git repo
initCmds := [][]string{
{"init"},
{"init", "-b", "main"},
{"commit", "--allow-empty", "-m", "feat: initial commit"},
}
for _, c := range initCmds {
Expand Down

0 comments on commit 1c53db7

Please sign in to comment.