summaryrefslogtreecommitdiff
path: root/doClean.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-08-19 21:04:57 -0500
committerJeff Carr <[email protected]>2025-08-19 21:04:57 -0500
commitd1c9436e45b5c440875a6d32b8b72f1d16c0af4c (patch)
treeee50f3679e5097c955035bd4457415e63b546258 /doClean.go
parent631544356a3946933711e47b96a48f883b2c70a8 (diff)
cleaning up default behavior
Diffstat (limited to 'doClean.go')
-rw-r--r--doClean.go126
1 files changed, 74 insertions, 52 deletions
diff --git a/doClean.go b/doClean.go
index e2ad047..05f5272 100644
--- a/doClean.go
+++ b/doClean.go
@@ -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
- }
- 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
+ // fix this to work, then delete all the other options for "forge clean'
+ if err := doAllCheckoutMaster(); err != nil {
+ // badExit(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())
+ // 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
+ }
+ }
- 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
+ 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 things not in %s count=%d", bruser, brdevel, b1)
+ 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)