fix: use one function for up-to-date checks

This commit is contained in:
2021-12-25 23:45:52 +01:00
parent 8735a8f0ea
commit ba8138079f
3 changed files with 24 additions and 64 deletions

View File

@ -314,6 +314,15 @@ func GetVersionLabelLocal(recipe Recipe) (string, error) {
func EnsureUpToDate(recipeName string) error {
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
isClean, err := gitPkg.IsClean(recipeName)
if err != nil {
return err
}
if !isClean {
return fmt.Errorf("%s has locally unstaged changes", recipeName)
}
repo, err := git.PlainOpen(recipeDir)
if err != nil {
return err
@ -329,6 +338,19 @@ func EnsureUpToDate(recipeName string) error {
return err
}
checkOutOpts := &git.CheckoutOptions{
Create: false,
Force: true,
Branch: plumbing.ReferenceName(branch),
}
if err := worktree.Checkout(checkOutOpts); err != nil {
logrus.Debugf("failed to check out %s in %s", branch, recipeDir)
return err
}
logrus.Debugf("successfully checked out %s in %s", branch, recipeDir)
remotes, err := repo.Remotes()
if err != nil {
return err
@ -340,6 +362,7 @@ func EnsureUpToDate(recipeName string) error {
}
opts := &git.PullOptions{
Force: true,
ReferenceName: plumbing.ReferenceName(branch),
}