Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert to default log order #19

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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