forked from toolshed/abra
feat: recipe fetch command
Also may have rooted out another go-git cloning bug 🙄 Closes coop-cloud/organising#365
This commit is contained in:
@ -10,9 +10,10 @@ import (
|
||||
|
||||
// Check if a branch exists in a repo. Use this and not repository.Branch(),
|
||||
// because the latter does not actually check for existing branches. See
|
||||
// https://github.com/go-git/go-git/issues/518 for more.
|
||||
// https://github.com/gogit/gogit/issues/518 for more.
|
||||
func HasBranch(repository *git.Repository, name string) bool {
|
||||
var exist bool
|
||||
|
||||
if iter, err := repository.Branches(); err == nil {
|
||||
iterFunc := func(reference *plumbing.Reference) error {
|
||||
if name == reference.Name().Short() {
|
||||
@ -23,6 +24,7 @@ func HasBranch(repository *git.Repository, name string) bool {
|
||||
}
|
||||
_ = iter.ForEach(iterFunc)
|
||||
}
|
||||
|
||||
return exist
|
||||
}
|
||||
|
||||
|
@ -15,22 +15,32 @@ import (
|
||||
func Clone(dir, url string) error {
|
||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||
logrus.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})
|
||||
|
||||
_, err := git.PlainClone(dir, false, &git.CloneOptions{
|
||||
URL: url,
|
||||
Tags: git.AllTags,
|
||||
ReferenceName: plumbing.ReferenceName("refs/heads/master"),
|
||||
SingleBranch: true,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Debugf("cloning %s default branch failed, attempting from main branch", url)
|
||||
|
||||
_, err := git.PlainClone(dir, false, &git.CloneOptions{
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("%s has been git cloned successfully", dir)
|
||||
} else {
|
||||
logrus.Debugf("%s already exists", dir)
|
||||
|
Reference in New Issue
Block a user