File tree Expand file tree Collapse file tree 5 files changed +28
-13
lines changed Expand file tree Collapse file tree 5 files changed +28
-13
lines changed Original file line number Diff line number Diff line change 1+ v0.0.6
Original file line number Diff line number Diff line change 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 ())
Original file line number Diff line number Diff 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 },
Original file line number Diff line number Diff 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
9191func GitFetchAll () {
92- assert .Must (RunShell ("git" , "fetch" , "--tags" ))
92+ assert .Must (RunShell ("git" , "fetch" , "--prune" , "-- tags" ))
9393}
9494
9595func IsDirty () (r result.Result [bool ]) {
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments