with actual head branch name

This commit is contained in:
Kasper Juul Hermansen 2022-09-18 01:46:58 +02:00
parent 1889f05db2
commit 64e9f8dca8
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
3 changed files with 19 additions and 10 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.cuddle/ .cuddle/
.env

View File

@ -2,7 +2,9 @@ package providers
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings"
"time" "time"
"git.front.kjuulh.io/kjuulh/kraken/internal/services/signer" "git.front.kjuulh.io/kjuulh/kraken/internal/services/signer"
@ -63,12 +65,12 @@ func NewGit(logger *zap.Logger, gitConfig *GitConfig, openPGP *signer.OpenPGP) *
} }
func (g *Git) GetOriginHEADForRepo(ctx context.Context, gitRepo *GitRepo) (string, error) { func (g *Git) GetOriginHEADForRepo(ctx context.Context, gitRepo *GitRepo) (string, error) {
remote, err := gitRepo.repo.Remote("origin") auth, err := g.GetAuth()
if err != nil { if err != nil {
return "", err return "", err
} }
auth, err := g.GetAuth() remote, err := gitRepo.repo.Remote("origin")
if err != nil { if err != nil {
return "", err return "", err
} }
@ -82,11 +84,16 @@ func (g *Git) GetOriginHEADForRepo(ctx context.Context, gitRepo *GitRepo) (strin
headRef := "" headRef := ""
for _, ref := range refs { for _, ref := range refs {
if !ref.Name().IsBranch() { //g.logger.Debug(ref.String())
headRef = ref.Target().Short() if ref.Name().IsBranch() && strings.Contains(ref.String(), "/heads/") {
headRef = ref.Name().Short()
} }
} }
if headRef == "" {
return "", errors.New("no upstream HEAD branch could be found")
}
return headRef, nil return headRef, nil
} }
@ -143,8 +150,8 @@ func (g *Git) Clone(ctx context.Context, storageArea *storage.Area, repoUrl stri
URL: repoUrl, URL: repoUrl,
Auth: auth, Auth: auth,
RemoteName: "origin", RemoteName: "origin",
ReferenceName: "refs/heads/main", // ReferenceName: "refs/heads/main",
SingleBranch: true, SingleBranch: false,
NoCheckout: false, NoCheckout: false,
Depth: 1, Depth: 1,
RecurseSubmodules: 1, RecurseSubmodules: 1,
@ -292,7 +299,6 @@ func (g *Git) Push(ctx context.Context, gitRepo *GitRepo) error {
CABundle: []byte{}, CABundle: []byte{},
RequireRemoteRefs: []config.RefSpec{}, RequireRemoteRefs: []config.RefSpec{},
}) })
if err != nil { if err != nil {
return err return err
} }

View File

@ -2,4 +2,6 @@
set -e set -e
export $(cat .env | xargs)
go run cmd/server/server.go start go run cmd/server/server.go start