Skip to content

Commit 9816193

Browse files
authored
Merge pull request #37 from dgannon991/feat/3064/defaults-for-git-commands
Add fallbacks for git commands
2 parents 169492a + 0cdeb4d commit 9816193

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

releases/git.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ func LoadMetadata() GitMetadata {
6363

6464
// Get the hash of the current commit
6565
func getCommit() string {
66-
commit, _ := must.OutputS("git", "rev-parse", "--short", "HEAD")
67-
return commit
66+
commit, _ := shx.OutputS("git", "rev-parse", "--short", "HEAD")
67+
if commit != "" {
68+
return commit
69+
}
70+
71+
return "0000000"
6872
}
6973

7074
// 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 {
8084

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

8693
return pickBranchName(refs)

0 commit comments

Comments
 (0)