From 2fbdcfb958ab3fcd94fb9072daa3412355a9a986 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sun, 20 Feb 2022 18:06:50 +0100 Subject: [PATCH] refactor: try the meta for default branch too Sometimes the Branch(...) call gets confused with state in the repository. Its more robust to use the default value we get from gitea. See https://git.coopcloud.tech/coop-cloud/organising/issues/299. --- pkg/recipe/recipe.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/recipe/recipe.go b/pkg/recipe/recipe.go index 8c08cbdd..01e09955 100644 --- a/pkg/recipe/recipe.go +++ b/pkg/recipe/recipe.go @@ -615,11 +615,15 @@ func EnsureUpToDate(recipeName string) error { func GetDefaultBranch(repo *git.Repository, recipeName string) (plumbing.ReferenceName, error) { recipeDir := path.Join(config.RECIPES_DIR, recipeName) + meta, _ := GetRecipeMeta(recipeName) + if meta.DefaultBranch != "" { + return plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", meta.DefaultBranch)), nil + } + branch := "master" if _, err := repo.Branch("master"); err != nil { if _, err := repo.Branch("main"); err != nil { - logrus.Debugf("failed to select branch in %s", recipeDir) - return "", err + return "", fmt.Errorf("failed to select default branch in %s", recipeDir) } branch = "main" }