From d39f826b2e060719220887ec3834291755b491f3 Mon Sep 17 00:00:00 2001 From: John Pignata Date: Tue, 2 Jan 2018 21:06:29 -0500 Subject: [PATCH] Simplify GetShortSha() Use Cmd.Output() rather than using a buffer. --- git/main.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/git/main.go b/git/main.go index 5248353..685fa74 100644 --- a/git/main.go +++ b/git/main.go @@ -1,7 +1,6 @@ package git import ( - "bytes" "os" "os/exec" "strings" @@ -10,28 +9,24 @@ import ( ) func GetShortSha() string { - console.Debug("Finding git HEAD short SHA") + var sha string - buf := new(bytes.Buffer) cmd := exec.Command("git", "rev-parse", "--short", "HEAD") - stdout, _ := cmd.StdoutPipe() if console.Verbose { cmd.Stderr = os.Stderr } - if err := cmd.Run(); err != nil { + if out, err := cmd.Output(); err == nil { + sha = strings.TrimSpace(string(out)) + } else { console.ErrorExit(err, "Could not find git HEAD short SHA") } - buf.ReadFrom(stdout) - - return strings.TrimSpace(buf.String()) + return sha } func IsCwdGitRepo() bool { - console.Debug("Checking if current working directory is a git repository") - cmd := exec.Command("git", "rev-parse", "--is-inside-work-tree") err := cmd.Run()