0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-24 21:20:40 +00:00

feat: add flag to create local tag only (#14)

This commit is contained in:
Robert Kaussow 2023-10-18 16:09:13 +02:00 committed by GitHub
parent aafeb36d4a
commit a2f25f042e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -152,19 +152,23 @@ func (g GitSV) Commit(header, body, footer string) error {
} }
// Tag create a git tag. // 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()) 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()) tagMsg := fmt.Sprintf("Version %d.%d.%d", version.Major(), version.Minor(), version.Patch())
tagCommand := exec.Command("git", "tag", tag) tagCommand := exec.Command("git", "tag", tag)
if annotate { 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 { if out, err := tagCommand.CombinedOutput(); err != nil {
return tag, combinedOutputErr(err, out) return tag, combinedOutputErr(err, out)
} }
if local {
return tag, nil
}
pushCommand := exec.Command("git", "push", "origin", tag) pushCommand := exec.Command("git", "push", "origin", tag)
if out, err := pushCommand.CombinedOutput(); err != nil { if out, err := pushCommand.CombinedOutput(); err != nil {
return tag, combinedOutputErr(err, out) return tag, combinedOutputErr(err, out)

View File

@ -14,9 +14,14 @@ func TagFlags(settings *app.TagSettings) []cli.Flag {
&cli.BoolFlag{ &cli.BoolFlag{
Name: "annotate", Name: "annotate",
Aliases: []string{"a"}, Aliases: []string{"a"},
Usage: "ignore size parameter, get changelog for every tag", Usage: "make an annotated tag object",
Destination: &settings.Annotate, Destination: &settings.Annotate,
}, },
&cli.BoolFlag{
Name: "local",
Usage: "create local tag only",
Destination: &settings.Local,
},
} }
} }
@ -41,7 +46,7 @@ func TagHandler(g app.GitSV, settings *app.TagSettings) cli.ActionFunc {
return nil return nil
} }
tagname, err := g.Tag(*nextVer, settings.Annotate) tagname, err := g.Tag(*nextVer, settings.Annotate, settings.Local)
if err != nil { if err != nil {
return fmt.Errorf("error generating tag version: %s: %w", nextVer.String(), err) return fmt.Errorf("error generating tag version: %s: %w", nextVer.String(), err)
} }

View File

@ -51,6 +51,7 @@ type CommitLogSettings struct {
type TagSettings struct { type TagSettings struct {
Annotate bool Annotate bool
Local bool
} }
// Config cli yaml config. // Config cli yaml config.