start trying to make smarter tracking of git changes
This commit is contained in:
parent
01b332ceb8
commit
cea5968b0f
48
repo.new.go
48
repo.new.go
|
@ -4,8 +4,10 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// scans in a new git repo. If it detects the repo is a golang project,
|
// scans in a new git repo. If it detects the repo is a golang project,
|
||||||
|
@ -41,10 +43,8 @@ func (all *Repos) NewGoPath(basepath string, gopath string, url string) (*Repo,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
newr.Tags = new(GitTags)
|
newr.Tags = new(GitTags)
|
||||||
// newr.UpdateGit()
|
|
||||||
newr.UpdateGitTags()
|
newr.UpdateGitTags()
|
||||||
newr.GoDeps = new(GoDeps)
|
newr.GoDeps = new(GoDeps)
|
||||||
// newr.RedoGoMod()
|
|
||||||
|
|
||||||
switch newr.goListRepoType() {
|
switch newr.goListRepoType() {
|
||||||
case "plugin":
|
case "plugin":
|
||||||
|
@ -57,14 +57,22 @@ func (all *Repos) NewGoPath(basepath string, gopath string, url string) (*Repo,
|
||||||
newr.GoBinary = true
|
newr.GoBinary = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastpull, err := newr.LastGitPull()
|
||||||
|
if err == nil {
|
||||||
|
newr.LastPull = timestamppb.New(lastpull)
|
||||||
|
}
|
||||||
|
|
||||||
if all.AppendUniqueGoPath(&newr) {
|
if all.AppendUniqueGoPath(&newr) {
|
||||||
// worked
|
// worked
|
||||||
return &newr, nil
|
return &newr, nil
|
||||||
|
} else {
|
||||||
|
// this is dumb, probably never happens. todo: use Repos.Lock()
|
||||||
|
if r := all.FindByGoPath(gopath); r != nil {
|
||||||
|
// already had this gopath
|
||||||
|
return r, errors.New("gitpb.NewGoPath() AppendUnique() failed but Find() worked" + gopath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if r := all.FindByGoPath(gopath); r != nil {
|
// todo: use Repos.Lock()
|
||||||
// already had this gopath
|
|
||||||
return r, errors.New("gitpb.NewGoPath() AppendUnique() failed but Find() worked" + gopath)
|
|
||||||
}
|
|
||||||
return nil, errors.New("repo gitpb.NewGoPath() should never have gotten here " + gopath)
|
return nil, errors.New("repo gitpb.NewGoPath() should never have gotten here " + gopath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,3 +83,31 @@ func (repo *Repo) SetDevelBranchName(bname string) {
|
||||||
func (repo *Repo) SetUserBranchName(bname string) {
|
func (repo *Repo) SetUserBranchName(bname string) {
|
||||||
repo.UserBranchName = bname
|
repo.UserBranchName = bname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repo *Repo) GitChanged() bool {
|
||||||
|
fullfile := filepath.Join(repo.FullPath, ".git/FETCH_HEAD")
|
||||||
|
lasttime, err := repo.LastGitPull()
|
||||||
|
if err == nil {
|
||||||
|
// if error, something is wrong, assume true
|
||||||
|
log.Info("gitpb:", fullfile, "changed")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
newtime := repo.LastPull.AsTime()
|
||||||
|
|
||||||
|
if lasttime == newtime {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
log.Info("gitpb:", fullfile, "changed")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *Repo) GitPullAge() time.Duration {
|
||||||
|
lastpull, err := repo.LastGitPull()
|
||||||
|
if err == nil {
|
||||||
|
// if error, something is wrong, assume true
|
||||||
|
ltime := repo.LastPull.AsTime()
|
||||||
|
return time.Since(ltime)
|
||||||
|
}
|
||||||
|
|
||||||
|
return time.Since(lastpull)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue