cloned repos shall contain all branches
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
stevensting 2024-12-26 18:08:36 +01:00
parent 161f2127d6
commit 776a8414d4

View File

@ -8,7 +8,6 @@ import (
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
) )
// Clone runs a git clone which accounts for different default branches. // Clone runs a git clone which accounts for different default branches.
@ -17,28 +16,19 @@ func Clone(dir, url string) error {
log.Debugf("%s does not exist, attempting to git clone from %s", dir, url) log.Debugf("%s does not exist, attempting to git clone from %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"), // To be able to pull recipe from any branch
SingleBranch: true, SingleBranch: false,
}) })
if err != nil { if err != nil {
log.Debugf("cloning %s default branch failed, attempting from main branch", url) if strings.Contains(err.Error(), "authentication required") {
name := filepath.Base(dir)
_, err := git.PlainClone(dir, false, &git.CloneOptions{ return fmt.Errorf("unable to clone %s, does %s exist?", name, url)
URL: url,
Tags: git.AllTags,
ReferenceName: plumbing.ReferenceName("refs/heads/main"),
SingleBranch: true,
})
if err != nil {
if strings.Contains(err.Error(), "authentication required") {
name := filepath.Base(dir)
return fmt.Errorf("unable to clone %s, does %s exist?", name, url)
}
return err
} }
return err
} }
log.Debugf("%s has been git cloned successfully", dir) log.Debugf("%s has been git cloned successfully", dir)