From b9d4f88abdde4ff72a454f875c64e9c513840a58 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 19 Jan 2025 03:39:35 -0600 Subject: [PATCH] more checks on merge to master --- doCheckout.go | 4 ++++ doClean.go | 36 ++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/doCheckout.go b/doCheckout.go index d9fe1a4..b168da3 100644 --- a/doCheckout.go +++ b/doCheckout.go @@ -144,6 +144,10 @@ func rillCheckoutMaster(repo *gitpb.Repo) error { // don't switch braches if the user branch has uncommitted patches return nil } + if repo.GetDevelVersion() != repo.GetMasterVersion() { + // don't switch braches if the devel branch does not match master (needs merge) + return nil + } if repo.GetCurrentBranchName() == repo.GetMasterBranchName() { // repo is already on master return nil diff --git a/doClean.go b/doClean.go index 0717ad6..dcd782b 100644 --- a/doClean.go +++ b/doClean.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "os" "path/filepath" "slices" @@ -25,6 +24,9 @@ func doClean() error { // skip this while in devel // continue } + if repo.IsDirty() { + continue + } if err := doCleanRepo(repo); err != nil { badRepoExit(repo, err) } @@ -75,8 +77,10 @@ func doCleanRepo(repo *gitpb.Repo) error { } log.Info("\tlocal branch name unknown:", name, b.Merge, b.Remote) } - if hasLocal { - return ErrorReposHasLocalBranches + if argv.Clean.Force == nil { + if hasLocal { + return ErrorReposHasLocalBranches + } } return nil } @@ -115,8 +119,8 @@ func doCleanUserBranch(repo *gitpb.Repo, branch *gitpb.GitBranch) error { // me.forge.Repos.Delete(repo) me.forge.ConfigSave() - os.Exit(0) - return err + // os.Exit(0) + return nil } if repo.Exists(filepath.Join(".git/refs/remotes/origin", branch.Name)) { @@ -154,7 +158,7 @@ func doCleanUserBranch(repo *gitpb.Repo, branch *gitpb.GitBranch) error { if argv.Clean.Force != nil { cmd := []string{"git", "branch", "-D", branch.Name} _, err := repo.RunVerbose(cmd) - log.Info(err) + log.Info("THE GIT BRANCH DELETE ERROR IS:", err) return err } } @@ -165,19 +169,23 @@ func doCleanUserBranch(repo *gitpb.Repo, branch *gitpb.GitBranch) error { func userToDevelRequiresGitPush(repo *gitpb.Repo, branchName string) error { devel := repo.GetDevelBranchName() - b1 := countDiffObjects(repo, branchName, "origin/"+devel) + missing := countDiffObjects(repo, branchName, "origin/"+devel) b2 := countDiffObjects(repo, "origin/"+devel, branchName) - log.Info("user vs devel count", b1, b2) - if b1 == 0 && b2 == 0 { + log.Info("user vs devel count", missing, b2) + if missing == 0 && b2 == 0 { return nil } - if b1 != 0 { - log.Info("user vs devel count b1 != 0, b2 ==", b1, b2) - log.Info("THIS MEANS THE LOCAL BRANCH NEEDS GIT PUSH TO ORIGIN BRANCH ==", b1) + if missing != 0 { + log.Info("user vs devel count missing != 0, b2 ==", missing, b2) + log.Info("THIS MEANS THE LOCAL BRANCH NEEDS GIT PUSH TO ORIGIN BRANCH ==", missing) // if argv.Examine.Fix != nil { // return gitPushStrict(repo, branchName) // } - return fmt.Errorf("user branch not clean to delete %d %d", b1, b2) + return fmt.Errorf("user branch not clean to delete %d %d", missing, b2) } - return fmt.Errorf("user branch not clean to delete. maybe it is? devel might be ahead of user branch. %d %d", b1, b2) + if missing == 0 { + log.Info("THIS MEANS THE LOCAL BRANCH IS OK TO DELETE missing =", missing) + return nil + } + return fmt.Errorf("user branch not clean to delete. maybe it is? devel might be ahead of user branch. %d %d", missing, b2) }