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

@ -213,20 +213,15 @@ func EnsureLatest(recipeName string) error {
return 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", path.Join(config.APPS_DIR, recipeName))
return err
}
branch = "main"
branch, err := gitPkg.GetCurrentBranch(repo)
if err != nil {
return 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 {