diff options
Diffstat (limited to 'doClean.go')
| -rw-r--r-- | doClean.go | 44 |
1 files changed, 35 insertions, 9 deletions
@@ -174,13 +174,23 @@ func doRepoCleanUser(repo *gitpb.Repo) error { brmaster := repo.GetMasterBranchName() if repo.IsBranchRemote(bruser) { - b1 := repo.CountDiffObjects(bruser, "refs/heads/"+brdevel) // should be zero - if b1 == 0 { - log.Info("Local user branch is safe to delete", bruser) + b2, err := repo.CountDiffObjects("refs/heads/"+bruser, "refs/heads/"+brmaster) // should be zero + if err != nil { + log.Info(repo.FullPath, "doRepoCleanUser() bad branches") + return err } - b2 := repo.CountDiffObjects("refs/heads/"+bruser, "refs/heads/"+brmaster) // should be zero if b2 == 0 { log.Info("Local remote branch is safe to delete (is completely in master)", bruser) + cmd := []string{"git", "branch", "-D", bruser} + s := log.Sprintf("Run: %v in %s", cmd, repo.FullPath) + if !argv.Force { + if fhelp.QuestionUser(s) { + repo.RunVerbose([]string{"git", "branch", "-D", bruser}) + // repo.RunVerbose([]string{"git", "checkout", bname}) + } + } else { + repo.RunVerbose([]string{"git", "branch", "-D", bruser}) + } } log.Info("forge is designed to always have local only user branches", bruser) return fmt.Errorf("forge is designed to always have local only user branches") @@ -196,7 +206,11 @@ func doRepoCleanUser(repo *gitpb.Repo) error { // then if UserBranchCommits exist in DevelBranch // DeleteUserBranch is safe if repo.IsLocalBranch(brdevel) { - b1 := repo.CountDiffObjects(bruser, "refs/heads/"+brdevel) // should be zero + b1, err := repo.CountDiffObjects(bruser, "refs/heads/"+brdevel) // should be zero + if err != nil { + log.Info(repo.FullPath, "doRepoCleanUser() bad branches") + return err + } if b1 == 0 { // every user branch exists in devel. delete user branch cmd := []string{"git", "branch", "-D", bruser} @@ -211,7 +225,11 @@ func doRepoCleanUser(repo *gitpb.Repo) error { // 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 + b1, err := repo.CountDiffObjects(bruser, "refs/heads/"+brmaster) // should be zero + if err != nil { + log.Info(repo.FullPath, "doRepoCleanUser() bad branches") + return err + } if b1 == 0 { cmd := []string{"git", "branch", "-D", bruser} // log.Info("USER IS IN DEVEL", repo.GetGoPath(), cmd) @@ -240,7 +258,11 @@ func justDeleteTheDevelBranchAlready(repo *gitpb.Repo) error { // check against remote if it exists if repo.IsDevelRemote() { - b1 := repo.CountDiffObjects(branch, remote) // should be zero + b1, err := repo.CountDiffObjects(branch, remote) // should be zero + if err != nil { + log.Info(repo.FullPath, "doRepoCleanUser() bad branches") + return err + } if b1 == 0 { cmd := []string{"git", "branch", "-D", repo.GetDevelBranchName()} // log.Info("DEVEL IS IN REMOTE", repo.GetGoPath(), cmd) @@ -249,13 +271,17 @@ func justDeleteTheDevelBranchAlready(repo *gitpb.Repo) error { } cmd := []string{"git", "push"} log.Info("DEVEL LOCAL NEEDS GIT PUSH TO REMOTE", repo.GetGoPath(), cmd) - err := repo.RunVerbose(cmd) + err = repo.RunVerbose(cmd) return err } // remote doesn't exist, check against master master := repo.GetMasterBranchName() - b1 := repo.CountDiffObjects(branch, "refs/heads/"+master) // should be zero + b1, err := repo.CountDiffObjects(branch, "refs/heads/"+master) // should be zero + if err != nil { + log.Info(repo.FullPath, "doRepoCleanUser() bad branches") + return err + } if b1 == 0 { cmd := []string{"git", "branch", "-D", repo.GetDevelBranchName()} // log.Info("DEVEL IS IN REMOTE", repo.GetGoPath(), cmd) |
