MCPcopy
hub / github.com/cyclops-ui/cyclops / clone

Function clone

cyclops-ctrl/pkg/template/git.go:379–457  ·  view source on GitHub ↗
(repoURL, commit string, creds *auth.Credentials)

Source from the content-addressed store, hash-verified

377}
378
379func clone(repoURL, commit string, creds *auth.Credentials) (billy.Filesystem, error) {
380 // region clone from git
381 if gitproviders2.IsAzureRepo(repoURL) {
382 transport.UnsupportedCapabilities = []capability.Capability{
383 capability.ThinPack,
384 }
385 }
386
387 repo, err := git.Clone(memory.NewStorage(), memfs.New(), &git.CloneOptions{
388 URL: repoURL,
389 Tags: git.AllTags,
390 Auth: httpBasicAuthCredentials(creds),
391 })
392 if err != nil {
393 return nil, errors.Wrap(err, fmt.Sprintf("repo %s was not cloned successfully; authentication might be required; check if repository exists and you referenced it correctly", repoURL))
394 }
395
396 wt, err := repo.Worktree()
397 if err != nil {
398 return nil, err
399 }
400
401 if len(commit) != 0 {
402 remoteName := "origin"
403 branchPrefix := "refs/heads/"
404 tagPrefix := "refs/tags/"
405 remote, err := repo.Remote(remoteName)
406 if err != nil {
407 return nil, err
408 }
409 refList, err := remote.List(&git.ListOptions{
410 Auth: httpBasicAuthCredentials(creds),
411 })
412 if err != nil {
413 return nil, err
414 }
415
416 var reference *plumbing.Reference
417
418 for _, ref := range refList {
419 refName := ref.Name().String()
420 if strings.HasPrefix(refName, branchPrefix) {
421 branchName := refName[len(branchPrefix):]
422 if branchName != commit {
423 continue
424 }
425
426 refName := plumbing.NewRemoteReferenceName(remoteName, branchName)
427 reference, err = repo.Reference(refName, true)
428 if err != nil {
429 return nil, err
430 }
431 } else if strings.HasPrefix(refName, tagPrefix) {
432 tagName := refName[len(tagPrefix):]
433 if tagName != commit {
434 continue
435 }
436

Callers 2

LoadTemplateMethod · 0.85

Calls 2

httpBasicAuthCredentialsFunction · 0.70
ListMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…