diff options
| author | Jeff Carr <[email protected]> | 2025-10-07 20:43:43 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-07 20:43:43 -0500 |
| commit | 34ac2291bc0d9321b078cf70f81684fc4d14e7e8 (patch) | |
| tree | 3fa312d39fb1d39b9d0c565d04ead4f9cc151fd5 /doFix.urls.go | |
| parent | 2b01cc8c01a82bf8c5fbecea831e61660d9103f7 (diff) | |
make "Fix" subcommand
Diffstat (limited to 'doFix.urls.go')
| -rw-r--r-- | doFix.urls.go | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/doFix.urls.go b/doFix.urls.go new file mode 100644 index 0000000..e516107 --- /dev/null +++ b/doFix.urls.go @@ -0,0 +1,89 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "strings" + + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func updateURL(repo *gitpb.Repo) bool { + found := me.forge.Repos.FindByNamespace(repo.Namespace) + if found == nil { + return false + } + if repo.URL == found.URL { + return false + } + cmd := []string{"git", "remote", "set-url", "origin", repo.URL} + found.URL = repo.URL + if argv.Fix { + log.Infof("%s update URL to %v\n", found.URL, cmd) + found.Run(cmd) + return true + } + log.Infof("add --fix to update %s with %v\n", found.URL, cmd) + return true +} + +func doFixUrls() error { + submit := me.forge.PrepareCheckRepos() + updatepb, regPB, err := submit.HttpPost(myServer(), "check") + if err != nil { + log.Info("err =", err) + } + if regPB == nil { + log.Info("regPB==nil") + } + if updatepb == nil { + log.Info("server sent nil back") + return err + } + var count int + // log.Infof("pull check %s pb.Len()=%d client.Len()=%d server.Len()=%d err=%v\n", regPB.URL, updatepb.Len(), regPB.ClientDataLen, regPB.ServerDataLen, err) + log.Infof("pull check pb.Len()=%d\n", updatepb.Len()) + updatecheck := gitpb.NewRepos() + for repo := range updatepb.IterAll() { + if updateURL(repo) { + count += 1 + } + if repo.Namespace == "" { + log.Info("forge sent back empty namespace", repo) + continue + } + found := me.forge.Repos.FindByNamespace(repo.Namespace) + if found == nil { + log.Info("you don't have namespace?", repo.Namespace) + continue + } + if !strings.HasPrefix(found.Namespace, "go.wit.com") { + continue + } + updatecheck.Append(repo) + // spew.Dump(repo) + // me.sh.GoodExit("") + /* + found, _ := needToUpdateRepo(repo) + if found == nil { + continue + } + if !argv.Force { + continue + } + // found.RunVerbose([]string{"git", "pull", "origin", found.GetMasterBranchName()}) + found.CheckoutMaster() + found.GitPull() + found.ReloadCheck() + found.GitPull() + if count > 10 { + break + } + count += 1 + */ + } + me.forge.PrintPullTable(updatecheck) + return nil +} |
