MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / gitCloneAndCopy

Method gitCloneAndCopy

internal/tools/patterns_loader.go:214–247  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

212}
213
214func (o *PatternsLoader) gitCloneAndCopy() (err error) {
215 // Create temp folder if it doesn't exist
216 if err = os.MkdirAll(filepath.Dir(o.tempPatternsFolder), os.ModePerm); err != nil {
217 return fmt.Errorf(i18n.T("patterns_failed_create_temp_dir"), err)
218 }
219
220 fmt.Printf(i18n.T("patterns_cloning_repository"), o.DefaultGitRepoUrl.Value, o.DefaultFolder.Value)
221
222 // Try to fetch files with the current path
223 err = githelper.FetchFilesFromRepo(githelper.FetchOptions{
224 RepoURL: o.DefaultGitRepoUrl.Value,
225 PathPrefix: o.DefaultFolder.Value,
226 DestDir: o.tempPatternsFolder,
227 })
228 if err != nil {
229 return fmt.Errorf(i18n.T("patterns_failed_download_from_repo"), o.DefaultGitRepoUrl.Value, err)
230 }
231
232 // Check if patterns were downloaded
233 if patternCount, checkErr := o.countPatternsInDirectory(o.tempPatternsFolder); checkErr != nil {
234 return fmt.Errorf(i18n.T("patterns_failed_read_temp_directory"), checkErr)
235 } else if patternCount == 0 {
236 // No patterns found with current path, try automatic migration
237 if migrationErr := o.tryPathMigration(); migrationErr != nil {
238 return fmt.Errorf(i18n.T("patterns_no_patterns_migration_failed"), o.DefaultFolder.Value, migrationErr)
239 }
240 // Migration successful, try downloading again
241 return o.gitCloneAndCopy()
242 } else {
243 fmt.Printf(i18n.T("patterns_downloaded_temp"), patternCount)
244 }
245
246 return nil
247}
248
249// tryPathMigration attempts to migrate from old pattern paths to new restructured paths
250func (o *PatternsLoader) tryPathMigration() (err error) {

Callers 1

PopulateDBMethod · 0.95

Calls 4

tryPathMigrationMethod · 0.95
TFunction · 0.92
FetchFilesFromRepoFunction · 0.92

Tested by

no test coverage detected