changes to Reload()
This commit is contained in:
parent
6654dbb410
commit
719287c3bf
|
@ -127,7 +127,7 @@ func (repo *Repo) createUserBranch(branch string) error {
|
|||
if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
|
||||
repo.CheckoutDevel()
|
||||
}
|
||||
repo.Reload()
|
||||
repo.ReloadCheck()
|
||||
|
||||
if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
|
||||
log.Info("create user branch will probably fail", repo.GetGoPath())
|
||||
|
|
23
reload.go
23
reload.go
|
@ -4,17 +4,33 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"go.wit.com/lib/config"
|
||||
"go.wit.com/log"
|
||||
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
// sets a flag that the repos have changed
|
||||
// used later by applications on exit to test if
|
||||
// the protobuf needs to be written to disk
|
||||
func reposChanged(b bool) {
|
||||
config.SetChanged("repos", true)
|
||||
}
|
||||
|
||||
// returns true based on os.Stat() only checks
|
||||
// seems to kinda work ok. goal is to avoid os.Exec() here for speed
|
||||
// this might be the 1 place where libgit2 would be a good idea
|
||||
func (repo *Repo) HasChanged() bool {
|
||||
return repo.DidRepoChange()
|
||||
}
|
||||
|
||||
// does a fast check with os.Stat()
|
||||
// if the mtimes changed, does a full repo.Reload()
|
||||
// if the mtimes changed, does a full repo.ReloadForce()
|
||||
func (repo *Repo) ReloadCheck() error {
|
||||
if !repo.DidRepoChange() {
|
||||
return nil
|
||||
}
|
||||
err := repo.Reload()
|
||||
reposChanged(true)
|
||||
err := repo.ReloadForce()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -22,7 +38,8 @@ func (repo *Repo) ReloadCheck() error {
|
|||
}
|
||||
|
||||
// TODO: clean this up more, but it is working now more or less
|
||||
func (repo *Repo) Reload() error {
|
||||
func (repo *Repo) ReloadForce() error {
|
||||
reposChanged(true)
|
||||
// sometimes, on new repos, if .git/HEAD does not exist
|
||||
// defective git daemons or badly configured repos, 'git clone' can fail
|
||||
// if so, 'git fetch origin' can repair the state
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
func (r *Repo) MergeToDevel() (*cmd.Status, error) {
|
||||
r.Reload()
|
||||
r.ReloadCheck()
|
||||
if r.GetCurrentBranchName() != r.GetDevelBranchName() {
|
||||
return nil, fmt.Errorf("repo not on devel branch")
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ func (r *Repo) MergeToDevel() (*cmd.Status, error) {
|
|||
}
|
||||
|
||||
if !r.IsBranchRemote(devel) {
|
||||
r.Reload() // rescan the repo
|
||||
r.ReloadCheck() // rescan the repo
|
||||
// devel branch is not remote. do not try 'git push'
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -40,19 +40,19 @@ func (r *Repo) MergeToDevel() (*cmd.Status, error) {
|
|||
log.Log(WARN, "GitPushToDevel() failed", r.GetFullPath())
|
||||
return nil, result.Error
|
||||
}
|
||||
r.Reload() // rescan the repo
|
||||
r.ReloadCheck() // rescan the repo
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *Repo) MergeToMaster() (*cmd.Status, error) {
|
||||
r.Reload()
|
||||
r.ReloadCheck()
|
||||
|
||||
if r.GetCurrentBranchName() != r.GetMasterBranchName() {
|
||||
return nil, fmt.Errorf("repo not on master branch")
|
||||
}
|
||||
/*
|
||||
if r.GetReadOnly() {
|
||||
r.Reload() // rescan the repo
|
||||
r.ReloadCheck() // rescan the repo
|
||||
// master branch is read only. you can not git push
|
||||
lh := r.GetLocalHash("devel")
|
||||
rh := r.GetRemoteHash("devel")
|
||||
|
@ -87,6 +87,6 @@ func (r *Repo) MergeToMaster() (*cmd.Status, error) {
|
|||
log.Log(WARN, "GitPushToMaster() failed", r.GetFullPath())
|
||||
return nil, result.Error
|
||||
}
|
||||
r.Reload() // rescan the repo
|
||||
r.ReloadCheck() // rescan the repo
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) {
|
|||
newr.GoInfo = new(GoInfo)
|
||||
newr.GoInfo.GoPath = gopath
|
||||
// everything happens in here
|
||||
newr.Reload()
|
||||
newr.ReloadForce()
|
||||
|
||||
newr.ValidateUTF8()
|
||||
if all.AppendByFullPath(&newr) {
|
||||
|
@ -91,7 +91,7 @@ func (all *Repos) NewRepo(fullpath string, namespace string) (*Repo, error) {
|
|||
newr.Times = new(GitTimes)
|
||||
|
||||
// everything happens in here
|
||||
newr.Reload()
|
||||
newr.ReloadForce()
|
||||
|
||||
newr.ValidateUTF8()
|
||||
if all.AppendByFullPath(&newr) {
|
||||
|
@ -111,7 +111,7 @@ func NewRepo(fullpath string) (*Repo, error) {
|
|||
repo.Times = new(GitTimes)
|
||||
|
||||
// everything happens in here
|
||||
repo.Reload()
|
||||
repo.ReloadForce()
|
||||
repo.ValidateUTF8()
|
||||
if repo.Namespace == "" {
|
||||
giturl := repo.GetURL()
|
||||
|
|
Loading…
Reference in New Issue