From 161f2127d687eab3e2b0db44138609bb2a498a71 Mon Sep 17 00:00:00 2001 From: stevensting Date: Thu, 26 Dec 2024 17:55:35 +0100 Subject: [PATCH 1/3] allow to define remote branches as recipe source --- pkg/recipe/compose.go | 1 + pkg/recipe/git.go | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/recipe/compose.go b/pkg/recipe/compose.go index 736e5f70..f8506841 100644 --- a/pkg/recipe/compose.go +++ b/pkg/recipe/compose.go @@ -95,6 +95,7 @@ func (r Recipe) GetVersionLabelLocal() (string, error) { for _, service := range config.Services { for label, value := range service.Deploy.Labels { + log.Debugf("checking deploy label '%s'", label) if strings.HasPrefix(label, "coop-cloud") && strings.Contains(label, "version") { return value, nil } diff --git a/pkg/recipe/git.go b/pkg/recipe/git.go index 7a695fd3..afac7e1e 100644 --- a/pkg/recipe/git.go +++ b/pkg/recipe/git.go @@ -68,6 +68,7 @@ func (r Recipe) EnsureExists() error { // EnsureVersion checks whether a specific version exists for a recipe. func (r Recipe) EnsureVersion(version string) (bool, error) { isChaosCommit := false + log.Debugf("Ensuring version '%s'", version) if err := gitPkg.EnsureGitRepo(r.Dir); err != nil { return isChaosCommit, err @@ -78,7 +79,7 @@ func (r Recipe) EnsureVersion(version string) (bool, error) { return isChaosCommit, err } - tags, err := repo.Tags() + tags, err := repo.References() if err != nil { return isChaosCommit, err } @@ -117,11 +118,11 @@ func (r Recipe) EnsureVersion(version string) (bool, error) { worktree, err := repo.Worktree() if err != nil { - return isChaosCommit, nil + return isChaosCommit, err } if err := worktree.Checkout(opts); err != nil { - return isChaosCommit, nil + return isChaosCommit, err } log.Debugf("successfully checked %s out to %s in %s", r.Name, tagRef.Short(), r.Dir) @@ -216,7 +217,7 @@ func (r Recipe) EnsureUpToDate() error { opts := &git.PullOptions{ Force: true, ReferenceName: branch, - SingleBranch: true, + SingleBranch: false, } if err := worktree.Pull(opts); err != nil { -- 2.49.0 From 776a8414d4e865201acfe3b6b43fc8c54c01c96e Mon Sep 17 00:00:00 2001 From: stevensting Date: Thu, 26 Dec 2024 18:08:36 +0100 Subject: [PATCH 2/3] cloned repos shall contain all branches --- pkg/git/clone.go | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/pkg/git/clone.go b/pkg/git/clone.go index c295766f..7b58a086 100644 --- a/pkg/git/clone.go +++ b/pkg/git/clone.go @@ -8,7 +8,6 @@ import ( "coopcloud.tech/abra/pkg/log" "github.com/go-git/go-git/v5" - "github.com/go-git/go-git/v5/plumbing" ) // Clone runs a git clone which accounts for different default branches. @@ -17,28 +16,19 @@ func Clone(dir, url string) error { log.Debugf("%s does not exist, attempting to git clone from %s", dir, url) _, err := git.PlainClone(dir, false, &git.CloneOptions{ - URL: url, - Tags: git.AllTags, - ReferenceName: plumbing.ReferenceName("refs/heads/master"), - SingleBranch: true, + URL: url, + Tags: git.AllTags, + // To be able to pull recipe from any branch + SingleBranch: false, }) + if err != nil { - log.Debugf("cloning %s default branch failed, attempting from main branch", url) - - _, err := git.PlainClone(dir, false, &git.CloneOptions{ - URL: url, - Tags: git.AllTags, - ReferenceName: plumbing.ReferenceName("refs/heads/main"), - SingleBranch: true, - }) - if err != nil { - if strings.Contains(err.Error(), "authentication required") { - name := filepath.Base(dir) - return fmt.Errorf("unable to clone %s, does %s exist?", name, url) - } - - return err + if strings.Contains(err.Error(), "authentication required") { + name := filepath.Base(dir) + return fmt.Errorf("unable to clone %s, does %s exist?", name, url) } + + return err } log.Debugf("%s has been git cloned successfully", dir) -- 2.49.0 From 65c9f4c48ad634c2ecb5315edce7ac87200b9df5 Mon Sep 17 00:00:00 2001 From: stevensting Date: Fri, 3 Jan 2025 15:26:43 +0100 Subject: [PATCH 3/3] fix review findings --- pkg/recipe/compose.go | 2 +- pkg/recipe/git.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/recipe/compose.go b/pkg/recipe/compose.go index f8506841..2a3e8770 100644 --- a/pkg/recipe/compose.go +++ b/pkg/recipe/compose.go @@ -95,7 +95,7 @@ func (r Recipe) GetVersionLabelLocal() (string, error) { for _, service := range config.Services { for label, value := range service.Deploy.Labels { - log.Debugf("checking deploy label '%s'", label) + log.Debugf("checking deploy label '%s' with value '%s' for correct formatting", label, value) if strings.HasPrefix(label, "coop-cloud") && strings.Contains(label, "version") { return value, nil } diff --git a/pkg/recipe/git.go b/pkg/recipe/git.go index afac7e1e..37782441 100644 --- a/pkg/recipe/git.go +++ b/pkg/recipe/git.go @@ -68,7 +68,7 @@ func (r Recipe) EnsureExists() error { // EnsureVersion checks whether a specific version exists for a recipe. func (r Recipe) EnsureVersion(version string) (bool, error) { isChaosCommit := false - log.Debugf("Ensuring version '%s'", version) + log.Debugf("ensuring version '%s' exists for recipe '%s'", version, r.Name) if err := gitPkg.EnsureGitRepo(r.Dir); err != nil { return isChaosCommit, err -- 2.49.0