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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
// checks that repos are in a "normal" state
import (
"errors"
"fmt"
"path/filepath"
"strings"
"time"
"go.wit.com/lib/ENV"
"go.wit.com/lib/config"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
"google.golang.org/protobuf/proto"
)
// when in normal and requestiong "normal" again, do more stuff
func doNormalAll() (string, error) {
var s string
var err error
me.curpatches = forgepb.NewPatches()
me.curpatches.Filename = ENV.Get("curpatches")
if me.curpatches.Filename == "" {
panic("config failed. no 'curpatches' set in ~/.config/forge/config.text")
}
if err := me.curpatches.Load(); err != nil {
me.curpatches.Save()
me.curpatches.Save()
log.Info(err)
panic("no file")
// return
// // THIS IS NEEDED? NOTSURE
me.curpatches = forgepb.NewPatches()
me.curpatches.Filename = ENV.Get("curpatches")
me.curpatches.Save()
}
psets := forgepb.NewSets()
newpb, _, _ := psets.HttpPostVerbose(myServer(), "get")
footer, err := doPatchGet(newpb)
if footer == "" {
log.Info(footer)
}
// forces patching to be done in 'NORMAL' mode
// forge is too new to be able to handle anything else
if !isPatchingSafe() {
return "not safe", errors.New("not safe to work on patches")
}
s, err = doPatchProcess()
return s, err
}
func (a *args) DoNormal() (string, error) {
return doNormalAttempt()
}
// try to switch to "Normal" mode
func doNormalAttempt() (string, error) {
start := time.Now()
err := me.forge.DoAllCheckoutUser(argv.Force)
me.forge.RescanRepos() // looks for new dirs, checks existing repos for changes
dur := time.Since(start)
log.Printf("Checked out %d user braches in %s\n", me.forge.Repos.Len(), shell.FormatDuration(dur))
if err != nil {
return "not everything is 'normal' yet", err
}
me.forge.SetMode(forgepb.ForgeMode_NORMAL)
log.Info("normal mode on")
return "normal mode on", nil
}
// a quick check run each time when in "normal" mode
func doNormalStatus() bool {
me.forge.CheckDirtyQuiet()
var count int
stats := me.forge.RillRepos(checkNormalRepoState)
for path, stat := range stats {
dur := stat.End.Sub(stat.Start)
if dur > 10*time.Second {
log.Infof("%s checkNormalRepoState() took a long time (%s)\n", path, shell.FormatDuration(dur))
}
if stat.Err == nil {
continue
}
repo := me.forge.Repos.FindByFullPath(path)
if repo == nil {
log.Info("path deleted while running?", path)
continue
}
if stat.Err == ErrorLocalDevelBranch {
if argv.Fix {
bname := repo.GetDevelBranchName()
s := fmt.Sprintf("repair the %s branch on %s", bname, repo.FullPath)
if fhelp.QuestionUser(s) {
// todo, check to make sure we aren't on this branch
repo.RunVerbose([]string{"git", "checkout", repo.GetMasterBranchName()})
repo.RunVerbose([]string{"git", "branch", "-D", bname})
repo.RunVerbose([]string{"git", "checkout", bname})
}
}
}
if stat.Err == ErrorLocalMasterBranch {
if argv.Fix {
bname := repo.GetMasterBranchName()
s := fmt.Sprintf("repair the %s branch on %s", bname, repo.FullPath)
if fhelp.QuestionUser(s) {
// todo, check to make sure we aren't on this branch
repo.RunVerbose([]string{"git", "branch", "-D", bname})
repo.RunVerbose([]string{"git", "checkout", bname})
}
}
}
if stat.Err == ErrorLocalBehindDevel {
log.Info(path, "local branch is behind devel?")
}
// log.Infof("%-60s, %-60s %v %s\n", stat.Start, stat.End.String(), dur, path)
// log.Infof("%-30v %s %v\n", dur, path, stat.Err)
// log.Info("got path", path, stat.Err)
count += 1
}
if count > 0 {
log.Info("Some repos are not in a 'normal' state. error count =", count)
log.Info("TODO: list the repos here. forge patch repos?")
found := findWorkRepos()
found.SortNamespace()
if found.Len() == 0 {
log.Info("you currently have no repos with patches")
// return "you currently have no repos with patches", nil
}
footer := me.forge.PrintDefaultTB(found)
log.Info("repos with patches or unsaved changes: " + footer)
// return "repos with patches or unsaved changes: " + footer, nil
config.SetChanged("repos", true)
return false
}
return true
}
// 99% of the time, the repos during development should be on your user branch.
// error out if it's not
// this checks to see if a devel and user branch exist
// this needs to run each time in case repos were added manually by the user
// this also verifies that
func checkNormalRepoState(repo *gitpb.Repo) error {
var err error
tmp := filepath.Join(ENV.Get("gopath"), repo.GetNamespace())
if tmp != repo.FullPath {
log.Infof("checkNormalRepoState() %s != %s\n", repo.FullPath, tmp)
if strings.HasPrefix(repo.FullPath, ENV.Get("gopath")) {
tmp = strings.TrimPrefix(repo.FullPath, ENV.Get("gopath"))
tmp = strings.Trim(tmp, "/")
repo.Namespace = tmp
err = log.Errorf("namespace set to filepath")
}
} else {
// log.Infof("%s == %s\n", repo.FullPath, tmp)
}
tmp = strings.Trim(repo.Namespace, "/")
if tmp != repo.Namespace {
err = log.Errorf("junk in ns %s", repo.Namespace)
repo.Namespace = tmp
}
if repo.GetMasterBranchName() == "" {
me.forge.VerifyBranchNames(repo)
log.Info("ABNORMAL: master branch name was blank in", repo.GetFullPath())
}
if repo.GetMasterBranchName() == "" {
me.forge.VerifyBranchNames(repo)
err = log.Errorf("master branch name blank")
}
if repo.GetDevelBranchName() == "" {
me.forge.VerifyBranchNames(repo)
err = log.Errorf("devel branch name blank")
}
if repo.GetUserBranchName() == "" {
me.forge.VerifyBranchNames(repo)
err = log.Errorf("user branch name blank")
}
if repo.GetGoPath() == repo.GetNamespace() {
// log.Info(repo.FullPath, "gopath == namespace", repo.GetGoPath(), repo.GetNamespace())
} else {
log.Info(repo.FullPath, "gopath != namespace", repo.GetGoPath(), repo.GetNamespace())
}
repo.MakeLocalDevelBranch()
if !repo.VerifyRemoteAndLocalBranches(repo.GetDevelBranchName()) {
return ErrorLocalDevelBranch
}
if !repo.VerifyRemoteAndLocalBranches(repo.GetMasterBranchName()) {
return ErrorLocalMasterBranch
}
if repo.Tags.Master == nil {
if found := repo.GetRemoteTag(repo.GetMasterBranchName()); found != nil {
// log.Info("found master tag ", repo.FullPath, found)
repo.Tags.Master = proto.Clone(found).(*gitpb.GitTag)
config.SetChanged("repos", true)
} else {
log.Info("not found master tag (Reload() ?)", repo.FullPath)
}
}
if repo.IsBranchRemote(repo.GetUserBranchName()) {
log.Info(repo.FullPath)
}
// check to see if the user branch is behind the devel branch
if repo.GetUserVersion() != repo.GetDevelVersion() {
uver := repo.NewCompareTag(repo.GetUserBranchName())
dver := repo.NewCompareTag(repo.GetDevelBranchName())
if uver == nil {
log.Info(repo.FullPath, "uver == nil")
// make user here (should have already happened)
return ErrorNoUserBranch
}
if dver == nil {
log.Info(repo.FullPath, "dver == nil")
// make dev here (should have already happened)
return ErrorNoDevelBranch
}
/*
// THIS IS WRONG LOGIC
if len(dver.GreaterThan(uver)) == 0 {
log.Info(repo.FullPath, "usr < dev")
repo.State = "usr < dev"
// check if nothing new exists in user, then delete
return ErrorLocalBehindDevel
} else {
repo.State = "normal"
}
*/
// everything is fine
}
if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
log.Infof("changing to user(%s) branch: %s\n", repo.GetUserBranchName(), repo.FullPath)
repo.CheckoutUser()
repo.ReloadCheck()
err = log.Errorf("now on user branch")
}
// hopefully this can be deprecated soon
if repo.Namespace != repo.GetGoPath() {
log.Info(repo.Namespace, repo.GetGoPath())
}
// verify read-only
if me.forge.Config.IsReadOnly(repo.GetNamespace()) != repo.GetReadOnly() {
repo.ReadOnly = me.forge.Config.IsReadOnly(repo.GetNamespace())
log.Info("damnit", repo.FullPath)
err = log.Errorf("readonly bit wrong")
}
return err
}
|