fix: sync recipes from remotes

This commit is contained in:
2021-12-24 16:06:29 +01:00
parent dddf84d92b
commit 14400d4ed8
2 changed files with 52 additions and 6 deletions

View File

@ -184,7 +184,7 @@ func EnsureVersion(recipeName, version string) error {
return nil
}
// EnsureLatest makes sure the latest commit is checkout on for a local recipe repository.
// EnsureLatest makes sure the latest commit is checked out for a local recipe repository
func EnsureLatest(recipeName string) error {
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
@ -285,3 +285,37 @@ func GetVersionLabelLocal(recipe Recipe) (string, error) {
return label, nil
}
// EnsureUpToDate ensures that the local repo is synced to the remote
func EnsureUpToDate(recipeName string) error {
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
repo, err := git.PlainOpen(recipeDir)
if err != nil {
return err
}
worktree, err := repo.Worktree()
if err != nil {
return err
}
branch, err := gitPkg.GetCurrentBranch(repo)
if err != nil {
return err
}
opts := &git.PullOptions{
ReferenceName: plumbing.ReferenceName(branch),
}
if err := worktree.Pull(opts); err != nil {
if !strings.Contains(err.Error(), "already up-to-date") {
return err
}
}
logrus.Debugf("fetched latest git changes for %s", recipeName)
return nil
}