From 39f72d20344c5bbe05b83a13eee9c0d7b54f7e78 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 18 Jan 2025 23:25:55 -0600 Subject: better git checkout --- doClean.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'doClean.go') diff --git a/doClean.go b/doClean.go index 11e4b7e..bc665a6 100644 --- a/doClean.go +++ b/doClean.go @@ -7,18 +7,31 @@ import ( "go.wit.com/log" ) +var ErrorReposHasLocalBranches error = fmt.Errorf("repo still has local branches") + func doClean() error { + if err := IsEverythingOnMaster(); err != nil { + log.Info("Not all repos are on the master branch") + // return err + } + all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() + if repo.GetCurrentBranchName() != repo.GetMasterBranchName() { + continue + } if err := doCleanRepo(repo); err != nil { - badExit(err) + badRepoExit(repo, err) } } + log.Info("All repos on the master branch are clean") return nil } +// removes all local branches func doCleanRepo(repo *gitpb.Repo) error { + var hasLocal bool log.Info("Cleaning:", repo.GetGoPath()) if repo.GitConfig == nil { return fmt.Errorf("GitConfig == nil") @@ -30,6 +43,17 @@ func doCleanRepo(repo *gitpb.Repo) error { for name, b := range repo.GitConfig.Branches { log.Info("\tlocal branch name:", name, b.Merge, b.Remote) + if name == repo.GetMasterBranchName() { + continue + } + hasLocal = true } + if hasLocal { + return ErrorReposHasLocalBranches + } + return nil +} + +func verifyLocalBranchIsMerged(repo *gitpb.Repo, branch *gitpb.GitBranch) error { return nil } -- cgit v1.2.3