Skip to content

Commit 12fbefd

Browse files
committed
feat: add version file and tag conflict handling
1 parent 417d823 commit 12fbefd

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

.version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.0.6

cmds/fastcommit/cmd.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"sort"
8+
"strings"
89
"time"
910

1011
"github.com/briandowns/spinner"
@@ -82,6 +83,14 @@ func New(params Params) *Command {
8283

8384
cmdutils.LoadConfigAndBranch()
8485

86+
allTags := utils.GetAllGitTags()
87+
tagName := "v0.0.1"
88+
if len(allTags) > 0 {
89+
ver := utils.GetNextReleaseTag(allTags)
90+
tagName = "v" + strings.TrimPrefix(ver.Original(), "v")
91+
}
92+
assert.Exit(os.WriteFile(".version", []byte(tagName), 0644))
93+
8594
generatePrompt := utils.GeneratePrompt("en", 50, utils.ConventionalCommitType)
8695

8796
repoPath := assert.Must1(utils.AssertGitRepo())

cmds/tagcmd/cmd.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,7 @@ func New() *cli.Command {
2525
defer recovery.Exit()
2626

2727
cmdutils.LoadConfigAndBranch()
28-
29-
s := spinner.New(spinner.CharSets[35], 100*time.Millisecond, func(s *spinner.Spinner) {
30-
s.Prefix = "fetch git tag: "
31-
})
32-
s.Start()
33-
utils.GitFetchAll()
34-
s.Stop()
35-
28+
3629
var p = tea.NewProgram(initialModel())
3730
m := assert.Must1(p.Run()).(model)
3831
selected := strings.TrimSpace(m.selected)
@@ -59,7 +52,15 @@ func New() *cli.Command {
5952
return errors.Errorf("tag name is not valid: %s", tagName)
6053
}
6154

62-
utils.GitPushTag(tagName)
55+
output := utils.GitPushTag(tagName)
56+
if utils.IsRemoteTagExist(output) {
57+
s := spinner.New(spinner.CharSets[35], 100*time.Millisecond, func(s *spinner.Spinner) {
58+
s.Prefix = "fetch git tag: "
59+
})
60+
s.Start()
61+
utils.GitFetchAll()
62+
s.Stop()
63+
}
6364

6465
return nil
6566
},

utils/git.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ func GetDetectedMessage(files []string) string {
7878
return fmt.Sprintf("detected %d staged file%s", fileCount, pluralSuffix)
7979
}
8080

81-
func GitPushTag(ver string) {
81+
func GitPushTag(ver string) string {
8282
if ver == "" {
83-
return
83+
return ""
8484
}
8585

8686
log.Info().Msg("git push tag " + ver)
8787
assert.Must(RunShell("git", "tag", ver))
88-
assert.Must(RunShell("git", "push", "origin", ver))
88+
return assert.Exit1(RunOutput("git", "push", "origin", ver))
8989
}
9090

9191
func GitFetchAll() {
92-
assert.Must(RunShell("git", "fetch", "--tags"))
92+
assert.Must(RunShell("git", "fetch", "--prune", "--tags"))
9393
}
9494

9595
func IsDirty() (r result.Result[bool]) {

utils/util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,7 @@ func RunOutput(args ...string) (string, error) {
168168
log.Info().Msg("shell: " + strings.TrimSpace(shell))
169169
return script.Exec(shell).String()
170170
}
171+
172+
func IsRemoteTagExist(err string) bool {
173+
return strings.Contains(err, "[rejected]") && strings.Contains(err, "tag already exists")
174+
}

0 commit comments

Comments
 (0)