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 coop-cloud/organising#299.
This commit is contained in:
decentral1se 2022-02-20 18:06:50 +01:00
parent 09ac74d205
commit 2fbdcfb958
Signed by untrusted user: decentral1se
GPG Key ID: 03789458B3D0C410
1 changed files with 6 additions and 2 deletions

View File

@ -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"
}