Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Registry cache for Azure DevOps #1690

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions internal/registry/registry_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"

"github.com/go-git/go-git/v5"
Expand Down Expand Up @@ -168,6 +170,7 @@ func (r *Cache) Initialize() error {

// CreateCache creates the cache on the filesystem
func (r *Cache) CreateCache() error {
var repository *git.Repository
r.logger.Debugf("Creating registry cache for %s/%s", r.url.Host, r.url.Path)

registryDir, err := os.MkdirTemp(filepath.Dir(r.Root), "registry")
Expand All @@ -177,11 +180,23 @@ func (r *Cache) CreateCache() error {

r.RegistryDir = registryDir

repository, err := git.PlainClone(r.RegistryDir, false, &git.CloneOptions{
URL: r.url.String(),
})
if err != nil {
return errors.Wrap(err, "cloning remote registry")
if strings.Contains(r.url.String(), "dev.azure.com/") {
diznq marked this conversation as resolved.
Show resolved Hide resolved
err = exec.Command("git", "clone", r.url.String(), r.RegistryDir).Run()
if err != nil {
return errors.Wrap(err, "cloning remote registry")
diznq marked this conversation as resolved.
Show resolved Hide resolved
}

repository, err = git.PlainOpen(r.RegistryDir)
if err != nil {
return errors.Wrap(err, "opening remote registry clone")
}
} else {
repository, err = git.PlainClone(r.RegistryDir, false, &git.CloneOptions{
URL: r.url.String(),
})
if err != nil {
return errors.Wrap(err, "cloning remote registry")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could such error handling have been more perfect?

}
}

w, err := repository.Worktree()
Expand Down