forked from toolshed/abra
@ -119,10 +119,10 @@ func EnsureVersion(recipeName, version string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
logrus.Debugf("read '%s' as tags for recipe '%s'", tags, recipeName)
|
||||
|
||||
var parsedTags []string
|
||||
var tagRef plumbing.ReferenceName
|
||||
if err := tags.ForEach(func(ref *plumbing.Reference) (err error) {
|
||||
parsedTags = append(parsedTags, ref.Name().Short())
|
||||
if ref.Name().Short() == version {
|
||||
tagRef = ref.Name()
|
||||
}
|
||||
@ -131,6 +131,8 @@ func EnsureVersion(recipeName, version string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("read '%s' as tags for recipe '%s'", strings.Join(parsedTags, ", "), recipeName)
|
||||
|
||||
if tagRef.String() == "" {
|
||||
return fmt.Errorf("%s is not available?", version)
|
||||
}
|
||||
@ -145,7 +147,48 @@ func EnsureVersion(recipeName, version string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("successfully checked '%s' out to '%s' in '%s'", recipeName, tagRef, recipeDir)
|
||||
logrus.Debugf("successfully checked '%s' out to '%s' in '%s'", recipeName, tagRef.Short(), recipeDir)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnsureLatest makes sure the latest commit is checkout on for a local recipe repository.
|
||||
func EnsureLatest(recipeName string) error {
|
||||
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
|
||||
|
||||
logrus.Debugf("attempting to open git repository in '%s'", recipeDir)
|
||||
|
||||
repo, err := git.PlainOpen(recipeDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
worktree, err := repo.Worktree()
|
||||
if err != nil {
|
||||
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"
|
||||
}
|
||||
|
||||
refName := fmt.Sprintf("refs/heads/%s", branch)
|
||||
checkOutOpts := &git.CheckoutOptions{
|
||||
Create: false,
|
||||
Force: true,
|
||||
Keep: false,
|
||||
Branch: plumbing.ReferenceName(refName),
|
||||
}
|
||||
|
||||
if err := worktree.Checkout(checkOutOpts); err != nil {
|
||||
logrus.Debugf("failed to check out '%s' in '%s'", branch, recipeDir)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user