lots of changes to isolate exec 'git'
This commit is contained in:
parent
4bc95ad268
commit
233f7bca76
Notes:
Jeff Carr
2024-12-17 15:53:13 -06:00
// `autogen:go.mod` module go.wit.com/lib/protobuf/gitpb go 1.21 toolchain go1.23.4 require ( github.com/destel/rill v0.6.0 github.com/go-cmd/cmd v1.4.3 go.wit.com/lib/gui/shell v0.22.18 go.wit.com/log v0.22.9 google.golang.org/protobuf v1.36.0 ) // `autogen:go.sum` github.com/destel/rill v0.6.0 h1:8MQRzS6k0akKmwNZFahKIhG1dkBeNxMoWKSfOxkaJNw= github.com/destel/rill v0.6.0/go.mod h1:srKuXzvGqINUEGYR5b/iwvW+L9/S35RxVHWGYbXNoO4= github.com/go-cmd/cmd v1.4.3 h1:6y3G+3UqPerXvPcXvj+5QNPHT02BUw7p6PsqRxLNA7Y= github.com/go-cmd/cmd v1.4.3/go.mod h1:u3hxg/ry+D5kwh8WvUkHLAMe2zQCaXd00t35WfQaOFk= github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= go.wit.com/lib/gui/shell v0.22.18 h1:2z14XRxGrNjRKVsfvlk70sWsRZWoLdnL7z0FS+BFzFM= go.wit.com/lib/gui/shell v0.22.18/go.mod h1:zduuMSWq+EE7w0xbXn+vkoGZ4HJhURVJpvXw8oK9WAU= go.wit.com/log v0.22.9 h1:aBM6SI2kxlJcBfS/osFTomJqNhO0hfEo1gk+LCqLk7Y= go.wit.com/log v0.22.9/go.mod h1:4uNPFBqhsAh8zNF+zxVEmC3c/9AZ8JeTfUUvRpddvLQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ= google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= // `autogen:`
6
age.go
6
age.go
|
@ -28,7 +28,7 @@ func (repo *Repo) GoSumAge() (time.Duration, error) {
|
|||
return time.Since(mtime), nil
|
||||
}
|
||||
now := time.Now()
|
||||
return time.Since(now), errors.New(repo.GoPath + " go.mod missing")
|
||||
return time.Since(now), errors.New(repo.GetGoPath() + " go.mod missing")
|
||||
}
|
||||
|
||||
func (repo *Repo) GitChanged() bool {
|
||||
|
@ -39,7 +39,7 @@ func (repo *Repo) GitChanged() bool {
|
|||
log.Info("gitpb:", fullfile, "changed")
|
||||
return true
|
||||
}
|
||||
newtime := repo.LastPull.AsTime()
|
||||
newtime := repo.Times.LastPull.AsTime()
|
||||
|
||||
if lasttime == newtime {
|
||||
return false
|
||||
|
@ -52,7 +52,7 @@ func (repo *Repo) GitPullAge() time.Duration {
|
|||
lastpull, err := repo.LastGitPull()
|
||||
if err == nil {
|
||||
// if error, something is wrong, assume true
|
||||
ltime := repo.LastPull.AsTime()
|
||||
ltime := repo.Times.LastPull.AsTime()
|
||||
return time.Since(ltime)
|
||||
}
|
||||
|
||||
|
|
21
changed.go
21
changed.go
|
@ -29,8 +29,12 @@ func (repo *Repo) changedDir() bool {
|
|||
// .git doesn't exist. something is wrong. rescan this repo
|
||||
return true
|
||||
}
|
||||
pbtime := repo.Times.MtimeDir
|
||||
mtime := timestamppb.New(*fileTime)
|
||||
pbtime := repo.Times.MtimeDir
|
||||
if pbtime == nil { // this can happen?
|
||||
repo.Times.MtimeDir = mtime
|
||||
return true
|
||||
}
|
||||
if (pbtime.Seconds == mtime.Seconds) && (pbtime.Nanos == mtime.Nanos) {
|
||||
return false
|
||||
}
|
||||
|
@ -47,8 +51,13 @@ func (repo *Repo) changedHead() bool {
|
|||
// .git/HEAD doesn't exist. something is wrong. rescan this repo
|
||||
return true
|
||||
}
|
||||
pbtime := repo.Times.MtimeHead
|
||||
mtime := timestamppb.New(*fileTime)
|
||||
pbtime := repo.Times.MtimeHead
|
||||
if pbtime == nil { // this can happen?
|
||||
repo.Times.MtimeHead = mtime
|
||||
return true
|
||||
}
|
||||
|
||||
if (pbtime.Seconds == mtime.Seconds) && (pbtime.Nanos == mtime.Nanos) {
|
||||
return false
|
||||
}
|
||||
|
@ -65,8 +74,12 @@ func (repo *Repo) changedIndex() bool {
|
|||
// .git/index doesn't exist. something is wrong. rescan this repo
|
||||
return true
|
||||
}
|
||||
pbtime := repo.Times.MtimeIndex
|
||||
mtime := timestamppb.New(*fileTime)
|
||||
pbtime := repo.Times.MtimeIndex
|
||||
if pbtime == nil { // this can happen?
|
||||
repo.Times.MtimeIndex = mtime
|
||||
return true
|
||||
}
|
||||
if (pbtime.Seconds == mtime.Seconds) && (pbtime.Nanos == mtime.Nanos) {
|
||||
return false
|
||||
}
|
||||
|
@ -90,7 +103,7 @@ func (repo *Repo) RepoChanged() bool {
|
|||
changed = true
|
||||
}
|
||||
if repo.changedDir() {
|
||||
changed = true
|
||||
// changed = true
|
||||
}
|
||||
|
||||
return changed
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package gitpb
|
||||
|
||||
import "go.wit.com/log"
|
||||
|
||||
func (repo *Repo) SetReadOnly(b bool) {
|
||||
repo.ReadOnly = b
|
||||
}
|
||||
|
@ -9,5 +11,13 @@ func (repo *Repo) SetTargetVersion(target string) {
|
|||
}
|
||||
|
||||
func (repo *Repo) SetMasterBranchName(s string) {
|
||||
log.Info("gitpb.SetMaster() SET MASTER TO", s)
|
||||
repo.MasterBranchName = s
|
||||
}
|
||||
|
||||
func (repo *Repo) GetGoPath() string {
|
||||
if repo.GoInfo == nil {
|
||||
return ""
|
||||
}
|
||||
return repo.GoInfo.GoPath
|
||||
}
|
47
config.go
47
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) {
|
||||
|
|
|
@ -14,44 +14,50 @@ import (
|
|||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func (repo *Repo) GetMasterVersion() string {
|
||||
func (repo *Repo) InitVersions() {
|
||||
repo.setMasterVersion()
|
||||
repo.setDevelVersion()
|
||||
repo.setUserVersion()
|
||||
}
|
||||
|
||||
func (repo *Repo) setMasterVersion() {
|
||||
bname := repo.GetMasterBranchName()
|
||||
v, err := repo.gitVersionByName(bname)
|
||||
/*
|
||||
count := repo.LenGitTags()
|
||||
log.Info(repo.GoPath, "tag count", count)
|
||||
log.Info(repo.GetGoPath(), "tag count", count)
|
||||
repo.UpdateGitTags()
|
||||
count = repo.LenGitTags()
|
||||
log.Info(repo.GoPath, "tag count", count)
|
||||
log.Info(repo.GetGoPath(), "tag count", count)
|
||||
*/
|
||||
|
||||
if err == nil {
|
||||
return v
|
||||
repo.MasterVersion = v
|
||||
} else {
|
||||
log.Log(GITPBWARN, "gitpb.GitMasterVersion() error:", err)
|
||||
return ""
|
||||
repo.MasterVersion = "giterr"
|
||||
}
|
||||
}
|
||||
|
||||
func (repo *Repo) GetDevelVersion() string {
|
||||
func (repo *Repo) setDevelVersion() {
|
||||
bname := repo.GetDevelBranchName()
|
||||
v, err := repo.gitVersionByName(bname)
|
||||
if err == nil {
|
||||
return v
|
||||
repo.DevelVersion = v
|
||||
} else {
|
||||
log.Log(GITPBWARN, "gitpb.GitDevelVersion() error:", err)
|
||||
return ""
|
||||
repo.DevelVersion = "deverr"
|
||||
}
|
||||
}
|
||||
|
||||
func (repo *Repo) GetUserVersion() string {
|
||||
func (repo *Repo) setUserVersion() {
|
||||
bname := repo.GetUserBranchName()
|
||||
v, err := repo.gitVersionByName(bname)
|
||||
if err == nil {
|
||||
return v
|
||||
repo.UserVersion = v
|
||||
} else {
|
||||
log.Log(GITPBWARN, "gitpb.GitUserVersion() error:", err)
|
||||
return ""
|
||||
repo.UserVersion = "uerr"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +67,7 @@ func (repo *Repo) GetCurrentBranchName() string {
|
|||
r := repo.RunQuiet([]string{"git", "branch", "--show-current"})
|
||||
output := strings.Join(r.Stdout, "\n")
|
||||
if r.Error != nil {
|
||||
log.Log(GITPBWARN, "GetCurrentBranchName() not in a git repo?", r.Error, repo.GoPath)
|
||||
log.Log(GITPBWARN, "GetCurrentBranchName() not in a git repo?", r.Error, repo.GetGoPath())
|
||||
log.Log(GITPBWARN, "GetCurrentBranchName() output might have worked anyway:", output)
|
||||
}
|
||||
return strings.TrimSpace(output)
|
||||
|
@ -92,7 +98,7 @@ func (repo *Repo) gitDescribeByHash(hash string) (string, error) {
|
|||
r := repo.RunQuiet([]string{"git", "describe", "--tags", "--always", hash})
|
||||
out := strings.Join(r.Stdout, "\n")
|
||||
if r.Error != nil {
|
||||
log.Warn("not in a git repo or bad hash?", r.Error, repo.GoPath)
|
||||
log.Warn("not in a git repo or bad hash?", r.Error, repo.GetGoPath())
|
||||
return out, r.Error
|
||||
}
|
||||
return out, r.Error
|
||||
|
@ -137,7 +143,7 @@ func (repo *Repo) gitVersionByName(name string) (string, error) {
|
|||
output := strings.Join(r.Stdout, "\n")
|
||||
if r.Error != nil {
|
||||
log.Log(GITPBWARN, "gitDescribeByName() output might have worked anyway:", output)
|
||||
log.Log(GITPBWARN, "gitDescribeByName() not in a git repo?", r.Error, repo.GoPath)
|
||||
log.Log(GITPBWARN, "gitDescribeByName() not in a git repo?", r.Error, repo.GetGoPath())
|
||||
return "", r.Error
|
||||
}
|
||||
return strings.TrimSpace(output), nil
|
||||
|
@ -154,7 +160,7 @@ func (repo *Repo) gitVersionByName(name string) (string, error) {
|
|||
log.Log(GITPBWARN, "cmd =", cmd)
|
||||
log.Log(GITPBWARN, "err =", result.Error)
|
||||
log.Log(GITPBWARN, "output (might have worked with error?) =", output)
|
||||
log.Log(GITPBWARN, "not in a git repo or bad tag?", repo.GoPath)
|
||||
log.Log(GITPBWARN, "not in a git repo or bad tag?", repo.GetGoPath())
|
||||
return "", result.Error
|
||||
}
|
||||
|
||||
|
@ -179,13 +185,13 @@ func (repo *Repo) IsBranch(findname string) bool {
|
|||
continue
|
||||
}
|
||||
path, filename := filepath.Split(tagname)
|
||||
log.Log(GITPB, "gitpb.IsBranch() tag:", path, filename, "from", repo.GoPath)
|
||||
log.Log(GITPB, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath())
|
||||
if filename == findname {
|
||||
log.Log(GITPB, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GoPath)
|
||||
log.Log(GITPB, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath())
|
||||
return true
|
||||
}
|
||||
}
|
||||
log.Log(GITPB, "did not find tag:", findname, "in", repo.GoPath)
|
||||
log.Log(GITPB, "did not find tag:", findname, "in", repo.GetGoPath())
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -201,13 +207,13 @@ func (repo *Repo) IsLocalBranch(findname string) bool {
|
|||
continue
|
||||
}
|
||||
path, filename := filepath.Split(tagname)
|
||||
log.Log(GITPB, "gitpb.IsBranch() tag:", path, filename, "from", repo.GoPath)
|
||||
log.Log(GITPB, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath())
|
||||
if filename == findname {
|
||||
log.Log(GITPB, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GoPath)
|
||||
log.Log(GITPB, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath())
|
||||
return true
|
||||
}
|
||||
}
|
||||
log.Log(GITPB, "did not find tag:", findname, "in", repo.GoPath)
|
||||
log.Log(GITPB, "did not find tag:", findname, "in", repo.GetGoPath())
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ func (repo *Repo) AppendGoDep(newP *GoDep) bool {
|
|||
|
||||
// returns time.Duration since last scan of go.sum & go.mod
|
||||
func (repo *Repo) AgeGoDep() time.Duration {
|
||||
t := time.Since(repo.LastGoDep.AsTime())
|
||||
t := time.Since(repo.Times.LastGoDep.AsTime())
|
||||
return t
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ func (repo *Repo) ParseGoSum() (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
/*
|
||||
// reads and parses the go.sum file
|
||||
// is identical to the one above, change that
|
||||
func (repo *Repo) UpdatePublished() (bool, error) {
|
||||
|
@ -108,3 +109,4 @@ func (repo *Repo) UpdatePublished() (bool, error) {
|
|||
}
|
||||
return true, nil
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -13,7 +13,7 @@ func (repo *Repo) ValidGoSum() error {
|
|||
if !repo.Exists("go.mod") {
|
||||
return errors.New("ValidGoSum() go.mod is missing")
|
||||
}
|
||||
if repo.GoPrimitive {
|
||||
if repo.GoInfo.GoPrimitive {
|
||||
if !repo.Exists("go.mod") {
|
||||
return errors.New("GoPrimitive == true, but go.mod is missing")
|
||||
}
|
||||
|
|
|
@ -51,13 +51,13 @@ func (repo *Repo) IsPrimitive() (bool, error) {
|
|||
}
|
||||
if parts[0] == "go" {
|
||||
if parts[1] != "1.21" {
|
||||
log.Log(GITPBWARN, "go not set to 1.21 for", repo.GoPath)
|
||||
// return false, errors.New("go not set to 1.21 for " + repo.GoPath)
|
||||
log.Log(GITPBWARN, "go not set to 1.21 for", repo.GetGoPath())
|
||||
// return false, errors.New("go not set to 1.21 for " + repo.GetGoPath())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
repo.GoPrimitive = true
|
||||
repo.GoInfo.GoPrimitive = true
|
||||
repo.GoDeps = nil
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func (repo *Repo) GetMasterPatches() (int, []*Patch) {
|
|||
}
|
||||
|
||||
func (all *Repos) MakePatchset(setdir string) bool {
|
||||
loop := all.SortByGoPath()
|
||||
loop := all.SortByFullPath()
|
||||
for loop.Scan() {
|
||||
repo := loop.Next()
|
||||
log.Info("repo", repo.GetGoPath())
|
||||
|
|
27
reload.go
27
reload.go
|
@ -13,36 +13,15 @@ func (repo *Repo) Reload() error {
|
|||
repo.GoDeps = new(GoDeps)
|
||||
repo.ParseGoSum()
|
||||
|
||||
if repo.GoInfo != nil {
|
||||
repo.ReloadGo()
|
||||
}
|
||||
|
||||
repo.setLastTag()
|
||||
repo.setCurrentBranchName()
|
||||
repo.setRepoType()
|
||||
|
||||
// everything has been checked, now save the mtime's
|
||||
repo.RepoChanged()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *Repo) ReloadGo() error {
|
||||
repo.GoPlugin = false
|
||||
repo.GoProtobuf = false
|
||||
repo.GoLibrary = false
|
||||
repo.GoBinary = false
|
||||
switch repo.goListRepoType() {
|
||||
case "plugin":
|
||||
repo.GoPlugin = true
|
||||
case "protobuf":
|
||||
repo.GoProtobuf = true
|
||||
case "library":
|
||||
repo.GoLibrary = true
|
||||
case "binary":
|
||||
repo.GoBinary = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *Repo) SetDevelBranchName(bname string) {
|
||||
repo.DevelBranchName = bname
|
||||
}
|
||||
|
@ -82,7 +61,7 @@ func (repo *Repo) setCurrentBranchName() {
|
|||
r := repo.RunQuiet([]string{"git", "branch", "--show-current"})
|
||||
output := strings.Join(r.Stdout, "\n")
|
||||
if r.Error != nil {
|
||||
log.Log(GITPBWARN, "GetCurrentBranchName() not in a git repo?", r.Error, repo.GoPath)
|
||||
log.Log(GITPBWARN, "GetCurrentBranchName() not in a git repo?", r.Error, repo.GetGoPath())
|
||||
log.Log(GITPBWARN, "GetCurrentBranchName() output might have worked anyway:", output)
|
||||
}
|
||||
repo.CurrentBranchName = strings.TrimSpace(output)
|
||||
|
@ -98,7 +77,7 @@ func (repo *Repo) setCurrentBranchVersion() {
|
|||
r := repo.RunQuiet([]string{"git", "describe", "--tags", "--always"})
|
||||
output := strings.Join(r.Stdout, "\n")
|
||||
if r.Error != nil {
|
||||
log.Log(GITPBWARN, "GetCurrentBranchVersion() not in a git repo?", r.Error, repo.GoPath)
|
||||
log.Log(GITPBWARN, "GetCurrentBranchVersion() not in a git repo?", r.Error, repo.GetGoPath())
|
||||
log.Log(GITPBWARN, "GetCurrentBranchVersion() output might have worked anyway:", output)
|
||||
}
|
||||
repo.CurrentBranchVersion = strings.TrimSpace(output)
|
||||
|
|
|
@ -40,12 +40,12 @@ func (repo *Repo) RepoIgnoresGoMod() error {
|
|||
repo.GoInfo.GitIgnoresGoSum = false
|
||||
file := "go.mod"
|
||||
if tracked, err := repo.isTracked(file); err != nil {
|
||||
msg := fmt.Sprintf("%s Error checking if %s tracked: %v\n", repo.GoPath, file, err)
|
||||
msg := fmt.Sprintf("%s Error checking if %s tracked: %v\n", repo.GetGoPath(), file, err)
|
||||
log.Info("gitpb:", msg)
|
||||
return err
|
||||
} else {
|
||||
if tracked {
|
||||
msg := fmt.Sprintf("%s %s is tracked by Git.\n", repo.GoPath, file)
|
||||
msg := fmt.Sprintf("%s %s is tracked by Git.\n", repo.GetGoPath(), file)
|
||||
log.Info("gitpb:", msg)
|
||||
return errors.New(msg)
|
||||
}
|
||||
|
@ -53,18 +53,18 @@ func (repo *Repo) RepoIgnoresGoMod() error {
|
|||
|
||||
if ignored, err := repo.isIgnored(file); err != nil {
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("%s Error checking if ignored: %v\n", repo.GoPath, err)
|
||||
msg := fmt.Sprintf("%s Error checking if ignored: %v\n", repo.GetGoPath(), err)
|
||||
log.Info("gitpb:", msg)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if ignored {
|
||||
fmt.Printf("%s %s is ignored by Git.\n", repo.GoPath, file)
|
||||
fmt.Printf("%s %s is ignored by Git.\n", repo.GetGoPath(), file)
|
||||
repo.GoInfo.GitIgnoresGoSum = true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
msg := fmt.Sprintf("%s %s is neither tracked nor ignored by Git.\n", repo.GoPath, file)
|
||||
msg := fmt.Sprintf("%s %s is neither tracked nor ignored by Git.\n", repo.GetGoPath(), file)
|
||||
// this means, if you make a go.mod file, it'll add it to the repo to be tracked
|
||||
// so you need to either add it to .gitignore (this is what should happen)
|
||||
// or accept you want an auto-generated file to put endless garbage in your git repo
|
||||
|
|
|
@ -9,26 +9,58 @@ import (
|
|||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func (repo *Repo) RepoType() string {
|
||||
func (repo *Repo) GetRepoType() string {
|
||||
if repo == nil {
|
||||
return "nil"
|
||||
}
|
||||
if repo.GetGoPlugin() {
|
||||
if repo.GoInfo == nil {
|
||||
log.Warn("gitpb.RepoType() plugin was not set correctly")
|
||||
log.Warn("gitpb.RepoType() plugin was not set correctly")
|
||||
log.Warn("gitpb.RepoType() plugin was not set correctly")
|
||||
repo.GoInfo = new(GoInfo)
|
||||
repo.setRepoType()
|
||||
}
|
||||
|
||||
if repo.GoInfo.GoPlugin {
|
||||
return "plugin"
|
||||
}
|
||||
if repo.GetGoBinary() {
|
||||
if repo.GoInfo.GoProtobuf {
|
||||
return "protobuf"
|
||||
}
|
||||
if repo.GoInfo.GoBinary {
|
||||
if repo.Exists(".plugin") {
|
||||
log.Warn("gitpb.RepoType() plugin was not set correctly")
|
||||
repo.GoInfo.GoPlugin = true
|
||||
return "plugin"
|
||||
}
|
||||
return "binary"
|
||||
}
|
||||
if ok, _, _ := repo.IsProtobuf(); ok {
|
||||
return "protobuf"
|
||||
}
|
||||
if repo.GetGoLibrary() {
|
||||
if repo.GoInfo.GoLibrary {
|
||||
return "library"
|
||||
}
|
||||
return ""
|
||||
return "err"
|
||||
}
|
||||
|
||||
func (repo *Repo) setRepoType() {
|
||||
if repo == nil {
|
||||
return
|
||||
}
|
||||
if repo.Exists(".plugin") {
|
||||
repo.GoInfo.GoPlugin = true
|
||||
return
|
||||
}
|
||||
if ok, _, _ := repo.IsProtobuf(); ok {
|
||||
repo.GoInfo.GoProtobuf = true
|
||||
return
|
||||
}
|
||||
switch repo.goListRepoType() {
|
||||
case "binary":
|
||||
repo.GoInfo.GoBinary = true
|
||||
return
|
||||
case "library":
|
||||
repo.GoInfo.GoLibrary = true
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (repo *Repo) goListRepoType() string {
|
||||
|
|
25
repo.new.go
25
repo.new.go
|
@ -16,8 +16,8 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) {
|
|||
if gopath == "" {
|
||||
return nil, errors.New("blank gopath")
|
||||
}
|
||||
if r := all.FindByGoPath(gopath); r != nil {
|
||||
log.Info("gitpb.NewGoPath() already has gopath", r.GoPath)
|
||||
if r := all.FindByFullPath(fullpath); r != nil {
|
||||
log.Info("gitpb.NewGoPath() already has gopath", r.GetGoPath())
|
||||
log.Info("gitpb.NewGoPath() already has FullPath", r.FullPath)
|
||||
// already had this gopath
|
||||
return r, errors.New("gitpb.NewGoPath() duplicate gopath " + gopath)
|
||||
|
@ -31,13 +31,15 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) {
|
|||
|
||||
newr.GoInfo = new(GoInfo)
|
||||
newr.GoInfo.GoPath = gopath
|
||||
// everything happens in here
|
||||
newr.Reload()
|
||||
|
||||
if all.AppendUniqueGoPath(&newr) {
|
||||
if all.AppendUniqueFullPath(&newr) {
|
||||
// worked
|
||||
return &newr, nil
|
||||
} else {
|
||||
// this is dumb, probably never happens. todo: use Repos.Lock()
|
||||
if r := all.FindByGoPath(gopath); r != nil {
|
||||
if r := all.FindByFullPath(fullpath); r != nil {
|
||||
// already had this gopath
|
||||
return r, errors.New("gitpb.NewGoPath() AppendUnique() failed but Find() worked" + gopath)
|
||||
}
|
||||
|
@ -45,3 +47,18 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) {
|
|||
// todo: use Repos.Lock()
|
||||
return nil, errors.New("repo gitpb.NewGoPath() should never have gotten here " + gopath)
|
||||
}
|
||||
|
||||
// enforces GoPath is unique
|
||||
func (all *Repos) AppendUniqueGoPath(newr *Repo) bool {
|
||||
all.Lock.RLock()
|
||||
defer all.Lock.RUnlock()
|
||||
|
||||
for _, r := range all.Repos {
|
||||
if r.GoInfo.GoPath == newr.GoInfo.GoPath {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
all.Repos = append(all.Repos, newr)
|
||||
return true
|
||||
}
|
||||
|
|
43
repo.proto
43
repo.proto
|
@ -13,35 +13,25 @@ import "google/protobuf/timestamp.proto"; // Import the well-known type for Time
|
|||
|
||||
message Repo { // `autogenpb:marshal`
|
||||
string fullPath = 1; // `autogenpb:unique` // the actual path to the .git directory: '/home/devel/golang.org/x/tools'
|
||||
google.protobuf.Timestamp lastPull = 2; // last time a git pull was done
|
||||
string masterBranchName = 3; // git 'main' or 'master' branch name
|
||||
string develBranchName = 4; // whatever the git 'devel' branch name is
|
||||
string userBranchName = 5; // whatever your username branch is
|
||||
GitTags tags = 6; // known tags
|
||||
string goPath = 7; // `autogenpb:unique` // the logical path as used by golang: 'go.wit.com/apps/helloworld'
|
||||
bool goLibrary = 8; // is this a golang library?
|
||||
bool goBinary = 9; // is this a golang binary?
|
||||
bool goPrimitive = 10; // if this is a golang primitive (only has go.mod)
|
||||
bool goPlugin = 11; // is this a golang plugin?
|
||||
GoDeps goDeps = 12; // what is in the go.sum file
|
||||
google.protobuf.Timestamp lastGoDep = 13; // last time go.sum was processed
|
||||
bool dirty = 14; // if git says things have been changed
|
||||
GoDeps published = 15; // the last published go.mod/go.sum
|
||||
string targetVersion = 16; // useful during the package release process
|
||||
bool readOnly = 17; // tracks access to 'git push'
|
||||
string URL = 18; // the URL. amazingly I didn't add this earlier. duh.
|
||||
bool goProtobuf = 19; // autogen go files from .proto
|
||||
string desc = 20; // what is this repo?
|
||||
bytes goMod = 21; // the last go.mod file
|
||||
bytes goSum = 22; // the last go.sum file
|
||||
google.protobuf.Timestamp mtimeGitDir = 23; // mtime for ./git
|
||||
google.protobuf.Timestamp mtimeGitHead = 24; // mtime for ./git/HEAD // these two mtimes allow really fast checks to see if git has changed
|
||||
GitTimes times = 25; // store all the mtime values here. these are temporary
|
||||
GoInfo goInfo = 26; // put all the go specifcs here
|
||||
string stateChange = 27; // reason for state change
|
||||
string lastTag = 28; // the oldest tag
|
||||
string currentBranchName = 29; // the branch currently checked out
|
||||
string currentBranchVersion = 30; // the branch currently checked out
|
||||
bool dirty = 6; // if git says things have been changed
|
||||
string URL = 7; // the URL
|
||||
GitTags tags = 8; // known tags
|
||||
GitTimes times = 9; // store all the mtime values here. these are temporary
|
||||
GoInfo goInfo = 10; // put all the go specifcs here
|
||||
GoDeps goDeps = 11; // what is in the go.sum file
|
||||
string currentBranchName = 12; // the branch currently checked out
|
||||
string currentBranchVersion = 13; // the branch currently checked out
|
||||
string lastTag = 14; // the oldest tag
|
||||
string targetVersion = 15; // useful during the package release process
|
||||
bool readOnly = 16; // tracks access to 'git push'
|
||||
string desc = 17; // what is this repo?
|
||||
string stateChange = 18; // reason for state change
|
||||
string masterVersion = 19; // just store this for now
|
||||
string develVersion = 20; //
|
||||
string userVersion = 21; //
|
||||
}
|
||||
|
||||
message Repos { // `autogenpb:marshal`
|
||||
|
@ -59,6 +49,7 @@ message GitTimes {
|
|||
google.protobuf.Timestamp mtimeHead = 5; // mtime for ./git/HEAD // these two mtimes allow really fast checks to see if git has changed
|
||||
google.protobuf.Timestamp mtimeIndex = 6; // mtime for ./git/HEAD // probably always in sync with HEAD
|
||||
google.protobuf.Timestamp mtimeFetch = 7; // mtime for ./git/FETCH_HEAD // last time 'git fetch' or 'git pull' was run on current branch?
|
||||
google.protobuf.Timestamp lastGoDep = 8; // mtime for last go.sum scan
|
||||
}
|
||||
|
||||
// this is probably better. think about moving to this instead
|
||||
|
|
4
rill.go
4
rill.go
|
@ -23,7 +23,7 @@ func (repo *Repo) GitPull() cmd.Status {
|
|||
var result cmd.Status
|
||||
result.Exit = 21
|
||||
result.Error = ErrorGitPullOnLocal
|
||||
// log.Info("git pull skipped on local only branch", repo.GoPath)
|
||||
// log.Info("git pull skipped on local only branch", repo.GetGoPath())
|
||||
return result
|
||||
}
|
||||
var cmd []string
|
||||
|
@ -87,7 +87,7 @@ func (all *Repos) RillGitPull(part1 int, part2 int) map[*Repo]cmd.Status {
|
|||
*/
|
||||
var result cmd.Status
|
||||
result = repo.GitPull()
|
||||
log.Info("git pull", strings.Join(result.Stdout, " "), repo.GoPath)
|
||||
log.Info("git pull", strings.Join(result.Stdout, " "), repo.GetGoPath())
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
allerr[repo] = result
|
||||
|
|
2
shell.go
2
shell.go
|
@ -55,7 +55,7 @@ func (repo *Repo) RunStrict(cmd []string) error {
|
|||
func (repo *Repo) StrictRun(cmd []string) error {
|
||||
result := repo.RunQuiet(cmd)
|
||||
if result.Error != nil {
|
||||
log.Warn(repo.GoPath, cmd, "wow. golang is cool. an os.Error:", result.Error)
|
||||
log.Warn(repo.GetGoPath(), cmd, "wow. golang is cool. an os.Error:", result.Error)
|
||||
return result.Error
|
||||
}
|
||||
if result.Exit != 0 {
|
||||
|
|
Loading…
Reference in New Issue