parent
d38f3ab7f5
commit
ce7dda1eae
@ -3,10 +3,8 @@ package recipe
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"coopcloud.tech/abra/pkg/config"
|
|
||||||
"coopcloud.tech/abra/pkg/formatter"
|
"coopcloud.tech/abra/pkg/formatter"
|
||||||
gitPkg "coopcloud.tech/abra/pkg/git"
|
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||||
"coopcloud.tech/abra/pkg/log"
|
"coopcloud.tech/abra/pkg/log"
|
||||||
@ -142,13 +140,11 @@ func (r Recipe) EnsureIsClean() error {
|
|||||||
|
|
||||||
// EnsureLatest makes sure the latest commit is checked out for the local recipe repository
|
// EnsureLatest makes sure the latest commit is checked out for the local recipe repository
|
||||||
func (r Recipe) EnsureLatest() error {
|
func (r Recipe) EnsureLatest() error {
|
||||||
recipeDir := path.Join(config.RECIPES_DIR, r.Name)
|
if err := gitPkg.EnsureGitRepo(r.Dir); err != nil {
|
||||||
|
|
||||||
if err := gitPkg.EnsureGitRepo(recipeDir); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := git.PlainOpen(recipeDir)
|
repo, err := git.PlainOpen(r.Dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -158,7 +154,7 @@ func (r Recipe) EnsureLatest() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
branch, err := gitPkg.GetDefaultBranch(repo, recipeDir)
|
branch, err := gitPkg.GetDefaultBranch(repo, r.Dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -170,7 +166,7 @@ func (r Recipe) EnsureLatest() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := worktree.Checkout(checkOutOpts); err != nil {
|
if err := worktree.Checkout(checkOutOpts); err != nil {
|
||||||
log.Debugf("failed to check out %s in %s", branch, recipeDir)
|
log.Debugf("failed to check out %s in %s", branch, r.Dir)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,16 +175,14 @@ func (r Recipe) EnsureLatest() error {
|
|||||||
|
|
||||||
// EnsureUpToDate ensures that the local repo is synced to the remote
|
// EnsureUpToDate ensures that the local repo is synced to the remote
|
||||||
func (r Recipe) EnsureUpToDate() error {
|
func (r Recipe) EnsureUpToDate() error {
|
||||||
recipeDir := path.Join(config.RECIPES_DIR, r.Name)
|
repo, err := git.PlainOpen(r.Dir)
|
||||||
|
|
||||||
repo, err := git.PlainOpen(recipeDir)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to open %s: %s", recipeDir, err)
|
return fmt.Errorf("unable to open %s: %s", r.Dir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
remotes, err := repo.Remotes()
|
remotes, err := repo.Remotes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to read remotes in %s: %s", recipeDir, err)
|
return fmt.Errorf("unable to read remotes in %s: %s", r.Dir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(remotes) == 0 {
|
if len(remotes) == 0 {
|
||||||
@ -198,18 +192,18 @@ func (r Recipe) EnsureUpToDate() error {
|
|||||||
|
|
||||||
worktree, err := repo.Worktree()
|
worktree, err := repo.Worktree()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to open git work tree in %s: %s", recipeDir, err)
|
return fmt.Errorf("unable to open git work tree in %s: %s", r.Dir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
branch, err := gitPkg.CheckoutDefaultBranch(repo, recipeDir)
|
branch, err := gitPkg.CheckoutDefaultBranch(repo, r.Dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to check out default branch in %s: %s", recipeDir, err)
|
return fmt.Errorf("unable to check out default branch in %s: %s", r.Dir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchOpts := &git.FetchOptions{Tags: git.AllTags}
|
fetchOpts := &git.FetchOptions{Tags: git.AllTags}
|
||||||
if err := repo.Fetch(fetchOpts); err != nil {
|
if err := repo.Fetch(fetchOpts); err != nil {
|
||||||
if !strings.Contains(err.Error(), "already up-to-date") {
|
if !strings.Contains(err.Error(), "already up-to-date") {
|
||||||
return fmt.Errorf("unable to fetch tags in %s: %s", recipeDir, err)
|
return fmt.Errorf("unable to fetch tags in %s: %s", r.Dir, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +215,7 @@ func (r Recipe) EnsureUpToDate() error {
|
|||||||
|
|
||||||
if err := worktree.Pull(opts); err != nil {
|
if err := worktree.Pull(opts); err != nil {
|
||||||
if !strings.Contains(err.Error(), "already up-to-date") {
|
if !strings.Contains(err.Error(), "already up-to-date") {
|
||||||
return fmt.Errorf("unable to git pull in %s: %s", recipeDir, err)
|
return fmt.Errorf("unable to git pull in %s: %s", r.Dir, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,8 +235,7 @@ func (r Recipe) ChaosVersion() (string, error) {
|
|||||||
|
|
||||||
version = formatter.SmallSHA(head.String())
|
version = formatter.SmallSHA(head.String())
|
||||||
|
|
||||||
recipeDir := path.Join(config.RECIPES_DIR, r.Name)
|
isClean, err := gitPkg.IsClean(r.Dir)
|
||||||
isClean, err := gitPkg.IsClean(recipeDir)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return version, err
|
return version, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user