1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// 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
*/
}
footer := me.forge.PrintPullTable(updatecheck)
log.Info("These repos have broken URLs. Fix them with --fix", footer)
return nil
}
|