// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 package main import ( "fmt" "strings" "go.wit.com/lib/config" "go.wit.com/lib/fhelp" "go.wit.com/log" ) // // go-clone everything from wit // func doClone() error { initForge() data, err := resources.ReadFile("resources/repomap") if err != nil { log.Info("open repomap failed", err) return err } if len(data) == 0 { log.Info("resources/repomap is empty") return config.ErrEmpty } if argv.Clone.Repomap != nil { makeNewRepomap(string(data)) return nil } for _, line := range strings.Split(string(data), "\n") { if line == "" { continue } if strings.HasPrefix(line, "#") { continue } parts := strings.Fields(line) namespace := parts[0] repo := me.forge.Repos.FindByNamespace(namespace) if argv.Clone.Check != nil { if repo == nil { log.Info("don't have repo", namespace) continue } if repo.URL == parts[1] { continue } log.Info("url wrong?", repo.URL, parts[1]) continue } if argv.Clone.Fix != nil { if repo == nil { log.Info("don't have repo", namespace) continue } if repo.URL == parts[1] { continue } cmd := []string{"git", "remote", "set-url", "origin", parts[1]} log.Info("url wrong?", cmd) repo.RunVerbose(cmd) continue } if repo != nil { if argv.Verbose { log.Info("already have", repo.FullPath) } continue } var cmd []string cmd = []string{"go-clone", "--non-recursive", namespace} if argv.DryRun { log.Info("run:", cmd) } else { log.Info("should run:", cmd) if _, err := fhelp.RunRealtimeError(cmd); err != nil { if !argv.Force { msg := fmt.Sprintf("failed: %v", cmd) me.argv.BadExit(msg, err) } } } } return nil } func makeNewRepomap(lines string) { for _, line := range strings.Split(lines, "\n") { if line == "" { log.Info(line) continue } if strings.HasPrefix(line, "#") { log.Info(line) continue } parts := strings.Fields(line) namespace := parts[0] repo := me.forge.Repos.FindByNamespace(namespace) if repo == nil { log.Info(line) continue } newparts := []string{namespace} newparts = append(newparts, repo.URL) if len(parts) > 2 { newparts = append(newparts, parts[2:]...) } newline := strings.Join(newparts, " ") log.Info(newline) } }