recreate user branches after delete
This commit is contained in:
parent
62dd96ccec
commit
ab9f3bf62d
|
@ -101,7 +101,9 @@ func rillCheckoutUser(repo *gitpb.Repo) error {
|
||||||
// repo is already on user branch
|
// repo is already on user branch
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
repo.CheckoutUser()
|
if err := repo.CheckoutUser(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
63
doClean.go
63
doClean.go
|
@ -49,6 +49,20 @@ func doCleanRepo(repo *gitpb.Repo) error {
|
||||||
for _, l := range repo.GitConfig.Local {
|
for _, l := range repo.GitConfig.Local {
|
||||||
log.Info("\tlocal branch name:", l.Name)
|
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 {
|
for name, b := range repo.GitConfig.Branches {
|
||||||
if b.Name == "" {
|
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)
|
err = fmt.Errorf("repo %s BRANCH AND REMOTE CAN BE DELETED %s", repo.GetGoPath(), branch.Name)
|
||||||
log.Info(err)
|
log.Info(err)
|
||||||
if argv.Clean.Force != nil {
|
if argv.Clean.Force != nil {
|
||||||
err = forceDeleteBranch(repo, base)
|
err = BADforceDeleteBranch(repo, base)
|
||||||
repo.Reload()
|
repo.Reload()
|
||||||
}
|
}
|
||||||
return err
|
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)
|
err := fmt.Errorf("repo %s BRANCH CAN PROBABLY BE DELETED base=%s fullname=%s", repo.GetGoPath(), base, branch.Name)
|
||||||
log.Info(err)
|
log.Info(err)
|
||||||
if argv.Clean.Force != nil {
|
if argv.Clean.Force != nil {
|
||||||
err = forceDeleteBranch(repo, base)
|
err = BADforceDeleteBranch(repo, base)
|
||||||
repo.Reload()
|
repo.Reload()
|
||||||
}
|
}
|
||||||
return err
|
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)
|
log.Info("THIS USER BRANCH IS CLEAN TO DELETE", branch.Name)
|
||||||
if argv.Clean.Force != nil {
|
if argv.Clean.Force != nil {
|
||||||
err := forceDeleteBranch(repo, branch.Name)
|
err := BADforceDeleteBranch(repo, branch.Name)
|
||||||
repo.Reload()
|
repo.Reload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// 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() {
|
if repo.IsDirty() {
|
||||||
log.Info(repo.GetGoPath(), "is dirty")
|
log.Info(repo.GetGoPath(), "is dirty")
|
||||||
return nil
|
return nil
|
||||||
|
@ -285,6 +299,45 @@ func forceDeleteBranch(repo *gitpb.Repo, branch string) error {
|
||||||
log.Info(repo.GetGoPath(), branch, "is not the user branch", repo.GetUserBranchName())
|
log.Info(repo.GetGoPath(), branch, "is not the user branch", repo.GetUserBranchName())
|
||||||
return nil
|
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}
|
||||||
|
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)
|
||||||
|
// 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
|
configSave = true
|
||||||
|
|
||||||
cmd := []string{"git", "branch", "-D", branch}
|
cmd := []string{"git", "branch", "-D", branch}
|
||||||
|
@ -293,12 +346,14 @@ func forceDeleteBranch(repo *gitpb.Repo, branch string) error {
|
||||||
// return err
|
// return err
|
||||||
}
|
}
|
||||||
log.Info("THIS USER REMOTE BRANCH MUST BE DELETED HERE", branch)
|
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
|
// git push origin --delete jcarr
|
||||||
cmd = []string{"git", "push", "origin", "--delete", branch}
|
cmd = []string{"git", "push", "origin", "--delete", branch}
|
||||||
if _, err := repo.RunVerbose(cmd); err != nil {
|
if _, err := repo.RunVerbose(cmd); err != nil {
|
||||||
log.Info("THE GIT BRANCH DELETE ERROR IS:", err)
|
log.Info("THE GIT BRANCH DELETE ERROR IS:", err)
|
||||||
// return err
|
// return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
cmd = []string{"git", "branch", "-D", "--remote", "origin/" + branch}
|
cmd = []string{"git", "branch", "-D", "--remote", "origin/" + branch}
|
||||||
if _, err := repo.RunVerbose(cmd); err != nil {
|
if _, err := repo.RunVerbose(cmd); err != nil {
|
||||||
log.Info("THE GIT BRANCH DELETE ERROR IS:", err)
|
log.Info("THE GIT BRANCH DELETE ERROR IS:", err)
|
||||||
|
|
Loading…
Reference in New Issue