fix: get branch is now more robust

This commit is contained in:
2021-12-24 00:43:24 +01:00
parent a85cfe40d0
commit 9b8ff1ddcd
4 changed files with 50 additions and 19 deletions

View File

@ -15,6 +15,7 @@ import (
"coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/pkg/client"
"coopcloud.tech/abra/pkg/config"
gitPkg "coopcloud.tech/abra/pkg/git"
"coopcloud.tech/abra/pkg/recipe"
"coopcloud.tech/abra/pkg/web"
"github.com/docker/distribution/reference"
@ -600,20 +601,15 @@ func GetRecipeVersions(recipeName string) (RecipeVersions, error) {
return versions, err
}
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)
logrus.Fatal(err)
}
branch = "main"
branch, err := gitPkg.GetCurrentBranch(repo)
if err != nil {
return versions, err
}
refName := fmt.Sprintf("refs/heads/%s", branch)
checkOutOpts := &git.CheckoutOptions{
Create: false,
Force: true,
Branch: plumbing.ReferenceName(refName),
Branch: plumbing.ReferenceName(branch),
}
if err := worktree.Checkout(checkOutOpts); err != nil {
logrus.Debugf("failed to check out %s in %s", branch, recipeDir)