Skip to content

Commit

Permalink
feat: add flag to create local tag only (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys authored Oct 18, 2023
1 parent aafeb36 commit a2f25f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,23 @@ func (g GitSV) Commit(header, body, footer string) error {
}

// Tag create a git tag.
func (g GitSV) Tag(version semver.Version, annotate bool) (string, error) {
func (g GitSV) Tag(version semver.Version, annotate, local bool) (string, error) {
tag := fmt.Sprintf(*g.Config.Tag.Pattern, version.Major(), version.Minor(), version.Patch())
tagMsg := fmt.Sprintf("Version %d.%d.%d", version.Major(), version.Minor(), version.Patch())

tagCommand := exec.Command("git", "tag", tag)
if annotate {
tagCommand = exec.Command("git", "tag", "-a", tag, "-m", tagMsg)
tagCommand.Args = append(tagCommand.Args, "-a", "-m", tagMsg)
}

if out, err := tagCommand.CombinedOutput(); err != nil {
return tag, combinedOutputErr(err, out)
}

if local {
return tag, nil
}

pushCommand := exec.Command("git", "push", "origin", tag)
if out, err := pushCommand.CombinedOutput(); err != nil {
return tag, combinedOutputErr(err, out)
Expand Down
9 changes: 7 additions & 2 deletions app/commands/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ func TagFlags(settings *app.TagSettings) []cli.Flag {
&cli.BoolFlag{
Name: "annotate",
Aliases: []string{"a"},
Usage: "ignore size parameter, get changelog for every tag",
Usage: "make an annotated tag object",
Destination: &settings.Annotate,
},
&cli.BoolFlag{
Name: "local",
Usage: "create local tag only",
Destination: &settings.Local,
},
}
}

Expand All @@ -41,7 +46,7 @@ func TagHandler(g app.GitSV, settings *app.TagSettings) cli.ActionFunc {
return nil
}

tagname, err := g.Tag(*nextVer, settings.Annotate)
tagname, err := g.Tag(*nextVer, settings.Annotate, settings.Local)
if err != nil {
return fmt.Errorf("error generating tag version: %s: %w", nextVer.String(), err)
}
Expand Down
1 change: 1 addition & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type CommitLogSettings struct {

type TagSettings struct {
Annotate bool
Local bool
}

// Config cli yaml config.
Expand Down

0 comments on commit a2f25f0

Please sign in to comment.