From cb0704e8bfcbfcfd6fcdd529044aa33e979e6f3f Mon Sep 17 00:00:00 2001 From: Casey Lee Date: Thu, 17 Jan 2019 15:53:03 -0800 Subject: [PATCH] fixup handling of git revisions for non-branch HEAD --- common/git.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/common/git.go b/common/git.go index 7ed87bb..0335220 100644 --- a/common/git.go +++ b/common/git.go @@ -34,11 +34,19 @@ func FindGitRevision(file string) (shortSha string, sha string, err error) { if err != nil { return "", "", err } - // load commitid ref - refBuf, err := ioutil.ReadFile(fmt.Sprintf("%s/%s", gitDir, head)) - if err != nil { - return "", "", err + + var refBuf []byte + if strings.HasPrefix(head, "refs/") { + // load commitid ref + refBuf, err = ioutil.ReadFile(fmt.Sprintf("%s/%s", gitDir, head)) + if err != nil { + return "", "", err + } + } else { + refBuf = []byte(head) } + + log.Debugf("Found revision: %s", refBuf) return string(refBuf[:7]), string(refBuf), nil } @@ -82,7 +90,7 @@ func findGitHead(file string) (string, error) { head := make(map[string]string) err = yaml.Unmarshal(headBytes, head) if err != nil { - ref = string(headBytes) + ref = strings.TrimRight(string(headBytes), "\r\n") } else { ref = head["ref"] }