MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / DownloadFilesByGit

Method DownloadFilesByGit

cli/pkg/common/git.go:237–277  ·  view source on GitHub ↗

从git下载相关文件

(workingRootDir string, gitCloneUrl string, branch string, filePathExpression string)

Source from the content-addressed store, hash-verified

235
236// 从git下载相关文件
237func (g gitOperation) DownloadFilesByGit(workingRootDir string, gitCloneUrl string, branch string, filePathExpression string) (
238 gitRepoRootDirPath string, fileRelativePaths []string, err error) {
239 // home 目录的路径
240 home, err := os.UserHomeDir()
241 if err != nil {
242 return
243 }
244
245 // 文件路径
246 //workingRootDir := filepath.Join(home, ".ide", ".k8s") // 工作目录,repo 会clone到当前目录下
247 sshPath := filepath.Join(home, ".ssh")
248 if !IsExist(workingRootDir) { // 目录如果不存在,就要创建
249 os.MkdirAll(workingRootDir, os.ModePerm)
250 }
251
252 // 设置不进行host的检查,即clone新的git库时,不会给出提示
253 err = FS.SkipStrictHostKeyChecking(sshPath, false)
254 if err != nil {
255 return
256 }
257
258 // 下载指定的文件
259 //filePathExpression = common.PathJoin(".ide", filePathExpression)
260 filePathExpression = strings.ReplaceAll(filePathExpression, "\\", "/")
261 fileRelativePaths, err = GIT.SparseCheckout(workingRootDir, gitCloneUrl, filePathExpression, branch)
262 if err != nil {
263 return
264 }
265
266 // 还原.ssh config 的设置
267 err = FS.SkipStrictHostKeyChecking(sshPath, true)
268 if err != nil {
269 return
270 }
271
272 gitRepoRootDirPath = filepath.Join(workingRootDir, GetRepoName(gitCloneUrl)) // git repo 的根目录
273 for index, _ := range fileRelativePaths {
274 fileRelativePaths[index] = strings.Replace(fileRelativePaths[index], gitRepoRootDirPath, "", -1) // 把绝对路径改为相对路径
275 }
276 return gitRepoRootDirPath, fileRelativePaths, nil
277}

Callers 1

downloadFilesByGitFunction · 0.80

Calls 5

IsExistFunction · 0.85
GetRepoNameFunction · 0.85
SparseCheckoutMethod · 0.80
JoinMethod · 0.45

Tested by

no test coverage detected