diff options
Diffstat (limited to 'doClean.go')
| -rw-r--r-- | doClean.go | 67 |
1 files changed, 61 insertions, 6 deletions
@@ -49,6 +49,20 @@ func doCleanRepo(repo *gitpb.Repo) error { for _, l := range repo.GitConfig.Local { log.Info("\tlocal branch name:", l.Name) } + if argv.Clean.User != nil { + base := repo.GetUserBranchName() + if repo.Exists(filepath.Join(".git/refs/heads", base)) { + log.Info("Delete local branch:", base, repo.GetGoPath()) + err := forceDeleteUserBranch(repo, base) + repo.Reload() + if err != nil { + log.Info("Delete local branch ERROR:", err) + return err + } + // return fmt.Errorf("todo") + } + return nil + } for name, b := range repo.GitConfig.Branches { if b.Name == "" { @@ -109,7 +123,7 @@ func verifyLocalBranchIsMerged(repo *gitpb.Repo, branch *gitpb.GitBranch) error err = fmt.Errorf("repo %s BRANCH AND REMOTE CAN BE DELETED %s", repo.GetGoPath(), branch.Name) log.Info(err) if argv.Clean.Force != nil { - err = forceDeleteBranch(repo, base) + err = BADforceDeleteBranch(repo, base) repo.Reload() } return err @@ -130,7 +144,7 @@ func verifyLocalBranchIsMerged(repo *gitpb.Repo, branch *gitpb.GitBranch) error err := fmt.Errorf("repo %s BRANCH CAN PROBABLY BE DELETED base=%s fullname=%s", repo.GetGoPath(), base, branch.Name) log.Info(err) if argv.Clean.Force != nil { - err = forceDeleteBranch(repo, base) + err = BADforceDeleteBranch(repo, base) repo.Reload() } return err @@ -182,7 +196,7 @@ func doCleanUserBranch(repo *gitpb.Repo, branch *gitpb.GitBranch) error { } log.Info("THIS USER BRANCH IS CLEAN TO DELETE", branch.Name) if argv.Clean.Force != nil { - err := forceDeleteBranch(repo, branch.Name) + err := BADforceDeleteBranch(repo, branch.Name) repo.Reload() if err != nil { return err @@ -276,7 +290,7 @@ func isSafeToDelete(repo *gitpb.Repo, old string) error { } // literally ignore all errors. delete everthing with no checks for now -func forceDeleteBranch(repo *gitpb.Repo, branch string) error { +func forceDeleteUserBranch(repo *gitpb.Repo, branch string) error { if repo.IsDirty() { log.Info(repo.GetGoPath(), "is dirty") return nil @@ -285,6 +299,14 @@ func forceDeleteBranch(repo *gitpb.Repo, branch string) error { log.Info(repo.GetGoPath(), branch, "is not the user branch", repo.GetUserBranchName()) return nil } + if err := isSafeToDelete(repo, branch); err != nil { + log.Info(err) + return err + } + if err := requiresGitPush(repo, branch); err != nil { + log.Info(err) + return err + } configSave = true cmd := []string{"git", "branch", "-D", branch} @@ -293,12 +315,45 @@ func forceDeleteBranch(repo *gitpb.Repo, branch string) error { // return err } log.Info("THIS USER REMOTE BRANCH MUST BE DELETED HERE", branch) - // git push origin --delete jcarr - cmd = []string{"git", "push", "origin", "--delete", branch} + if repo.Exists(filepath.Join(".git/refs/remote/origin", branch)) { + // git push origin --delete jcarr + cmd = []string{"git", "push", "origin", "--delete", branch} + if _, err := repo.RunVerbose(cmd); err != nil { + log.Info("THE GIT BRANCH DELETE ERROR IS:", err) + // return err + } + } + cmd = []string{"git", "branch", "-D", "--remote", "origin/" + branch} if _, err := repo.RunVerbose(cmd); err != nil { log.Info("THE GIT BRANCH DELETE ERROR IS:", err) // return err } + // return fmt.Errorf("one at a time %s", repo.GetGoPath()) + return nil +} + +// literally ignore all errors. delete everthing with no checks for now +func BADforceDeleteBranch(repo *gitpb.Repo, branch string) error { + if repo.IsDirty() { + log.Info(repo.GetGoPath(), "is dirty") + return nil + } + configSave = true + + cmd := []string{"git", "branch", "-D", branch} + if _, err := repo.RunVerbose(cmd); err != nil { + log.Info("THE GIT BRANCH DELETE ERROR IS:", err) + // return err + } + log.Info("THIS USER REMOTE BRANCH MUST BE DELETED HERE", branch) + if repo.Exists(filepath.Join(".git/refs/remote/origin", branch)) { + // git push origin --delete jcarr + cmd = []string{"git", "push", "origin", "--delete", branch} + if _, err := repo.RunVerbose(cmd); err != nil { + log.Info("THE GIT BRANCH DELETE ERROR IS:", err) + // return err + } + } cmd = []string{"git", "branch", "-D", "--remote", "origin/" + branch} if _, err := repo.RunVerbose(cmd); err != nil { log.Info("THE GIT BRANCH DELETE ERROR IS:", err) |
