summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-17 06:37:14 -0600
committerJeff Carr <[email protected]>2024-12-17 06:37:14 -0600
commit233f7bca767aab9df55adea409e9820050631586 (patch)
tree1ce61760e8b31077b9accc9b1da978d935a132d3 /config.go
parent4bc95ad2684cb42159229b8198aa8a2377f80aa1 (diff)
lots of changes to isolate exec 'git'
Diffstat (limited to 'config.go')
-rw-r--r--config.go47
1 files changed, 19 insertions, 28 deletions
diff --git a/config.go b/config.go
index 2fc02d0..9b38238 100644
--- a/config.go
+++ b/config.go
@@ -33,7 +33,9 @@ func (all *Repos) ConfigSave() error {
return nil
}
-// load the ~/.config/forge/ files
+// load the repos.pb file. I shouldn't really matter if this
+// fails. the file should be autogenerated. This is used
+// locally just for speed
func (all *Repos) ConfigLoad() error {
if os.Getenv("FORGE_GOSRC") == "" {
homeDir, _ := os.UserHomeDir()
@@ -46,36 +48,25 @@ func (all *Repos) ConfigLoad() error {
cfgname := filepath.Join(os.Getenv("FORGE_GOSRC"), "repos.pb")
if data, err = loadFile(cfgname); err != nil {
// something went wrong loading the file
+ // all.sampleConfig() // causes nil panic
return err
}
- if data != nil {
- // this means the forge.pb file exists and was read
- if len(data) == 0 {
- // todo: error out if the file is empty?
- // try forge.text & forge.json?
- log.Warn("gitpb.ConfigLoad() repos.pb is empty")
- return errors.New("gitpb.ConfigLoad() repos.pb is empty")
- }
- if all.Repos == nil {
- // log.Warn("gitpb.ConfigLoad() all.Repos == nil")
- } else {
- log.Warn("gitpb.ConfigLoad() error. should be zero. all.Repos.Len() =", all.Len())
- }
- if err = all.Unmarshal(data); err != nil {
- log.Warn("gitpb.ConfigLoad() failed", err)
- if all.Repos == nil {
- log.Warn("gitpb.ConfigLoad() all.Repos == nil")
- } else {
- log.Warn("gitpb.ConfigLoad() all.Repos.Len()", all.Len())
- log.Warn("gitpb.ConfigLoad() trying to resave the file")
- all.ConfigSave()
- }
- return err
- }
- log.Info("gitpb.Init() ", len(all.Repos), "repos in", cfgname)
- return nil
+ // this means the forge.pb file exists and was read
+ if len(data) == 0 {
+ all.sampleConfig() // causes nil panic
+ return errors.New("gitpb.ConfigLoad() repos.pb is empty")
+ }
+ return all.Unmarshal(data)
+}
+
+func (all *Repos) sampleConfig() {
+ newr := new(Repo)
+ newr.FullPath = "/opt/forge/dummyentry"
+ if all.Append(newr) {
+ log.Info("added", newr.GetGoPath(), "ok")
+ } else {
+ log.Info("added", newr.GetGoPath(), "failed")
}
- return nil
}
func loadFile(fullname string) ([]byte, error) {