Skip to content

Commit

Permalink
fixup handling of git revisions for non-branch HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
cplee committed Jan 17, 2019
1 parent 20f20ed commit cb0704e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions common/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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"]
}
Expand Down

0 comments on commit cb0704e

Please sign in to comment.