MCPcopy
hub / github.com/danielmiessler/Fabric / FetchFilesFromRepo

Function FetchFilesFromRepo

internal/tools/githelper/githelper.go:35–58  ·  view source on GitHub ↗

FetchFilesFromRepo clones a git repo and extracts files from a specific folder. It tries go-git first, and falls back to the git CLI if available.

(opts FetchOptions)

Source from the content-addressed store, hash-verified

33// FetchFilesFromRepo clones a git repo and extracts files from a specific folder.
34// It tries go-git first, and falls back to the git CLI if available.
35func FetchFilesFromRepo(opts FetchOptions) error {
36 // Ensure path prefix ends with slash
37 if !strings.HasSuffix(opts.PathPrefix, "/") {
38 opts.PathPrefix = opts.PathPrefix + "/"
39 }
40
41 // Try go-git first (in-memory clone)
42 goGitErr := fetchFilesViaGoGit(opts)
43 if goGitErr == nil {
44 return nil
45 }
46
47 // go-git failed; try git CLI fallback if available
48 if _, lookErr := exec.LookPath("git"); lookErr != nil {
49 return goGitErr
50 }
51
52 cliErr := fetchFilesViaGitCLI(opts)
53 if cliErr == nil {
54 return nil
55 }
56
57 return fmt.Errorf(i18n.T("githelper_failed_git_cli_fallback"), goGitErr, cliErr)
58}
59
60// fetchFilesViaGoGit clones a repo in memory using go-git and extracts files.
61func fetchFilesViaGoGit(opts FetchOptions) error {

Callers 3

gitCloneAndCopyMethod · 0.92
tryPathMigrationMethod · 0.92
gitCloneAndCopyMethod · 0.92

Calls 3

TFunction · 0.92
fetchFilesViaGoGitFunction · 0.85
fetchFilesViaGitCLIFunction · 0.85

Tested by

no test coverage detected