From 5d60e0ca4d1d71b88d29c10af06d34e88154d431 Mon Sep 17 00:00:00 2001 From: Ray Miller Date: Wed, 10 May 2023 14:08:26 +0100 Subject: [PATCH] Improved and simplified error handling around execution of git commands. --- main.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 3c138e5..5ce5b71 100644 --- a/main.go +++ b/main.go @@ -263,25 +263,18 @@ func createTag(tagName string, sign bool) error { if sign { signFlag = "-s" } - cmd := exec.Command("git", "tag", signFlag, "-m", "Version "+tagName, tagName) - stderr, err := cmd.StderrPipe() + out, err := exec.Command("git", "tag", signFlag, "-m", "Version "+tagName, tagName).CombinedOutput() 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 { + fmt.Fprintln(os.Stderr, string(out)) return err } return nil } func getVersion(versionPrefix string) (*semver.Version, error) { - out, err := exec.Command("git", "tag").Output() + out, err := exec.Command("git", "tag").CombinedOutput() if err != nil { + fmt.Fprintln(os.Stderr, string(out)) return nil, err } var latest *semver.Version