Compare commits
No commits in common. "master" and "v0.0.125" have entirely different histories.
17
checkout.go
17
checkout.go
|
@ -2,6 +2,7 @@ package gitpb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
@ -10,6 +11,20 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -112,7 +127,7 @@ func (repo *Repo) createUserBranch(branch string) error {
|
||||||
if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
|
if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
|
||||||
repo.CheckoutDevel()
|
repo.CheckoutDevel()
|
||||||
}
|
}
|
||||||
repo.ReloadCheck()
|
repo.Reload()
|
||||||
|
|
||||||
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,10 +14,7 @@ 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 repo.Namespace
|
return ""
|
||||||
}
|
|
||||||
if repo.GoInfo.GoPath == "" {
|
|
||||||
return repo.Namespace
|
|
||||||
}
|
}
|
||||||
return repo.GoInfo.GoPath
|
return repo.GoInfo.GoPath
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,6 @@ 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,6 +38,7 @@ 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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,11 +134,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
|
||||||
cmd := []string{"git", "describe", "--tags"}
|
r, err := repo.RunQuiet([]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, repo.FullPath, "gitDescribeByName() ", output, err, cmd)
|
log.Log(WARN, "gitDescribeByName() output might have worked anyway:", output)
|
||||||
|
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,3 +19,23 @@ 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,33 +4,17 @@ 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.ReloadForce()
|
// if the mtimes changed, does a full repo.Reload()
|
||||||
func (repo *Repo) ReloadCheck() error {
|
func (repo *Repo) ReloadCheck() error {
|
||||||
if !repo.DidRepoChange() {
|
if !repo.DidRepoChange() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
reposChanged(true)
|
err := repo.Reload()
|
||||||
err := repo.ReloadForce()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -38,8 +22,7 @@ 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) ReloadForce() error {
|
func (repo *Repo) Reload() 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() *RepoAnyFunc {
|
func (t *ReposTable) MyMasterBranch() *RepoStringFunc {
|
||||||
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.ReloadCheck()
|
r.Reload()
|
||||||
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.ReloadCheck() // rescan the repo
|
r.Reload() // 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.ReloadCheck() // rescan the repo
|
r.Reload() // rescan the repo
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) MergeToMaster() (*cmd.Status, error) {
|
func (r *Repo) MergeToMaster() (*cmd.Status, error) {
|
||||||
r.ReloadCheck()
|
r.Reload()
|
||||||
|
|
||||||
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.ReloadCheck() // rescan the repo
|
r.Reload() // 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.ReloadCheck() // rescan the repo
|
r.Reload() // 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.ReloadForce()
|
newr.Reload()
|
||||||
|
|
||||||
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.ReloadForce()
|
newr.Reload()
|
||||||
|
|
||||||
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.ReloadForce()
|
repo.Reload()
|
||||||
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.ReloadCheck()
|
repo.Reload()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue