From ff90b439299386450c07f3cac91cffc9feeed7b5 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Wed, 10 Jul 2024 15:51:11 +0200 Subject: [PATCH] fix: use struct data for HEAD retrieval See ce7dda1eaea5665da7155b4fc2d0a5f885237b1a --- cli/app/deploy.go | 3 +-- pkg/git/read.go | 20 -------------------- pkg/recipe/git.go | 17 ++++++++++++++++- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/cli/app/deploy.go b/cli/app/deploy.go index 0f2c0ed5..d589c694 100644 --- a/cli/app/deploy.go +++ b/cli/app/deploy.go @@ -12,7 +12,6 @@ import ( "coopcloud.tech/abra/pkg/client" "coopcloud.tech/abra/pkg/dns" "coopcloud.tech/abra/pkg/formatter" - "coopcloud.tech/abra/pkg/git" "coopcloud.tech/abra/pkg/lint" "coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/upstream/stack" @@ -135,7 +134,7 @@ EXAMPLE: log.Fatal(err) } } else { - head, err := git.GetRecipeHead(app.Recipe.Name) + head, err := app.Recipe.Head() if err != nil { log.Fatal(err) } diff --git a/pkg/git/read.go b/pkg/git/read.go index ad104c74..aa125fc5 100644 --- a/pkg/git/read.go +++ b/pkg/git/read.go @@ -4,35 +4,15 @@ import ( "io/ioutil" "os" "os/user" - "path" "path/filepath" "strings" - "coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/log" "github.com/go-git/go-git/v5" 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" ) -// 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 func IsClean(repoPath string) (bool, error) { repo, err := git.PlainOpen(repoPath) diff --git a/pkg/recipe/git.go b/pkg/recipe/git.go index d4468db2..60b20c4f 100644 --- a/pkg/recipe/git.go +++ b/pkg/recipe/git.go @@ -228,7 +228,7 @@ func (r Recipe) EnsureUpToDate() error { func (r Recipe) ChaosVersion() (string, error) { var version string - head, err := gitPkg.GetRecipeHead(r.Name) + head, err := r.Head() if err != nil { return version, err } @@ -379,3 +379,18 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, error) { 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 +}