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)
| 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. |
| 35 | func 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. |
| 61 | func fetchFilesViaGoGit(opts FetchOptions) error { |
no test coverage detected