summaryrefslogtreecommitdiff
path: root/doClean.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-27 10:53:12 -0500
committerJeff Carr <[email protected]>2025-09-27 10:53:12 -0500
commitc7d406fc290a95baffebb957be783f6a4974c46a (patch)
tree58df8c0bd5ec5661a40eafb11ae2309623733c8f /doClean.go
parent3cc5a7a142c26f853b470d2e2bd01f14a435fa12 (diff)
reset a single repov0.25.42
Diffstat (limited to 'doClean.go')
-rw-r--r--doClean.go83
1 files changed, 51 insertions, 32 deletions
diff --git a/doClean.go b/doClean.go
index e8da80e..93927cd 100644
--- a/doClean.go
+++ b/doClean.go
@@ -14,10 +14,59 @@ import (
"go.wit.com/log"
)
+func doResetRepo(repo *gitpb.Repo) error {
+ if repo.GetCurrentBranchName() != repo.GetMasterBranchName() {
+ return log.Errorf("not on master branch")
+ }
+ if repo.IsDirty() {
+ return log.Errorf("repo is dirty")
+ }
+
+ // when publishing, clean out the details of that if it's still there
+ if repo.GetTargetVersion() != "" {
+ repo.SetTargetVersion("")
+ }
+
+ // try to delete user
+ if err := doRepoCleanUser(repo); err != nil {
+ if err == ErrorBranchUnique {
+ if argv.Clean.Fix != nil {
+ bname := repo.GetUserBranchName()
+ checkPatchIds(repo, repo.GetUserBranchName(), repo.GetMasterBranchName())
+ s := fmt.Sprintf("delete this odd user (%s) branch %s?", bname, repo.FullPath)
+ if fhelp.QuestionUser(s) {
+ repo.RunVerbose([]string{"git", "branch", "-D", bname})
+ // repo.RunVerbose([]string{"git", "checkout", bname})
+ }
+ }
+ } else {
+ log.Info(repo.GetGoPath(), err)
+ }
+ }
+
+ // try to delete devel
+ err := doRepoCleanDevel(repo)
+ return err
+}
+
// reverts all repos back to the original master branches
// automatically deletes local devel and user branches
func doClean() error {
- setForgeMode(forgepb.ForgeMode_CLEAN)
+ if argv.Clean.Repo != "" {
+ setForgeMode(forgepb.ForgeMode_CLEAN)
+ log.Info("only reset repo:", argv.Clean.Repo)
+ if found := me.forge.Repos.FindByNamespace(argv.Clean.Repo); found != nil {
+ return doResetRepo(found)
+ }
+ if found := me.forge.Repos.FindByFullPath(argv.Clean.Repo); found != nil {
+ return doResetRepo(found)
+ }
+ return log.Errorf("repo not found: %s", argv.Clean.Repo)
+ }
+
+ s := fmt.Sprintf("Reset all (%d) git repos to the original state (non-destructive)?", me.forge.Repos.Len())
+ if !fhelp.QuestionUser(s) {
+ }
// fix this to work, then delete all the other options for "forge clean'
if err := me.forge.DoAllCheckoutMaster(); err != nil {
@@ -27,37 +76,7 @@ func doClean() error {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
- if repo.GetCurrentBranchName() != repo.GetMasterBranchName() {
- continue
- }
- if repo.IsDirty() {
- continue
- }
-
- // when publishing, clean out the details of that if it's still there
- if repo.GetTargetVersion() != "" {
- repo.SetTargetVersion("")
- }
-
- // try to delete user
- if err := doRepoCleanUser(repo); err != nil {
- if err == ErrorBranchUnique {
- if argv.Clean.Fix != nil {
- bname := repo.GetUserBranchName()
- checkPatchIds(repo, repo.GetUserBranchName(), repo.GetMasterBranchName())
- s := fmt.Sprintf("delete this odd user (%s) branch %s?", bname, repo.FullPath)
- if fhelp.QuestionUser(s) {
- repo.RunVerbose([]string{"git", "branch", "-D", bname})
- // repo.RunVerbose([]string{"git", "checkout", bname})
- }
- }
- } else {
- log.Info(repo.GetGoPath(), err)
- }
- }
-
- // try to delete devel
- doRepoCleanDevel(repo)
+ doResetRepo(repo)
}
found := gitpb.NewRepos()