diff options
| author | Jeff Carr <[email protected]> | 2025-01-19 08:48:17 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-01-19 08:48:17 -0600 |
| commit | ab9f3bf62d5255674de1026ec97ec813796cfdd8 (patch) | |
| tree | 1f78a9c1aa6b24a311957e03b296729745663a3c | |
| parent | 62dd96ccec29a41e6b21c138a9cfc0ea812b93bf (diff) | |
recreate user branches after delete
| -rw-r--r-- | doCheckout.go | 4 | ||||
| -rw-r--r-- | doClean.go | 67 |
2 files changed, 64 insertions, 7 deletions
diff --git a/doCheckout.go b/doCheckout.go index 4c30d5a..a4d6b2a 100644 --- a/doCheckout.go +++ b/doCheckout.go @@ -101,7 +101,9 @@ func rillCheckoutUser(repo *gitpb.Repo) error { // repo is already on user branch return nil } - repo.CheckoutUser() + if err := repo.CheckoutUser(); err != nil { + return err + } return nil } @@ -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) |
