summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-12 23:50:38 -0600
committerJeff Carr <[email protected]>2024-12-12 23:50:38 -0600
commit4e94089128d88f6c7778a6e71884d583eb06e1b8 (patch)
treec0d76f5d235568ff399b0365202da61a652938c5
parent4928804bf41c8c9194390e122cd9337d624b7eed (diff)
cleaner Init() output
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--goSrcFind.go21
-rw-r--r--goSrcScan.go24
-rw-r--r--init.go23
3 files changed, 42 insertions, 26 deletions
diff --git a/goSrcFind.go b/goSrcFind.go
index e776cf0..7dbb26f 100644
--- a/goSrcFind.go
+++ b/goSrcFind.go
@@ -17,26 +17,26 @@ import (
// otherwise use ~/go/src
func (f *Forge) findGoSrc() (string, error) {
pwd, err := os.Getwd()
- startpwd, _ := os.Getwd()
+ // startpwd, _ := os.Getwd()
if err == nil {
- log.Info("forge.findGoSrc() trying digup", pwd, err)
// Check for go.work in the current directory and then move up until root
if pwd, err := digup(pwd); err == nil {
- log.Info("forge.findGoSrc() using go.work file in directory", pwd)
f.goWork = true
// found an existing go.work file
// os.Chdir(pwd)
return pwd, nil
} else {
- log.Info("forge.digup() err", pwd, err)
+ // if there is an error looking for the go.work file
+ // default to using ~/go/src
+ // log.Info("forge.digup() err", pwd, err)
}
} else {
- log.Info("forge.findGoSrc() os.Getwd()", pwd, err)
+ // this shouldn't really happen. maybe your working directory got deleted
+ log.Info("forge.findGoSrc() os.Getwd() was probably deleted", pwd, err)
}
// there are no go.work files, resume the ~/go/src behavior from prior to golang 1.22
pwd, err = useGoSrc()
- log.Info("forge.findGoSrc() 2 using ~/go/src directory", pwd, "start was", startpwd)
return pwd, err
}
@@ -57,26 +57,23 @@ func (f *Forge) goWorkExists() bool {
var err error
workFilePath := filepath.Join(f.GetGoSrc(), "go.work")
if _, err = os.Stat(workFilePath); err == nil {
- log.Info("f.goWorkExists() found", workFilePath)
+ // log.Info("f.goWorkExists() found", workFilePath)
return true
} else if !os.IsNotExist(err) {
- log.Info("f.goWorkExists() missing", workFilePath)
+ // log.Info("f.goWorkExists() missing", workFilePath)
return false
}
// probably false, but some other error
- log.Info("f.goWorkExists() os.Stat() error", err, workFilePath)
+ // log.Info("f.goWorkExists() os.Stat() error", err, workFilePath)
return false
}
func digup(path string) (string, error) {
for {
workFilePath := filepath.Join(path, "go.work")
- log.Info("digup trying", workFilePath)
if _, err := os.Stat(workFilePath); err == nil {
- log.Info("digup found", path)
return path, nil // Found the go.work file
} else if !os.IsNotExist(err) {
- log.Info("forgepb.digup() failed", workFilePath, err)
return "", err // An error other than not existing
}
diff --git a/goSrcScan.go b/goSrcScan.go
index 1879a1b..6670259 100644
--- a/goSrcScan.go
+++ b/goSrcScan.go
@@ -50,6 +50,8 @@ func (f *Forge) ScanGoSrc() (bool, error) {
// not stupid like my old version
func gitDirectoriesNew(srcDir string) ([]string, error) {
var all []string
+ var trip bool
+ reposfile := filepath.Join(srcDir, "repos.pb")
err := filepath.WalkDir(srcDir, func(path string, d os.DirEntry, err error) error {
if err != nil {
// Handle possible errors, like permission issues
@@ -60,7 +62,13 @@ func gitDirectoriesNew(srcDir string) ([]string, error) {
if d.IsDir() {
// log.Info("path is dir", path)
} else {
- log.Info("warning: you have an untracked file:", path)
+ if path == reposfile {
+ // ignore repos.pb // todo: also ignore go.work // add config option to not warn about this
+ } else {
+ // todo: figure out a way to do padding for init()
+ log.Info("WARNING: you have an untracked file outside of any .git repository:", path)
+ trip = true
+ }
return nil
}
@@ -72,6 +80,20 @@ func gitDirectoriesNew(srcDir string) ([]string, error) {
}
return nil
})
+ //
+ // probably always leave this here forever
+ // this check, along with CheckDirty() makes sure you can safely delete ~/go/src or the go.work directory
+ // because everything is either checked in or deleted. An important thing to know!
+ if trip {
+ log.Info("WARNING:")
+ log.Info("WARNING: there isn't a way to disable this warning yet")
+ log.Info("WARNING: probably this is a good thing however. you don't want to leave files outside of git repos here")
+ log.Info("WARNING: so this warning should probably stay")
+ log.Info("WARNING:")
+ log.Info("WARNING: this also might mean you put these files here because you are actively working on them")
+ log.Info("WARNING: and you don't want to forget about them")
+ log.Info("WARNING:")
+ }
return all, err
}
diff --git a/init.go b/init.go
index ac4e092..ca40f25 100644
--- a/init.go
+++ b/init.go
@@ -12,21 +12,17 @@ import (
func Init() *Forge {
f := new(Forge)
- getwd, _ := os.Getwd()
- log.Info("forgepbb.Init() os.Getwd()", getwd)
- log.Info("forgepbb.Init() started with FORGE_CONFIG", os.Getenv("FORGE_CONFIG"))
- log.Info("forgepbb.Init() started with FORGE_GOSRC", os.Getenv("FORGE_GOSRC"))
// TODO: rethink this but it works for now
gosrc := os.Getenv("FORGE_GOSRC")
if gosrc == "" {
goSrcDir, err := f.findGoSrc()
if err != nil {
log.Warn("forge init() findGoSrc()", err)
+ os.Exit(-1)
}
os.Setenv("FORGE_GOSRC", goSrcDir)
}
f.goSrc = os.Getenv("FORGE_GOSRC")
- log.Info("forge.Init() using ~/go/src directory", f.goSrc)
// also rethink this, but maybe this is the right thing to do
if os.Getenv("FORGE_CONFIG") == "" {
@@ -34,12 +30,15 @@ func Init() *Forge {
fullpath := filepath.Join(homeDir, ".config/forge")
os.Setenv("FORGE_CONFIG", fullpath)
}
+
+ // check again for go.work // user could have a go.work file in ~/go/src
if f.goWorkExists() {
f.goWork = true
}
- log.Info("forgepbb.Init() ~/go/src ", f.goSrc)
- log.Info("forgepbb.Init() 2 FORGE_CONFIG", os.Getenv("FORGE_CONFIG"))
- log.Info("forgepbb.Init() 2 FORGE_GOSRC", os.Getenv("FORGE_GOSRC"), "f.goWork =", f.IsGoWork())
+
+ // print out the settings that will be used
+ log.Info("forgepbb.Init() FORGE_CONFIG", os.Getenv("FORGE_CONFIG"))
+ log.Info("forgepbb.Init() FORGE_GOSRC ", os.Getenv("FORGE_GOSRC"), "f.goWork =", f.IsGoWork())
// cache.go has Do()
// f.initOnce.Do(f.initWork)
@@ -65,12 +64,10 @@ func Init() *Forge {
start := f.Repos.Len()
f.ScanGoSrc()
end := f.Repos.Len()
- log.Info("forge.ScanGoSrc() Found", end-start, "new repos in", f.goSrc)
- testenv := os.Getenv("GO111MODULE")
- if testenv == "off" {
- log.Info("GO111MODULE=off", "f.goWork =", f.IsGoWork(), "f.gosrc =", f.GetGoSrc())
+ if (end - start) == 0 {
+ log.Info("Scan of", f.GetGoSrc(), "did not find new git repositories")
} else {
- log.Info("GO111MODULE=", testenv, "f.goWork =", f.IsGoWork(), "f.gosrc =", f.GetGoSrc())
+ log.Info("Scan of", f.GetGoSrc(), "Found", end-start, "new git repositories")
}
return f
}