(ctx context.Context, workingDirectory string, source *latest.SourceConfig, log log.Logger)
| 79 | } |
| 80 | |
| 81 | func 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 | } |
no test coverage detected