Skip to content

Commit

Permalink
Revert "feat: try to infer sub-package tag (#161)"
Browse files Browse the repository at this point in the history
This reverts commit 680777b.
  • Loading branch information
caarlos0 committed Aug 24, 2024
1 parent fc3e2dc commit 8e1fe56
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 35 deletions.
6 changes: 0 additions & 6 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ func IsRepo() bool {
return err == nil && strings.TrimSpace(out) == "true"
}

// Root returns the root of the git repository
func Root() (string, error) {
out, err := run("rev-parse", "--show-toplevel")
return strings.TrimSpace(out), err
}

func getAllTags(args ...string) ([]string, error) {
tags, err := run(append([]string{"-c", "versionsort.suffix=-", "tag", "--sort=-version:refname"}, args...)...)
if err != nil {
Expand Down
32 changes: 3 additions & 29 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ package main
import (
"fmt"
"os"
"path"
"runtime/debug"
"strings"

"github.com/alecthomas/kingpin/v2"
"github.com/caarlos0/svu/v2/internal/git"
"github.com/caarlos0/svu/v2/internal/svu"
)

Expand All @@ -21,10 +18,10 @@ var (
currentCmd = app.Command("current", "prints current version").Alias("c")
preReleaseCmd = app.Command("prerelease", "new pre release version based on the next version calculated from git log").
Alias("pr")
preRelease = app.Flag("pre-release", "adds a pre-release suffix to the version, without the semver mandatory dash prefix").
preRelease = app.Flag("pre-release", "adds a pre-release suffix to the version, without the semver mandatory dash prefix").
String()
pattern = app.Flag("pattern", "limits calculations to be based on tags matching the given pattern").Default(defaults("pattern")).String()
prefix = app.Flag("prefix", "set a custom prefix").Default(defaults("prefix")).String()
pattern = app.Flag("pattern", "limits calculations to be based on tags matching the given pattern").String()
prefix = app.Flag("prefix", "set a custom prefix").Default("v").String()
stripPrefix = app.Flag("strip-prefix", "strips the prefix from the tag").Default("false").Bool()
build = app.Flag("build", "adds a build suffix to the version, without the semver mandatory plug prefix").
String()
Expand All @@ -40,29 +37,6 @@ var (
Bool()
)

func defaults(flag string) string {
var def, pat string
switch flag {
case "prefix":
def, pat = "v", "v"
case "pattern":
def, pat = "", "*"
default:
return ""
}

cwd, wdErr := os.Getwd()
gitRoot, grErr := git.Root()
if wdErr == nil && grErr == nil && cwd != gitRoot {
prefix := strings.TrimPrefix(cwd, gitRoot)
prefix = strings.TrimPrefix(prefix, string(os.PathSeparator))
prefix = strings.TrimSuffix(prefix, string(os.PathSeparator))
return path.Join(prefix, pat)
}

return def
}

func main() {
app.Author("Carlos Alexandro Becker <[email protected]>")
app.Version(buildVersion(version, commit, date, builtBy))
Expand Down

0 comments on commit 8e1fe56

Please sign in to comment.