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
|
package repolist
import (
"fmt"
"os"
"path/filepath"
"sort"
"go.wit.com/gui"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/log"
)
func (r *RepoList) Hidden() bool {
return r.reposbox.Hidden()
}
func (r *RepoList) Show() {
r.reposbox.Show()
}
func (r *RepoList) Hide() {
r.reposbox.Hide()
}
// better name: use this
func (r *RepoList) FindRepoByName(path string) *RepoRow {
return r.FindRepo(path)
}
func (r *RepoList) FindRepo(path string) *RepoRow {
repo, _ := me.allrepos[path]
return repo
}
func (r *RepoList) AllRepos() []*RepoRow {
var all []*RepoRow
for _, repo := range me.allrepos {
all = append(all, repo)
}
return all
}
// deprecate this
func AllRepos() []*RepoRow {
var all []*RepoRow
for _, repo := range me.allrepos {
all = append(all, repo)
}
return all
}
// a human readable state of the current repo
func (r *RepoRow) State() string {
return r.gitState.String()
}
func (r *RepoRow) Scan() int {
return r.NewScan()
}
// returns a name for human consuption only
// todo: implement nicknames
func (rs *RepoRow) Name() string {
if rs.Status.IsGoLang() {
return rs.Status.GoPath()
}
return rs.Status.Path()
}
func (r *RepoRow) GoPath() string {
return r.Status.GoPath()
}
func (r *RepoRow) CheckDirty() bool {
return r.Status.CheckDirty()
}
func (r *RepoRow) IsDirty() bool {
return r.Status.IsDirty()
}
func (r *RepoRow) ReadOnly() bool {
if r == nil {
log.Warn("ReadOnly() repo == nil")
return false
}
if r.Status == nil {
log.Warn("ReadOnly() repo.Status == nil")
return false
}
return r.Status.ReadOnly()
}
func (r *RepoRow) LastTag() string {
if r == nil {
log.Warn("LastTag() repo == nil")
return ""
}
return r.lastTag.String()
}
/*
// returns the state of the GO go.mod and go.sum files
// this is used to tell if they are valid and correctly reflect
// the versions of the other GUI packages
// at this point in time, there is _NO_ way to be check our
// be sure that anything will run with older versions
// because this are changing too often at this point
// TODO: revisit this in 2025 or 2026
func (r *RepoRow) GoState() string {
if r == nil {
log.Info("GoState() r == nil")
return "goState == nil"
}
if r.goState == nil {
log.Info("GoState() r.goState == nil")
return "goState == nil"
}
return r.goState.String()
}
func (r *RepoRow) SetGoState(s string) {
if r == nil {
log.Info("SetGoState() r == nil")
return
}
if r.goState == nil {
log.Info("goState == nil")
return
}
r.goState.SetText(s)
}
*/
func (r *RepoRow) IsPerfect() bool {
if r.gitState.String() == "PERFECT" {
return true
}
if r.gitState.String() == "unchanged" {
return true
}
return false
}
func (r *RepoRow) RunCmd(cmd []string) (error, string) {
return r.Status.RunCmd(cmd)
}
func (r *RepoRow) AllTags() []*repostatus.Tag {
return r.Status.Tags.ListAll()
}
func (r *RepoRow) TagsBox() *repostatus.GitTagBox {
return r.Status.Tags
}
// todo, fix bool return for deletetag()
func (r *RepoRow) DeleteTag(t *repostatus.Tag) bool {
r.Status.DeleteTag(t)
return true
}
func (rl *RepoList) MirrorShownCount() *gui.Node {
return gui.RawMirror(rl.shownCount)
}
func (rl *RepoList) MirrorScanDuration() *gui.Node {
return gui.RawMirror(rl.duration)
}
func (rl *RepoList) Total() int {
return len(me.allrepos)
}
func (rl *RepoList) TotalGo() int {
var count int
for _, repo := range me.allrepos {
if repo.Status.IsGoLang() {
count += 1
}
}
return count
}
// very much a hack job
func (rl *RepoList) MakeGoWork() error {
goSrcDir := os.Getenv("REPO_WORK_PATH")
filename := filepath.Join(goSrcDir, "go.work")
f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
return err
}
defer f.Close()
fmt.Fprintln(f, "go 1.21.4") // fix this
fmt.Fprintln(f, "")
fmt.Fprintln(f, "use (")
keys := make([]string, 0, len(rl.allrepos))
for k := range rl.allrepos {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
repo := rl.allrepos[k]
if repo.Status.GoPath() == "" {
// skip repos that aren't go
// todo: handle non-flat repos?
log.Info("SKIPPED REPO", repo.Status.Path())
continue
}
if repo.Status.Exists("go.mod") {
fmt.Fprintln(f, "\t"+repo.Status.GoPath())
log.Info("ADDING REPO", goSrcDir, repo.Status.GoPath())
} else {
log.Log(REPO, "missing go.mod for", repo.Status.Path())
// repo.Status.MakeRedomod()
}
}
fmt.Fprintln(f, ")")
return nil
}
|