This commit is contained in:
2022-09-18 00:10:30 +02:00
parent eef25c4c7a
commit 88430eb879
4 changed files with 98 additions and 17 deletions

View File

@@ -62,6 +62,34 @@ func NewGit(logger *zap.Logger, gitConfig *GitConfig, openPGP *signer.OpenPGP) *
return &Git{logger: logger, gitConfig: gitConfig, openPGP: openPGP}
}
func (g *Git) GetOriginHEADForRepo(ctx context.Context, gitRepo *GitRepo) (string, error) {
remote, err := gitRepo.repo.Remote("origin")
if err != nil {
return "", err
}
auth, err := g.GetAuth()
if err != nil {
return "", err
}
refs, err := remote.ListContext(ctx, &git.ListOptions{
Auth: auth,
})
if err != nil {
return "", err
}
headRef := ""
for _, ref := range refs {
if !ref.Name().IsBranch() {
headRef = ref.Target().Short()
}
}
return headRef, nil
}
func (g *Git) CloneBranch(ctx context.Context, storageArea *storage.Area, repoUrl string, branch string) (*GitRepo, error) {
g.logger.Debug(
"cloning repository",