fix: use struct data for HEAD retrieval
All checks were successful
continuous-integration/drone/push Build is passing

See ce7dda1eaea5665da7155b4fc2d0a5f885237b1a
This commit is contained in:
decentral1se 2024-07-10 15:51:11 +02:00
parent c5724d56f8
commit ff90b43929
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
3 changed files with 17 additions and 23 deletions

View File

@ -12,7 +12,6 @@ import (
"coopcloud.tech/abra/pkg/client" "coopcloud.tech/abra/pkg/client"
"coopcloud.tech/abra/pkg/dns" "coopcloud.tech/abra/pkg/dns"
"coopcloud.tech/abra/pkg/formatter" "coopcloud.tech/abra/pkg/formatter"
"coopcloud.tech/abra/pkg/git"
"coopcloud.tech/abra/pkg/lint" "coopcloud.tech/abra/pkg/lint"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"coopcloud.tech/abra/pkg/upstream/stack" "coopcloud.tech/abra/pkg/upstream/stack"
@ -135,7 +134,7 @@ EXAMPLE:
log.Fatal(err) log.Fatal(err)
} }
} else { } else {
head, err := git.GetRecipeHead(app.Recipe.Name) head, err := app.Recipe.Head()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -4,35 +4,15 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/user" "os/user"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
gitConfigPkg "github.com/go-git/go-git/v5/config" gitConfigPkg "github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/gitignore" "github.com/go-git/go-git/v5/plumbing/format/gitignore"
) )
// GetRecipeHead retrieves latest HEAD metadata.
func GetRecipeHead(recipeName string) (*plumbing.Reference, error) {
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
repo, err := git.PlainOpen(recipeDir)
if err != nil {
return nil, err
}
head, err := repo.Head()
if err != nil {
return nil, err
}
return head, nil
}
// IsClean checks if a repo has unstaged changes // IsClean checks if a repo has unstaged changes
func IsClean(repoPath string) (bool, error) { func IsClean(repoPath string) (bool, error) {
repo, err := git.PlainOpen(repoPath) repo, err := git.PlainOpen(repoPath)

View File

@ -228,7 +228,7 @@ func (r Recipe) EnsureUpToDate() error {
func (r Recipe) ChaosVersion() (string, error) { func (r Recipe) ChaosVersion() (string, error) {
var version string var version string
head, err := gitPkg.GetRecipeHead(r.Name) head, err := r.Head()
if err != nil { if err != nil {
return version, err return version, err
} }
@ -379,3 +379,18 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, error) {
return versions, nil return versions, nil
} }
// Head retrieves latest HEAD metadata.
func (r Recipe) Head() (*plumbing.Reference, error) {
repo, err := git.PlainOpen(r.Dir)
if err != nil {
return nil, err
}
head, err := repo.Head()
if err != nil {
return nil, err
}
return head, nil
}