From 0cdeb4d3888fa7d4c4513127ce8cd31b9265b0d6 Mon Sep 17 00:00:00 2001 From: David <19214156+dgannon991@users.noreply.github.com> Date: Tue, 9 Apr 2024 21:04:18 +0100 Subject: [PATCH] Add fallbacks for git commands Signed-off-by: David <19214156+dgannon991@users.noreply.github.com> --- releases/git.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/releases/git.go b/releases/git.go index 69c5bd4..857d8fd 100644 --- a/releases/git.go +++ b/releases/git.go @@ -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) @@ -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)