stop git branch delete if no local branch

This commit is contained in:
Jeff Carr 2025-03-04 06:35:53 -06:00
parent cad5321516
commit 3b44a76cc4
1 changed files with 12 additions and 38 deletions

View File

@ -76,19 +76,11 @@ func doCleanDevel() error {
for all.Scan() { for all.Scan() {
repo := all.Next() repo := all.Next()
total += 1 total += 1
// devel := repo.GetDevelBranchName() if !repo.IsLocalBranch(repo.GetDevelBranchName()) {
if repo.GetDevelVersion() == "derr" { // there is no local branch named 'devel'
// already deleted continue
return nil
} }
/*
if !doesLocalBranchExist(repo, devel) {
if argv.Verbose {
log.Info("local branch was already deleted:", repo.GetGoPath())
}
continue
}
*/
if repo.GetCurrentBranchName() != repo.GetMasterBranchName() { if repo.GetCurrentBranchName() != repo.GetMasterBranchName() {
log.Info("Repo not on master branch:", repo.GetGoPath()) log.Info("Repo not on master branch:", repo.GetGoPath())
continue continue
@ -107,26 +99,6 @@ func doCleanDevel() error {
return nil return nil
} }
/*
func checkhashes(repo *gitpb.Repo, hashes []string, refpath string) ([]string, error) {
if !repo.Exists(refpath) {
return hashes, nil
}
r, err := repo.RunStrict([]string{"cat", refpath})
if err != nil {
return hashes, err
}
newhash := r.Stdout[0]
for _, hash := range hashes {
if newhash != hash {
return hashes, fmt.Errorf("%s hash broke %s %s", repo.GetGoPath(), newhash, hash)
}
}
hashes = append(hashes, newhash)
return hashes, nil
}
*/
// removes all local branches // removes all local branches
func doCleanUserRepo(repo *gitpb.Repo) error { func doCleanUserRepo(repo *gitpb.Repo) error {
if repo.IsDirty() { if repo.IsDirty() {
@ -136,17 +108,18 @@ func doCleanUserRepo(repo *gitpb.Repo) error {
bruser := repo.GetUserBranchName() bruser := repo.GetUserBranchName()
brdevel := repo.GetDevelBranchName() brdevel := repo.GetDevelBranchName()
if repo.GetUserVersion() == "uerr" {
// already deleted
return nil
}
log.Info("trying", bruser, repo.GetUserVersion())
if repo.IsBranchRemote(bruser) { if repo.IsBranchRemote(bruser) {
log.Info("forge is designed to always have local only user branches", 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") return fmt.Errorf("forge is designed to always have local only user branches")
} }
if !repo.IsLocalBranch(bruser) {
// there is no local user branch
return nil
}
log.Info("trying to delete", bruser, repo.GetUserVersion())
b1 := repo.CountDiffObjects(bruser, brdevel) // should be zero b1 := repo.CountDiffObjects(bruser, brdevel) // should be zero
if b1 == 0 { if b1 == 0 {
cmd := []string{"git", "branch", "-D", bruser} cmd := []string{"git", "branch", "-D", bruser}
@ -158,6 +131,7 @@ func doCleanUserRepo(repo *gitpb.Repo) error {
return fmt.Errorf("%s branch has things not in %s count=%d", bruser, brdevel, b1) return fmt.Errorf("%s branch has things not in %s count=%d", bruser, brdevel, b1)
} }
// hack to cleanup release versioning info
func doCleanPub() error { func doCleanPub() error {
total := 0 total := 0
all := me.forge.Repos.SortByFullPath() all := me.forge.Repos.SortByFullPath()