Skip to content
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ version based on this table:
> alias gtn='git tag $(svu next)'
> ```

> [!NOTE]
> [Jujutsu (jj)](https://github.com/jj-vcs/jj) repositories that are not
> colocated with git are supported as well: svu reads the tags and the
> history of the working-copy commit (`@`) with the `jj` CLI, skipping commits
> without a description. Colocated repositories are read through git.

## configuration

Every flag option can also be set in a `.svu.yml` in the current
Expand Down
127 changes: 0 additions & 127 deletions internal/git/git.go

This file was deleted.

25 changes: 14 additions & 11 deletions internal/svu/svu.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"

"github.com/Masterminds/semver/v3"
"github.com/caarlos0/svu/v3/internal/git"
"github.com/caarlos0/svu/v3/internal/vcs"
)

type Action uint
Expand Down Expand Up @@ -60,7 +60,8 @@ type VersionInfo struct {
}

func Version(opts Options) (string, error) {
tag, err := git.DescribeTag(opts.Ctx, opts.TagMode, opts.Pattern)
repo := vcs.Detect(".")
tag, err := repo.DescribeTag(opts.Ctx, opts.TagMode, opts.Pattern)
if err != nil {
return "", fmt.Errorf("failed to get current tag for repo: %w", err)
}
Expand All @@ -70,7 +71,7 @@ func Version(opts Options) (string, error) {
return "", fmt.Errorf("could not get current version from tag: '%s': %w", tag, err)
}

result, err := nextVersion(current, tag, opts)
result, err := nextVersion(repo, current, tag, opts)
if err != nil {
return "", fmt.Errorf("could not get next tag: '%s': %w", tag, err)
}
Expand All @@ -83,6 +84,7 @@ func Version(opts Options) (string, error) {
}

func nextVersion(
repo vcs.Repo,
current *semver.Version,
tag string,
opts Options,
Expand All @@ -95,7 +97,7 @@ func nextVersion(
var err error
switch opts.Action {
case Next, PreRelease:
result, err = findNextWithGitLog(current, tag, opts)
result, err = findNextWithLog(repo, current, tag, opts)
case Major:
result = current.IncMajor()
case Minor:
Expand Down Expand Up @@ -199,33 +201,34 @@ func getCurrentVersion(tag, prefix string) (*semver.Version, error) {
return current, err
}

func findNextWithGitLog(
func findNextWithLog(
repo vcs.Repo,
current *semver.Version,
tag string,
opts Options,
) (semver.Version, error) {
log, err := git.Changelog(opts.Ctx, tag, opts.Directories)
log, err := repo.Changelog(opts.Ctx, tag, opts.Directories)
if err != nil {
return semver.Version{}, fmt.Errorf("failed to get changelog: %w", err)
}

return findNext(current, log, opts), nil
}

func isBreaking(commit git.Commit) bool {
func isBreaking(commit vcs.Commit) bool {
return breakingBody.MatchString(commit.Body) || breaking.MatchString(commit.Title)
}

func isFeature(commit git.Commit) bool {
func isFeature(commit vcs.Commit) bool {
return feature.MatchString(commit.Title)
}

func isPatch(commit git.Commit) bool {
func isPatch(commit vcs.Commit) bool {
return patch.MatchString(commit.Title)
}

func findNext(current *semver.Version, changes []git.Commit, opts Options) semver.Version {
var major, minor, patch *git.Commit
func findNext(current *semver.Version, changes []vcs.Commit, opts Options) semver.Version {
var major, minor, patch *vcs.Commit
for _, commit := range changes {
if isBreaking(commit) {
major = &commit
Expand Down
Loading