From c865b597c0c7fd00d3d7b539fe63a8fd66cc9fe9 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 18 Sep 2022 11:50:57 +0200 Subject: [PATCH] fixed git --- internal/services/providers/git.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/internal/services/providers/git.go b/internal/services/providers/git.go index 63db3cf..45ed04e 100644 --- a/internal/services/providers/git.go +++ b/internal/services/providers/git.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "strings" "time" "git.front.kjuulh.io/kjuulh/kraken/internal/services/signer" @@ -85,8 +84,8 @@ func (g *Git) GetOriginHEADForRepo(ctx context.Context, gitRepo *GitRepo) (strin headRef := "" for _, ref := range refs { //g.logger.Debug(ref.String()) - if ref.Name().IsBranch() && strings.Contains(ref.String(), "/heads/") { - headRef = ref.Name().Short() + if !ref.Name().IsBranch() { + headRef = ref.Target().Short() } } @@ -114,7 +113,7 @@ func (g *Git) CloneBranch(ctx context.Context, storageArea *storage.Area, repoUr Auth: auth, RemoteName: "origin", ReferenceName: plumbing.NewBranchReferenceName(branch), - SingleBranch: true, + SingleBranch: false, NoCheckout: false, Depth: 1, RecurseSubmodules: 1, @@ -125,7 +124,7 @@ func (g *Git) CloneBranch(ctx context.Context, storageArea *storage.Area, repoUr } repo, err := git.PlainCloneContext(ctx, storageArea.Path, false, &cloneOptions) - if err != nil { + if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { return nil, err } @@ -147,10 +146,10 @@ func (g *Git) Clone(ctx context.Context, storageArea *storage.Area, repoUrl stri } cloneOptions := git.CloneOptions{ - URL: repoUrl, - Auth: auth, - RemoteName: "origin", - // ReferenceName: "refs/heads/main", + URL: repoUrl, + Auth: auth, + RemoteName: "origin", + ReferenceName: "refs/heads/main", SingleBranch: false, NoCheckout: false, Depth: 1, @@ -252,7 +251,7 @@ func (g *Git) CreateBranch(ctx context.Context, gitRepo *GitRepo) error { InsecureSkipTLS: false, CABundle: []byte{}, }) - if err != nil { + if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { return fmt.Errorf("could not pull from origin: %w", err) }