fix: default to main then master

This commit is contained in:
decentral1se 2025-01-05 10:37:30 +01:00
parent 3869d6bce9
commit b1a0d54bd3
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410

View File

@ -14,21 +14,22 @@ import (
// Clone runs a git clone which accounts for different default branches. // Clone runs a git clone which accounts for different default branches.
func Clone(dir, url string) error { func Clone(dir, url string) error {
if _, err := os.Stat(dir); os.IsNotExist(err) { if _, err := os.Stat(dir); os.IsNotExist(err) {
log.Debugf("%s does not exist, attempting to git clone from %s", dir, url) log.Debugf("%s does not exist, attempting git clone of %s", dir, url)
_, err := git.PlainClone(dir, false, &git.CloneOptions{ _, err := git.PlainClone(dir, false, &git.CloneOptions{
URL: url, URL: url,
Tags: git.AllTags, Tags: git.AllTags,
ReferenceName: plumbing.ReferenceName("refs/heads/master"), ReferenceName: plumbing.ReferenceName("refs/heads/main"),
SingleBranch: true, SingleBranch: true,
}) })
if err != nil { if err != nil {
log.Debugf("cloning %s default branch failed, attempting from main branch", url) log.Debug("git clone: main branch failed, attempting master branch")
_, err := git.PlainClone(dir, false, &git.CloneOptions{ _, err := git.PlainClone(dir, false, &git.CloneOptions{
URL: url, URL: url,
Tags: git.AllTags, Tags: git.AllTags,
ReferenceName: plumbing.ReferenceName("refs/heads/main"), ReferenceName: plumbing.ReferenceName("refs/heads/master"),
SingleBranch: true, SingleBranch: true,
}) })
if err != nil { if err != nil {
@ -41,9 +42,9 @@ func Clone(dir, url string) error {
} }
} }
log.Debugf("%s has been git cloned successfully", dir) log.Debugf("git clone: %s cloned successfully", dir)
} else { } else {
log.Debugf("%s already exists", dir) log.Debugf("git clone: %s already exists", dir)
} }
return nil return nil