diff options
| author | Jeff Carr <[email protected]> | 2025-02-02 11:45:40 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-02-02 15:09:04 -0600 |
| commit | 81c72468a11f1685a8fbe696636d7b95cd0b36dc (patch) | |
| tree | 5d03c14ebccc2121dd2b524b272e9293c8147974 /doClean.go | |
| parent | 260f4c67e701dd4215fab516e4d883eaacf57e3f (diff) | |
code for a new user to start from scratch
Diffstat (limited to 'doClean.go')
| -rw-r--r-- | doClean.go | 134 |
1 files changed, 55 insertions, 79 deletions
@@ -62,30 +62,39 @@ func doCleanUser() error { return nil } +func doesLocalBranchExist(repo *gitpb.Repo, branch string) bool { + return repo.Exists(filepath.Join(".git/refs/heads", branch)) +} + func doCleanDevel() error { var total int var count int all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() - if argv.Verbose { - // log.Info("Cleaning:", repo.GetGoPath()) - } total += 1 + devel := repo.GetDevelBranchName() + if !doesLocalBranchExist(repo, devel) { + if argv.Verbose { + log.Info("local branch was already deleted:", repo.GetGoPath()) + } + continue + } if repo.GetCurrentBranchName() != repo.GetMasterBranchName() { - // repos must be in the master branch to clean the devel branch - return nil + log.Info("Repo not on master branch:", repo.GetGoPath()) + continue } if repo.IsDirty() { - return nil + log.Info("Repo is dirty:", repo.GetGoPath()) + continue } count += 1 - if err := doCleanDevelRepo(repo); err != nil { - log.Info(repo.GetGoPath(), err) - return err + if err := justDeleteTheDevelBranchAlready(repo); err != nil { + log.Info("justDeleteTheDevel() err", repo.GetGoPath(), err) } } - log.Printf("attempted cleaning %d branches of %d total branches\n", count, total) + log.Info("") + log.Printf("attempted cleaning %d devel branches of %d total branches\n", count, total) return nil } @@ -117,75 +126,6 @@ func checkhashes(repo *gitpb.Repo, hashes []string, refpath string) ([]string, e return hashes, nil } -func doCleanDevelRepo(repo *gitpb.Repo) error { - var hashes []string - devel := repo.GetDevelBranchName() - if argv.Verbose { - log.Printf("Start clean devel branch: %s %s\n", repo.GetGoPath(), devel) - } - - // check if devel branch exists in remote repo - if repo.Exists(filepath.Join(".git/refs/remotes/origin", devel)) { - if argv.Verbose { - var err error - if hashes, err = checkhashes(repo, hashes, filepath.Join(".git/refs/remotes/origin", devel)); err != nil { - return err - } - } - remote := filepath.Join("origin", devel) - if err := isBranchSubsetOfTrunk(repo, devel, remote); err != nil { - if err == ErrorMergeBranch { - log.Info("can not do this yet. need push to upstream", repo.GetGoPath()) - if argv.Force { - return nil - } - return err - } - return err - } - // log.Info("todo: verify against remote devel branch", repo.GetGoPath()) - } - - // verify devel branch is subset of master branch - master := repo.GetMasterBranchName() - if argv.Verbose { - var err error - if hashes, err = checkhashes(repo, hashes, filepath.Join(".git/refs/heads", devel)); err != nil { - return err - } - } - if argv.Verbose { - var err error - if hashes, err = checkhashes(repo, hashes, filepath.Join(".git/refs/heads", devel)); err != nil { - return err - } - } - if argv.Verbose { - log.Info("repo hashes all match. incredible", hashes, repo.GetGoPath()) - } - if err := isBranchSubsetOfTrunk(repo, devel, master); err != nil { - if err == ErrorMergeBranch { - if argv.Force { - if repo.GetCurrentBranchName() == devel { - cmd := []string{"git", "merge", master} - // only run this if branch is local - _, err := repo.RunVerbose(cmd) - return err - } else { - cmd := []string{"git", "merge", master} - log.Info("can't run. on wrong branch.", cmd, repo.GetGoPath(), "current branch =", repo.GetCurrentBranchName()) - } - return nil - } - return err - } - return err - } - // log.Info("todo: verify against remote devel branch", repo.GetGoPath()) - - return nil -} - // removes all local branches func doCleanUserRepo(repo *gitpb.Repo) error { var hasLocal bool @@ -560,3 +500,39 @@ func doCleanPub() error { log.Printf("clearing %d total repos\n", total) return nil } + +// if you call this, there is no going back. no checks anymore. nothing +// it deletes the 'devel' branch. git branch -D "devel". END OF STORY +func justDeleteTheDevelBranchAlready(repo *gitpb.Repo) error { + branch := repo.GetDevelBranchName() + remote := filepath.Join("origin", branch) + + // check against remote if it exists + if repo.Exists(filepath.Join(".git/refs/remotes", remote)) { + b1 := countGitDiffLog(repo, branch, remote) // should be zero + if b1 == 0 { + cmd := []string{"git", "branch", "-D", repo.GetDevelBranchName()} + log.Info("DEVEL IS IN REMOTE", repo.GetGoPath(), cmd) + _, err := repo.RunVerbose(cmd) + return err + } + cmd := []string{"git", "push"} + log.Info("DEVEL LOCAL NEEDS GIT PUSH TO REMOTE", repo.GetGoPath(), cmd) + _, err := repo.RunVerbose(cmd) + return err + } + + // remote doesn't exist, check against master + master := repo.GetMasterBranchName() + b1 := countGitDiffLog(repo, branch, master) // should be zero + if b1 == 0 { + cmd := []string{"git", "branch", "-D", repo.GetDevelBranchName()} + log.Info("DEVEL IS IN REMOTE", repo.GetGoPath(), cmd) + _, err := repo.RunVerbose(cmd) + return err + } + cmd := []string{"git", "merge something somehow"} + log.Info("DEVEL LOCAL NEEDS GIT MERGE TO MASTER", repo.GetGoPath(), cmd) + // _, err := repo.RunVerbose(cmd) + return nil +} |
