check branch differences

This commit is contained in:
Jeff Carr 2025-02-13 23:39:07 -06:00
parent 9cc9b9bc87
commit e127f53bd4
2 changed files with 6 additions and 12 deletions

View File

@ -6,17 +6,6 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
// count all objects only in branch1
func (repo *Repo) countDiffObjects(branch1, branch2 string) int {
cmd := repo.ConstructGitDiffLog(branch1, branch2)
r, err := repo.RunVerboseOnError(cmd)
if err != nil {
return -1
}
// log.Info("countDiffObjects()", cmd, len(r.Stdout), strings.Join(r.Stdout, " "))
return len(r.Stdout)
}
func (repo *Repo) setRepoState() { func (repo *Repo) setRepoState() {
if repo == nil { if repo == nil {
return return
@ -44,7 +33,7 @@ func (repo *Repo) setRepoState() {
repo.State = "devel not checked out" repo.State = "devel not checked out"
return return
} }
b1 := repo.countDiffObjects(repo.GetMasterBranchName(), repo.GetDevelBranchName()) b1 := repo.CountDiffObjects(repo.GetMasterBranchName(), repo.GetDevelBranchName())
if b1 == 0 { if b1 == 0 {
repo.State = "merge to main" repo.State = "merge to main"
// log.Info("master vs devel count is normal b1 == 0", b1) // log.Info("master vs devel count is normal b1 == 0", b1)

View File

@ -55,6 +55,11 @@ func (r *Repo) MergeToMaster() (*cmd.Status, error) {
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() {
r.Reload() // rescan the repo
// master branch is read only. you can not git push
return nil, fmt.Errorf("can't merge to master on read only() repos")
}
if r.CheckDirty() { if r.CheckDirty() {
return nil, fmt.Errorf("repo is dirty") return nil, fmt.Errorf("repo is dirty")
} }