From b80b3c1ef5e079b8c66a5edfcec4f9c048168508 Mon Sep 17 00:00:00 2001 From: Ray Miller Date: Wed, 10 May 2023 12:16:31 +0100 Subject: [PATCH] Capture and print stderr from the git tag command --- main.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 79d7997..3c138e5 100644 --- a/main.go +++ b/main.go @@ -147,13 +147,12 @@ func nextVersion(inc string) func(*cli.Context) error { } } tagName := conf.versionPrefix + newVer.String() + if !c.Bool("dryrun") { + if err = createTag(tagName, conf.sign); err != nil { + return cli.Exit(err.Error(), 3) + } + } fmt.Println(tagName) - if c.Bool("dryrun") { - return nil - } - if err = createTag(tagName, conf.sign); err != nil { - return cli.Exit(err.Error(), 3) - } return nil } } @@ -264,7 +263,20 @@ func createTag(tagName string, sign bool) error { if sign { signFlag = "-s" } - return exec.Command("git", "tag", signFlag, "-m", "Version "+tagName, tagName).Run() + cmd := exec.Command("git", "tag", signFlag, "-m", "Version "+tagName, tagName) + stderr, err := cmd.StderrPipe() + if err != nil { + return err + } + if err := cmd.Start(); err != nil { + return err + } + out, _ := io.ReadAll(stderr) + fmt.Fprintf(os.Stderr, string(out)) + if err := cmd.Wait(); err != nil { + return err + } + return nil } func getVersion(versionPrefix string) (*semver.Version, error) {