MCPcopy Create free account
hub / github.com/devspace-sh/devspace / DownloadDependency

Function DownloadDependency

pkg/devspace/dependency/util/util.go:81–216  ·  view source on GitHub ↗
(ctx context.Context, workingDirectory string, source *latest.SourceConfig, log log.Logger)

Source from the content-addressed store, hash-verified

79}
80
81func DownloadDependency(ctx context.Context, workingDirectory string, source *latest.SourceConfig, log log.Logger) (configPath string, err error) {
82 downloadMutex.Lock()
83 defer downloadMutex.Unlock()
84
85 ID, err := GetDependencyID(source)
86 if err != nil {
87 return "", err
88 }
89
90 var localPath string
91
92 // Resolve git source
93 if source.Git != "" {
94 gitPath := strings.TrimSpace(source.Git)
95
96 _ = os.MkdirAll(DependencyFolderPath, 0755)
97 localPath = filepath.Join(DependencyFolderPath, ID)
98
99 // Check if dependency are cached locally
100 _, statErr := os.Stat(localPath)
101
102 // Verify git cli works
103 repo, err := git.NewGitCLIRepository(ctx, localPath)
104 if err != nil {
105 if statErr == nil {
106 log.Warnf("Error creating git cli: %v", err)
107 return getDependencyConfigPath(localPath, source)
108 }
109 return "", err
110 }
111
112 // Create git clone options
113 var gitCloneOptions = git.CloneOptions{
114 URL: gitPath,
115 Tag: source.Tag,
116 Branch: source.Branch,
117 Commit: source.Revision,
118 Args: source.CloneArgs,
119 DisableShallow: source.DisableShallow,
120 }
121
122 // Git clone
123 if statErr != nil {
124 err = repo.Clone(ctx, gitCloneOptions)
125
126 if err != nil {
127 log.Warn("Error cloning repo: ", err)
128
129 gitCloneOptions.URL = switchURLType(gitPath)
130 log.Infof("Switching URL from %s to %s and will try cloning again", gitPath, gitCloneOptions.URL)
131 err = repo.Clone(ctx, gitCloneOptions)
132
133 if err != nil {
134 log.Warn("Failed to clone repo with both HTTPS and SSH URL. Please make sure if your git login or ssh setup is correct.")
135 if statErr == nil {
136 log.Warnf("Error cloning or pulling git repository %s: %v", gitPath, err)
137 return getDependencyConfigPath(localPath, source)
138 }

Callers 1

resolveRecursiveMethod · 0.92

Calls 15

CloneMethod · 0.95
PullMethod · 0.95
NewGitCLIRepositoryFunction · 0.92
GetDependencyIDFunction · 0.85
getDependencyConfigPathFunction · 0.85
switchURLTypeFunction · 0.85
isURLFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
CloseMethod · 0.65
CopyMethod · 0.65
WarnfMethod · 0.45

Tested by

no test coverage detected