diff options
| author | Jeff Carr <[email protected]> | 2025-10-03 16:44:31 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-03 16:44:31 -0500 |
| commit | 2a04c33edf87e5396ceb3cc829622c16ce3c173a (patch) | |
| tree | dacdf64bd00e6c1d3242b50497320efac804aa5b | |
| parent | d9e303b50cbb11bb781c8173e028a89131c947ca (diff) | |
work around .gitignore changes causing dirty reposv0.0.142
| -rw-r--r-- | checkout.go | 52 | ||||
| -rw-r--r-- | repo.merge.go | 33 |
2 files changed, 65 insertions, 20 deletions
diff --git a/checkout.go b/checkout.go index 18253b7..6b6e819 100644 --- a/checkout.go +++ b/checkout.go @@ -8,6 +8,15 @@ import ( "go.wit.com/log" ) +func (repo *Repo) CheckoutMasterError() error { + bName := repo.GetMasterBranchName() + if err := repo.checkoutBranchError(bName); err != nil { + return err + } + return nil +} + +// deprecate this func (repo *Repo) CheckoutMaster() bool { bName := repo.GetMasterBranchName() if repo.checkoutBranch(bName) { @@ -16,6 +25,17 @@ func (repo *Repo) CheckoutMaster() bool { return false } +func (repo *Repo) CheckoutDevelError() error { + bName := repo.GetDevelBranchName() + if err := repo.checkoutBranchError(bName); err != nil { + return err + // switch ok + } + repo.DevelBranchName = bName + return nil +} + +// deprecate this func (repo *Repo) CheckoutDevel() bool { bName := repo.GetDevelBranchName() if repo.checkoutBranch(bName) { @@ -49,6 +69,38 @@ func (repo *Repo) BranchExists(bName string) bool { return true } +func (repo *Repo) checkoutBranchError(bName string) error { + if !repo.BranchExists(bName) { + return fmt.Errorf("no branch") + } + if bName == "" { + return fmt.Errorf("branch name was blank") + } + if repo.CheckDirty() { + log.Log(INFO, repo.GetFullPath(), "is dirty") + return fmt.Errorf("repo is dirty") + } + cmd := []string{"git", "checkout", bName} + r := repo.Run(cmd) + if r.Error != nil { + log.Log(INFO, "git checkout error:", r.Error) + return r.Error + } + + // remove this if everything works + realname := repo.GetCurrentBranchName() + realversion := repo.GetCurrentBranchVersion() + log.Info("checkoutranchError()", repo.GetFullPath(), "realname =", realname, "realversion =", realversion) + /* this is deprecated now probably + + if realname != bName { + log.Log(INFO, "git checkout failed", repo.GetFullPath(), bName, "!=", realname) + return fmt.Errorf("repo Reload() name match failure") + } + */ + return nil +} + func (repo *Repo) checkoutBranch(bName string) bool { if !repo.BranchExists(bName) { return false diff --git a/repo.merge.go b/repo.merge.go index 1b07558..3bdc3c5 100644 --- a/repo.merge.go +++ b/repo.merge.go @@ -9,12 +9,16 @@ import ( func (r *Repo) MergeToDevel() (*cmd.Status, error) { r.ReloadCheck() - if r.GetCurrentBranchName() != r.GetDevelBranchName() { - return nil, fmt.Errorf("repo not on devel branch") - } if r.CheckDirty() { return nil, fmt.Errorf("repo is dirty") } + if r.GetCurrentBranchName() != r.GetUserBranchName() { + return nil, fmt.Errorf("repo is not on user branch") + } + if err := r.CheckoutDevelError(); err != nil { + log.Info("CheckoutDevelError()", err) + return nil, err + } devel := r.GetDevelBranchName() user := r.GetUserBranchName() @@ -47,27 +51,16 @@ func (r *Repo) MergeToDevel() (*cmd.Status, error) { func (r *Repo) MergeToMaster() (*cmd.Status, error) { r.ReloadCheck() - if r.GetCurrentBranchName() != r.GetMasterBranchName() { - return nil, fmt.Errorf("repo not on master branch") + if r.GetCurrentBranchName() != r.GetDevelBranchName() { + return nil, fmt.Errorf("repo is not on devel branch") } - /* - if r.GetReadOnly() { - r.ReloadCheck() // rescan the repo - // master branch is read only. you can not git push - lh := r.GetLocalHash("devel") - rh := r.GetRemoteHash("devel") - if lh == rh { - // log.Info(r.FullPath, "local devel == remote devel", lh, rh) - } else { - log.Info(r.FullPath, "local devel != remote devel", lh, rh) - } - log.Info("can't merge to master on read only() repos. trying anyway") - // return nil, fmt.Errorf("can't merge to master on read only() repos") - } - */ if r.CheckDirty() { return nil, fmt.Errorf("repo is dirty") } + if err := r.CheckoutMasterError(); err != nil { + log.Info("CheckoutMasterError()", err) + return nil, err + } master := r.GetMasterBranchName() devel := r.GetDevelBranchName() |
