Skip to content

Commit

Permalink
Merge pull request #37 from dgannon991/feat/3064/defaults-for-git-com…
Browse files Browse the repository at this point in the history
…mands

Add fallbacks for git commands
  • Loading branch information
sgettys authored Apr 26, 2024
2 parents 169492a + 0cdeb4d commit 9816193
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions releases/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ func LoadMetadata() GitMetadata {

// Get the hash of the current commit
func getCommit() string {
commit, _ := must.OutputS("git", "rev-parse", "--short", "HEAD")
return commit
commit, _ := shx.OutputS("git", "rev-parse", "--short", "HEAD")
if commit != "" {
return commit
}

return "0000000"
}

// Get a description of the commit, e.g. v0.30.1 (latest) or v0.30.1-32-gfe72ff73 (canary)
Expand All @@ -80,7 +84,10 @@ func getVersion() string {

// Return either "main", "v*", or "dev" for all other branches.
func getBranchName() string {
gitOutput, _ := must.OutputS("git", "for-each-ref", "--contains", "HEAD", "--format=%(refname)")
gitOutput, _ := shx.OutputS("git", "for-each-ref", "--contains", "HEAD", "--format=%(refname)")
if gitOutput == "" {
return "dev"
}
refs := strings.Split(gitOutput, "\n")

return pickBranchName(refs)
Expand Down

0 comments on commit 9816193

Please sign in to comment.