Skip to content
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ tmp/
*.DS_Store

dist/

semvertool
2 changes: 1 addition & 1 deletion cmd/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var bumpCmd = &cobra.Command{
}

func init() {
rootCmd.AddCommand(bumpCmd)
bumpCmd.AddCommand(gitCmd)

cf := getCommonBumpFlags()
bumpCmd.Flags().AddFlagSet(cf)
Expand Down
15 changes: 13 additions & 2 deletions cmd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,26 @@ var gitCmd = &cobra.Command{
Run: runGit,
}

func init() {
rootCmd.AddCommand(gitCmd)
var deprecatedGitCmd = &cobra.Command{
Use: gitCmd.Use,
Short: gitCmd.Short,
Long: gitCmd.Long,
Run: gitCmd.Run,
Deprecated: "and will be removed in a future release. Use 'bump git' instead",
}

func init() {
cf := getCommonBumpFlags()
gitCmd.Flags().AddFlagSet(cf)
gitCmd.Flags().BoolP("hash", "s", false, "Append the short hash (sha) to the version as metadata information.")
gitCmd.Flags().BoolP("from-commit", "c", false, "Extract the bump type from a commit message")
gitCmd.MarkFlagsMutuallyExclusive("major", "minor", "patch", "prerelease", "from-message", "from-commit")

deprecatedGitCmd.Flags().AddFlagSet(cf)
deprecatedGitCmd.Flags().BoolP("hash", "s", false, "Append the short hash (sha) to the version as metadata information.")
deprecatedGitCmd.Flags().BoolP("from-commit", "c", false, "Extract the bump type from a commit message")
deprecatedGitCmd.MarkFlagsMutuallyExclusive("major", "minor", "patch", "prerelease", "from-message", "from-commit")

}

func gitBump(repo *goget.Repository) (*semver.Version, error) {
Expand Down
33 changes: 33 additions & 0 deletions cmd/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,39 @@ func TestInvalidVersionAndRepository(t *testing.T) {
assert.Equal(t, expected, resultStrings)
}

func TestGetTagsStringsValidVersions(t *testing.T) {
repo, err := setupRepo()
assert.NoError(t, err)

commit, err := commitFile("file1.txt", repo)
assert.NoError(t, err)

_, err = repo.CreateTag("v1.0.0", commit, nil)
assert.NoError(t, err)

commit, err = commitFile("file2.txt", repo)
assert.NoError(t, err)

_, err = repo.CreateTag("1.0.1", commit, nil)
assert.NoError(t, err)

expected := []string{"v1.0.0", "1.0.1"}
resultStrings, err := getTagsStrings(repo)

assert.NoError(t, err)
assert.Equal(t, expected, resultStrings)
}

func TestGetTagsStringsNoTags(t *testing.T) {
repo, err := setupRepo()
assert.NoError(t, err)

expected := []string{}
resultStrings, err := getTagsStrings(repo)
assert.NoError(t, err)
assert.Equal(t, expected, resultStrings)
}

func TestGitBumpNoTags(t *testing.T) {
repo, err := setupRepo()
assert.NoError(t, err)
Expand Down
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ func init() {

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.AddCommand(deprecatedGitCmd)
rootCmd.AddCommand(bumpCmd)

// Add the sort subcommand to the root command
rootCmd.AddCommand(SortCmd)
}
8 changes: 2 additions & 6 deletions cmd/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,8 @@ func RunSort(cmd *cobra.Command, args []string) error {
versions = filtered
}

ascending := true
// Sort versions
if order == "descending" || order == "dsc" {
// Sort in descending order
ascending = false
}
ascending := order == "ascending" || order == "asc"

sort.SortVersions(semver.Collection(versions), ascending)

result := VersionsToStrings(versions)
Expand Down
8 changes: 4 additions & 4 deletions cmd/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestSort_RunSortSimple(t *testing.T) {
func TestSortRunSortSimple(t *testing.T) {
args := []string{"1.0.0", "2.0.0", "1.0.1"}
expected := "1.0.0 1.0.1 2.0.0"

Expand All @@ -34,7 +34,7 @@ func TestSort_RunSortSimple(t *testing.T) {
assert.Equal(t, expected, strings.TrimSuffix(buf.String(), "\n"))
}

func TestSort_RunSortDescending(t *testing.T) {
func TestSortRunSortDescending(t *testing.T) {
args := []string{"1.0.0", "2.0.0", "1.0.1"}
expected := "2.0.0 1.0.1 1.0.0"

Expand All @@ -61,7 +61,7 @@ func TestSort_RunSortDescending(t *testing.T) {
assert.Equal(t, expected, strings.TrimSuffix(buf.String(), "\n"))
}

func TestSort_RunSortNoPrerelease(t *testing.T) {
func TestSortRunSortNoPrerelease(t *testing.T) {
args := []string{"1.0.0", "2.0.0", "1.0.1-alpha.1"}
expected := "1.0.0 2.0.0"

Expand All @@ -88,7 +88,7 @@ func TestSort_RunSortNoPrerelease(t *testing.T) {
assert.Equal(t, expected, strings.TrimSuffix(buf.String(), "\n"))
}

// func TestSort_RunSortInvalidTag(t *testing.T) {
// func TestSortRunSortInvalidTag(t *testing.T) {
// args := []string{"1.0.0", "2.0.0", "1.0.1-alpha.1", "invalid-tag"}
// expected := "invalid semver version: invalid-tag"

Expand Down