cleaning up default behavior

This commit is contained in:
Jeff Carr 2025-08-19 21:04:57 -05:00
parent 631544356a
commit d1c9436e45
5 changed files with 85 additions and 116 deletions

View File

@ -6,14 +6,15 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
# make gocui # try the ncurses gui plugin
# make andlabs # try the andlabs gui plugin (uses GTK)
default: gocui
default: verbose install
forge clean
#forge
vet:
@GO111MODULE=off go vet
@echo this go binary package builds okay
verbose:
verbose: goimports vet plugin
GO111MODULE=off go build -v -x \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"

View File

@ -29,8 +29,8 @@ func (args) doBashAuto() {
// me.pp.WriteHelp(os.Stderr)
// me.pp.WriteUsageForSubcommand(os.Stderr, me.pp.SubcommandNames()...)
// me.pp.WriteHelpForSubcommand(os.Stderr, me.pp.SubcommandNames()...)
me.pp.WriteHelpForSubcommand(os.Stderr, "clean")
fmt.Println("devel user")
// me.pp.WriteHelpForSubcommand(os.Stderr, "clean")
fmt.Println("--force")
case "commit":
fmt.Println("--all")
case "config":
@ -66,7 +66,7 @@ func (args) doBashAuto() {
default:
if argv.BashAuto[0] == ARGNAME {
// list the subcommands here
fmt.Println("--bash list checkout commit config dirty debug fetch merge patch pull")
fmt.Println("--bash list checkout clean commit dirty debug fetch merge patch pull")
}
}
os.Exit(0)

View File

@ -11,63 +11,64 @@ import (
"go.wit.com/log"
)
var ErrorReposHasLocalBranches error = fmt.Errorf("repo still has local branches")
var ErrorMergeBranch error = fmt.Errorf("trunk has things not in the branch")
var ErrorMergeTrunk error = fmt.Errorf("branch has things not in trunk")
// reverts all repos back to the original master branches
// automatically deletes local devel and user branches
func doClean() error {
if argv.Clean.Pub != nil {
if err := doCleanPub(); err != nil {
badExit(err)
}
log.Info("finished attempt at cleaning devel branches")
return nil
// fix this to work, then delete all the other options for "forge clean'
if err := doAllCheckoutMaster(); err != nil {
// badExit(err)
}
if argv.Clean.Devel != nil {
if err := doCleanDevel(); err != nil {
badExit(err)
}
log.Info("finished attempt at cleaning devel branches")
return nil
}
if argv.Clean.User != nil {
if err := doCleanUser(); err != nil {
log.Info(err)
okExit("")
}
return nil
}
return nil
}
func doCleanUser() error {
if _, count, _, err := IsEverythingOnMaster(); err != nil {
if count == 0 {
log.Info("No repos are on the master branch")
return nil
}
log.Info("Not all repos are on the master branch")
// return err
}
var anyerr error
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
if repo.GetCurrentBranchName() != repo.GetMasterBranchName() {
continue
}
if repo.IsDirty() {
continue
}
if repo.GetTargetVersion() != "" {
repo.SetTargetVersion("")
configSave = true
}
// try to delete user
if err := doCleanUserRepo(repo); err != nil {
log.Info(repo.GetGoPath(), err)
anyerr = err
}
// try to delete devel
doRepoCleanDevel(repo)
}
return anyerr
log.Info("finished attempt at cleaning devel branches")
return nil
}
/*
func doesLocalBranchExist(repo *gitpb.Repo, branch string) bool {
return repo.Exists(filepath.Join(".git/refs/heads", branch))
}
func doesLocalBranchExist(repo *gitpb.Repo, branch string) bool {
return repo.Exists(filepath.Join(".git/refs/heads", branch))
}
*/
func doRepoCleanDevel(repo *gitpb.Repo) error {
if !repo.IsLocalBranch(repo.GetDevelBranchName()) {
// there is no local branch named 'devel'
return nil
}
if repo.GetCurrentBranchName() != repo.GetMasterBranchName() {
return log.Errorf("%s not on master branch:", repo.GetFullPath())
}
if repo.IsDirty() {
return log.Errorf("%s is dirty:", repo.GetFullPath())
}
if err := justDeleteTheDevelBranchAlready(repo); err != nil {
log.Info("justDeleteTheDevel() err", repo.GetGoPath(), err)
return err
}
return nil
}
func doCleanDevel() error {
var total int
@ -118,17 +119,38 @@ func doCleanUserRepo(repo *gitpb.Repo) error {
return nil
}
log.Info("trying to delete", bruser, repo.GetUserVersion())
b1 := repo.CountDiffObjects(bruser, brdevel) // should be zero
if b1 == 0 {
cmd := []string{"git", "branch", "-D", bruser}
log.Info("USER IS IN DEVEL", repo.GetGoPath(), cmd)
err := repo.RunVerbose(cmd)
return err
// will you loose work if you delete your user branch?
// if DevelBranchExists()
// then if UserBranchCommits exist in DevelBranch
// DeleteUserBranch is safe
if repo.IsLocalBranch(brdevel) {
b1 := repo.CountDiffObjects(bruser, "refs/heads/"+brdevel) // should be zero
if b1 == 0 {
// every user branch exists in devel. delete user branch
cmd := []string{"git", "branch", "-D", bruser}
log.Info("USER IS IN DEVEL", repo.GetGoPath(), cmd)
err := repo.RunVerbose(cmd)
return err
}
}
return fmt.Errorf("%s branch has things not in %s count=%d", bruser, brdevel, b1)
brmaster := repo.GetMasterBranchName()
// will you loose work if you delete your user branch?
// if master branch exists()
// then if all user commits exist in master
// delete user branch is safe
if repo.IsLocalBranch(brmaster) {
b1 := repo.CountDiffObjects(bruser, "refs/heads/"+brmaster) // should be zero
if b1 == 0 {
cmd := []string{"git", "branch", "-D", bruser}
log.Info("USER IS IN DEVEL", repo.GetGoPath(), cmd)
err := repo.RunVerbose(cmd)
return err
}
}
return fmt.Errorf("%s branch has unique commits", bruser)
}
// hack to cleanup release versioning info
@ -177,7 +199,7 @@ func justDeleteTheDevelBranchAlready(repo *gitpb.Repo) error {
// remote doesn't exist, check against master
master := repo.GetMasterBranchName()
b1 := repo.CountDiffObjects(branch, master) // should be zero
b1 := repo.CountDiffObjects(branch, "refs/heads/"+master) // should be zero
if b1 == 0 {
cmd := []string{"git", "branch", "-D", repo.GetDevelBranchName()}
log.Info("DEVEL IS IN REMOTE", repo.GetGoPath(), cmd)

View File

@ -39,14 +39,6 @@ func doSyncClean() error {
// force everything
argv.Force = true
if err := doCleanUser(); err != nil {
return err
}
if err := doCleanDevel(); err != nil {
return err
}
now := time.Now()
pullcount := me.forge.RillFuncError(rillPull)
count := me.forge.RillReload()

View File

@ -15,73 +15,27 @@ func makeModeMasterWin() *gadgets.GenericWindow {
win := gadgets.NewGenericWindow("Release", "tools")
grid := win.Group.RawGrid()
checkout := grid.NewButton("git checkout master", func() {
grid.NewButton("git checkout master", func() {
win.Disable()
defer win.Enable()
})
gitpull := grid.NewButton("git pull", func() {
grid.NewButton("git pull", func() {
win.Disable()
defer win.Enable()
})
grid.NextRow()
cleanUser := grid.NewButton("Clean user branches", func() {
grid.NewButton("Clean branches", func() {
win.Disable()
defer win.Enable()
if err := doCleanUser(); err != nil {
log.Info("Clean user branches failed", err)
}
doClean()
})
cleanDevel := grid.NewButton("Clean devel branches", func() {
win.Disable()
defer win.Enable()
if err := doCleanDevel(); err != nil {
log.Info("Clean devel branches failed", err)
}
})
grid.NextRow()
f := func() {
total, count, nope, err := IsEverythingOnMaster()
if nope == 0 {
checkout.Disable()
gitpull.Enable()
} else {
log.Printf("Master branch check. %d total repos. (%d ok) (%d not on master branch) err=%v\n", total, count, nope, err)
checkout.Enable()
}
var localuser bool // are there still local user branches
var localdevel bool // are there still local devel branches
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
if repo.IsLocalBranch(repo.GetUserBranchName()) {
localuser = true
}
if repo.IsLocalBranch(repo.GetDevelBranchName()) {
localdevel = true
}
}
if localuser {
cleanUser.Enable()
} else {
cleanUser.Disable()
}
if localdevel {
cleanDevel.Enable()
} else {
cleanDevel.Disable()
}
}
grid.NewButton("check repo state", func() {
win.Disable()
defer win.Enable()
f()
})
grid.NewButton("reset user branches (?)", func() {