abra/pkg/git/clone.go
stevensting 776a8414d4
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
cloned repos shall contain all branches
2024-12-26 18:08:36 +01:00

41 lines
871 B
Go

package git
import (
"fmt"
"os"
"path/filepath"
"strings"
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
)
// Clone runs a git clone which accounts for different default branches.
func Clone(dir, url string) error {
if _, err := os.Stat(dir); os.IsNotExist(err) {
log.Debugf("%s does not exist, attempting to git clone from %s", dir, url)
_, err := git.PlainClone(dir, false, &git.CloneOptions{
URL: url,
Tags: git.AllTags,
// To be able to pull recipe from any branch
SingleBranch: false,
})
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
}
log.Debugf("%s has been git cloned successfully", dir)
} else {
log.Debugf("%s already exists", dir)
}
return nil
}