forked from toolshed/abra
fix: use one function for up-to-date checks
This commit is contained in:
@ -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),
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user