Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
|
ab666ddbc3 | |
|
0b30cd36dc | |
|
2a47f1e547 | |
|
719287c3bf |
17
checkout.go
17
checkout.go
|
@ -2,7 +2,6 @@ package gitpb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
@ -11,20 +10,6 @@ import (
|
||||||
|
|
||||||
func (repo *Repo) CheckoutMaster() bool {
|
func (repo *Repo) CheckoutMaster() bool {
|
||||||
bName := repo.GetMasterBranchName()
|
bName := repo.GetMasterBranchName()
|
||||||
if bName == "giterr" {
|
|
||||||
cmd := []string{"git", "checkout", "main"} // todo: figure out main
|
|
||||||
repo.RunVerboseOnError(cmd)
|
|
||||||
os.Exit(-1)
|
|
||||||
// TODO: try to fix this
|
|
||||||
if repo.checkoutBranch("main") {
|
|
||||||
repo.MasterBranchName = "main"
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
cmd := []string{"git", "checkout", "main"} // todo: figure out main
|
|
||||||
repo.RunVerboseOnError(cmd)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if repo.checkoutBranch(bName) {
|
if repo.checkoutBranch(bName) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -127,7 +112,7 @@ func (repo *Repo) createUserBranch(branch string) error {
|
||||||
if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
|
if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
|
||||||
repo.CheckoutDevel()
|
repo.CheckoutDevel()
|
||||||
}
|
}
|
||||||
repo.Reload()
|
repo.ReloadCheck()
|
||||||
|
|
||||||
if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
|
if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
|
||||||
log.Info("create user branch will probably fail", repo.GetGoPath())
|
log.Info("create user branch will probably fail", repo.GetGoPath())
|
||||||
|
|
|
@ -14,7 +14,10 @@ func (repo *Repo) SetMasterBranchName(s string) {
|
||||||
|
|
||||||
func (repo *Repo) GetGoPath() string {
|
func (repo *Repo) GetGoPath() string {
|
||||||
if repo.GoInfo == nil {
|
if repo.GoInfo == nil {
|
||||||
return ""
|
return repo.Namespace
|
||||||
|
}
|
||||||
|
if repo.GoInfo.GoPath == "" {
|
||||||
|
return repo.Namespace
|
||||||
}
|
}
|
||||||
return repo.GoInfo.GoPath
|
return repo.GoInfo.GoPath
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,11 @@ func (all *Repos) ConfigSave(fname string) error {
|
||||||
return errors.New("gitpb.ConfigSave() repos == nil")
|
return errors.New("gitpb.ConfigSave() repos == nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, s := filepath.Split(fname); s != "repos.pb" {
|
||||||
|
log.Infof("ConfigSave() filename '%s' invalid\n", fname)
|
||||||
|
return log.Errorf("ConfigSave() filename '%s' invalid\n", fname)
|
||||||
|
}
|
||||||
|
|
||||||
data, err := all.Marshal()
|
data, err := all.Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("gitpb proto.Marshal() failed len", len(data), err)
|
log.Info("gitpb proto.Marshal() failed len", len(data), err)
|
||||||
|
|
|
@ -38,7 +38,6 @@ func (repo *Repo) setMasterVersion() {
|
||||||
repo.MasterVersion = v
|
repo.MasterVersion = v
|
||||||
} else {
|
} else {
|
||||||
log.Log(WARN, "gitpb.GitMasterVersion() error:", err)
|
log.Log(WARN, "gitpb.GitMasterVersion() error:", err)
|
||||||
repo.MasterVersion = "giterr"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,11 +133,11 @@ func (repo *Repo) gitVersionByName(name string) (string, error) {
|
||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
// git will return the current tag
|
// git will return the current tag
|
||||||
r, err := repo.RunQuiet([]string{"git", "describe", "--tags"})
|
cmd := []string{"git", "describe", "--tags"}
|
||||||
|
r, err := repo.RunQuiet(cmd)
|
||||||
output := strings.Join(r.Stdout, "\n")
|
output := strings.Join(r.Stdout, "\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log(WARN, "gitDescribeByName() output might have worked anyway:", output)
|
log.Log(WARN, repo.FullPath, "gitDescribeByName() ", output, err, cmd)
|
||||||
log.Log(WARN, "gitDescribeByName() not in a git repo?", err, repo.GetGoPath())
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return strings.TrimSpace(output), nil
|
return strings.TrimSpace(output), nil
|
||||||
|
|
|
@ -19,23 +19,3 @@ func (mt *GitTagsTable) PrintTable() {
|
||||||
mt.MakeTable()
|
mt.MakeTable()
|
||||||
cobol.PrintTable(mt.pb)
|
cobol.PrintTable(mt.pb)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func (mt *GitTagsTable) MakeTable() {
|
|
||||||
for _, name := range mt.pb.Order {
|
|
||||||
// log.Info("gitpb: looking for row name()", name)
|
|
||||||
if mt.doStringFunc(name) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if mt.doIntFunc(name) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if mt.doTimeFunc(name) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if mt.doButtonFunc(name) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
23
reload.go
23
reload.go
|
@ -4,17 +4,33 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/lib/config"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
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()
|
// 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 {
|
func (repo *Repo) ReloadCheck() error {
|
||||||
if !repo.DidRepoChange() {
|
if !repo.DidRepoChange() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
err := repo.Reload()
|
reposChanged(true)
|
||||||
|
err := repo.ReloadForce()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -22,7 +38,8 @@ func (repo *Repo) ReloadCheck() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: clean this up more, but it is working now more or less
|
// 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
|
// sometimes, on new repos, if .git/HEAD does not exist
|
||||||
// defective git daemons or badly configured repos, 'git clone' can fail
|
// defective git daemons or badly configured repos, 'git clone' can fail
|
||||||
// if so, 'git fetch origin' can repair the state
|
// if so, 'git fetch origin' can repair the state
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
package gitpb
|
package gitpb
|
||||||
|
|
||||||
func (t *ReposTable) MyMasterBranch() *RepoStringFunc {
|
func (t *ReposTable) MyMasterBranch() *RepoAnyFunc {
|
||||||
sf := t.AddStringFunc("master", func(m *Repo) string {
|
sf := t.AddStringFunc("master", func(m *Repo) string {
|
||||||
return m.MasterBranchName
|
return m.MasterBranchName
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Repo) MergeToDevel() (*cmd.Status, error) {
|
func (r *Repo) MergeToDevel() (*cmd.Status, error) {
|
||||||
r.Reload()
|
r.ReloadCheck()
|
||||||
if r.GetCurrentBranchName() != r.GetDevelBranchName() {
|
if r.GetCurrentBranchName() != r.GetDevelBranchName() {
|
||||||
return nil, fmt.Errorf("repo not on devel branch")
|
return nil, fmt.Errorf("repo not on devel branch")
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ func (r *Repo) MergeToDevel() (*cmd.Status, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !r.IsBranchRemote(devel) {
|
if !r.IsBranchRemote(devel) {
|
||||||
r.Reload() // rescan the repo
|
r.ReloadCheck() // rescan the repo
|
||||||
// devel branch is not remote. do not try 'git push'
|
// devel branch is not remote. do not try 'git push'
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -40,19 +40,19 @@ func (r *Repo) MergeToDevel() (*cmd.Status, error) {
|
||||||
log.Log(WARN, "GitPushToDevel() failed", r.GetFullPath())
|
log.Log(WARN, "GitPushToDevel() failed", r.GetFullPath())
|
||||||
return nil, result.Error
|
return nil, result.Error
|
||||||
}
|
}
|
||||||
r.Reload() // rescan the repo
|
r.ReloadCheck() // rescan the repo
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) MergeToMaster() (*cmd.Status, error) {
|
func (r *Repo) MergeToMaster() (*cmd.Status, error) {
|
||||||
r.Reload()
|
r.ReloadCheck()
|
||||||
|
|
||||||
if r.GetCurrentBranchName() != r.GetMasterBranchName() {
|
if r.GetCurrentBranchName() != r.GetMasterBranchName() {
|
||||||
return nil, fmt.Errorf("repo not on master branch")
|
return nil, fmt.Errorf("repo not on master branch")
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if r.GetReadOnly() {
|
if r.GetReadOnly() {
|
||||||
r.Reload() // rescan the repo
|
r.ReloadCheck() // rescan the repo
|
||||||
// master branch is read only. you can not git push
|
// master branch is read only. you can not git push
|
||||||
lh := r.GetLocalHash("devel")
|
lh := r.GetLocalHash("devel")
|
||||||
rh := r.GetRemoteHash("devel")
|
rh := r.GetRemoteHash("devel")
|
||||||
|
@ -87,6 +87,6 @@ func (r *Repo) MergeToMaster() (*cmd.Status, error) {
|
||||||
log.Log(WARN, "GitPushToMaster() failed", r.GetFullPath())
|
log.Log(WARN, "GitPushToMaster() failed", r.GetFullPath())
|
||||||
return nil, result.Error
|
return nil, result.Error
|
||||||
}
|
}
|
||||||
r.Reload() // rescan the repo
|
r.ReloadCheck() // rescan the repo
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) {
|
||||||
newr.GoInfo = new(GoInfo)
|
newr.GoInfo = new(GoInfo)
|
||||||
newr.GoInfo.GoPath = gopath
|
newr.GoInfo.GoPath = gopath
|
||||||
// everything happens in here
|
// everything happens in here
|
||||||
newr.Reload()
|
newr.ReloadForce()
|
||||||
|
|
||||||
newr.ValidateUTF8()
|
newr.ValidateUTF8()
|
||||||
if all.AppendByFullPath(&newr) {
|
if all.AppendByFullPath(&newr) {
|
||||||
|
@ -91,7 +91,7 @@ func (all *Repos) NewRepo(fullpath string, namespace string) (*Repo, error) {
|
||||||
newr.Times = new(GitTimes)
|
newr.Times = new(GitTimes)
|
||||||
|
|
||||||
// everything happens in here
|
// everything happens in here
|
||||||
newr.Reload()
|
newr.ReloadForce()
|
||||||
|
|
||||||
newr.ValidateUTF8()
|
newr.ValidateUTF8()
|
||||||
if all.AppendByFullPath(&newr) {
|
if all.AppendByFullPath(&newr) {
|
||||||
|
@ -111,7 +111,7 @@ func NewRepo(fullpath string) (*Repo, error) {
|
||||||
repo.Times = new(GitTimes)
|
repo.Times = new(GitTimes)
|
||||||
|
|
||||||
// everything happens in here
|
// everything happens in here
|
||||||
repo.Reload()
|
repo.ReloadForce()
|
||||||
repo.ValidateUTF8()
|
repo.ValidateUTF8()
|
||||||
if repo.Namespace == "" {
|
if repo.Namespace == "" {
|
||||||
giturl := repo.GetURL()
|
giturl := repo.GetURL()
|
||||||
|
|
|
@ -33,7 +33,7 @@ func (repo *Repo) RevertMasterToDevel() bool {
|
||||||
|
|
||||||
if repo.RunAll(all) {
|
if repo.RunAll(all) {
|
||||||
log.Info("EVERYTHING OK. RERELEASED", repo.GetGoPath())
|
log.Info("EVERYTHING OK. RERELEASED", repo.GetGoPath())
|
||||||
repo.Reload()
|
repo.ReloadCheck()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue