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
|
package repolist
import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"strings"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/log"
)
func (v *RepoList) InitRepoList(cfgfile string) {
v.cfgfile = cfgfile
lines := parsecfg(cfgfile)
for _, line := range lines {
var repo *RepoRow
var err error
line = strings.TrimSpace(line)
if line == "" {
// skip empty lines
continue
}
if strings.HasPrefix(line, "#") {
// skip config file comment lines
continue
}
parts := strings.Split(line, " ")
var private bool = false
var readonly bool = false
var userdir bool = false
if len(parts) > 1 {
repodir := parts[0]
for _, s := range parts[1:] {
option := strings.Split(s, "=")
if len(option) != 2 {
log.Log(REPOWARN, "can not parse cfgfile line:", line)
continue
}
switch option[0] {
case "private":
if option[1] == "true" {
log.Log(REPOWARN, repodir, "setting private to true")
private = true
} else {
log.Log(REPOWARN, repodir, "setting private to false")
private = false
}
case "readonly":
if option[1] == "true" {
log.Log(REPOWARN, repodir, "setting ReadOnly to true")
readonly = true
} else {
log.Log(REPOWARN, repodir, "setting ReadOnly to false")
readonly = false
}
case "userdir":
if option[1] == "true" {
log.Log(REPOWARN, repodir, "setting this directory as Writable()")
userdir = true
} else {
userdir = false
}
default:
log.Log(REPOWARN, "unknown config file option", s)
}
}
}
if userdir {
log.Log(REPOWARN, "add this as a writable dir", line)
continue
}
if len(parts) > 0 {
path := parts[0]
repo, err = v.NewRepo(path)
}
if err != nil {
log.Log(REPOWARN, line, "repo could not be added", err)
continue
}
if repo == nil {
// there is not a new repo
continue
}
if private {
repo.Status.SetPrivate(true)
} else {
repo.Status.SetPrivate(false)
}
if readonly {
repo.Status.SetReadOnly(true)
} else {
repo.Status.SetReadOnly(false)
}
}
}
func parsecfg(f string) []string {
homeDir, _ := os.UserHomeDir()
cfgfile := filepath.Join(homeDir, f)
content, err := ioutil.ReadFile(cfgfile)
if err != nil {
log.Log(REPOWARN, "read cfgfile error", err)
return nil
}
out := string(content)
out = strings.TrimSpace(out)
lines := strings.Split(out, "\n")
return lines
}
func (rl *RepoList) ArgGitPull() bool {
var localonly int
var badmap int
log.Log(REPOWARN, "running git pull everywhere")
var failed int = 0
for _, repo := range rl.AllRepos() {
if out, err := repo.Status.GitPull(); err == nil {
log.Log(REPOWARN, "Ran git pull ok", repo.Status.Path(), out)
} else {
failed += 1
repo.Status.DumpTags()
if errors.Is(repostatus.ErrorGitPullOnLocal, err) {
localonly += 1
continue
}
badmap += 1
log.Log(REPOWARN, "bad unknown git error", repo.Status.Path(), out, err)
}
}
log.Log(REPOWARN, "Ran git pull in all repos. failure count =", failed)
log.Log(REPOWARN, "Ran git pull in all repos. bad errors =", badmap)
if localonly != 0 {
log.Log(REPOWARN, "Ran git pull in all repos. ignored local only branches =", localonly)
}
return true
}
func (rl *RepoList) ArgCheckoutDevel() bool {
log.Log(REPOWARN, "running git checkout devel everwhere")
var failed int = 0
var count int = 0
for _, repo := range rl.AllRepos() {
count += 1
if repo.Status.CheckoutDevel() {
// checkout ok
} else {
failed += 1
}
}
log.Log(REPOWARN, "Ran git checkout in", count, "repos. failure count =", failed)
return true
}
func (rl *RepoList) ArgCheckoutMaster() bool {
log.Log(REPOWARN, "running git checkout master everwhere")
var failed int = 0
var count int = 0
for _, repo := range rl.AllRepos() {
count += 1
if repo.Status.CheckoutMaster() {
// checkout ok
} else {
failed += 1
}
}
log.Log(REPOWARN, "Ran git checkout in", count, "repos. failure count =", failed)
return true
}
func (rl *RepoList) ArgCheckoutUser() bool {
log.Log(REPOWARN, "running git checkout master everwhere")
var failed int = 0
var count int = 0
for _, repo := range rl.AllRepos() {
count += 1
if repo.Status.CheckoutUser() {
// checkout ok
} else {
failed += 1
}
}
log.Log(REPOWARN, "Ran git checkout in", count, "repos. failure count =", failed)
return true
}
func (rl *RepoList) Cfgfile() string {
return rl.cfgfile
}
|