diff options
| author | Jeff Carr <[email protected]> | 2025-10-06 05:01:35 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-06 05:01:35 -0500 |
| commit | 21901183f88b87cad82354afd815704964006bdf (patch) | |
| tree | 288a2a0ebe21a4cc85d8c1437c6f665de13b9889 /doDev.go | |
| parent | a7d418da30889a3b85257baf65d44f0d32c5df71 (diff) | |
almost working safe del user branches
Diffstat (limited to 'doDev.go')
| -rw-r--r-- | doDev.go | 153 |
1 files changed, 102 insertions, 51 deletions
@@ -4,6 +4,7 @@ package main import ( + "errors" "strings" "go.wit.com/lib/protobuf/forgepb" @@ -11,6 +12,8 @@ import ( "go.wit.com/log" ) +var ErrorNeedArgvFix error = errors.New("add --fix") + // FORGE USES THESE TO RECOVER FROM WHEN TOOLKITS FAIL TO LOAD // so don't delete them func doDev() (string, error) { @@ -35,22 +38,59 @@ func doDev() (string, error) { return "", nil } -func doFixDeleteUserBranches(repo *gitpb.Repo, remoteRef *gitpb.GitTag) { +func doFixDeleteUserBranches(repo *gitpb.Repo, remoteRef *gitpb.GitTag) *notesList { // log.Info("delete remote user", repo.FullPath) localTag := repo.IsBranchLocal(repo.GetUserBranchName()) if localTag != nil { // log.Info("THERE IS local user", repo.FullPath, localTag.Refname) log.Printf("%-13.13s %-55.55s %v\n", "LOCAL USER", repo.FullPath, localTag.Refname+" local branch exists") - doFixDeleteUserLocalBranch(repo, remoteRef, localTag) - return + err, notes := doFixDeleteUserLocalBranch(repo, remoteRef, localTag) + if err != nil { + log.Printf("%-13.13s %-55.55s %v noteslen(%d)\n", "need --fix", repo.FullPath, err, len(notes.all)) + } } - log.Printf("%-13.13s %-55.55s %v\n", "NO LOCAL USER", repo.FullPath, "only has remote user branch") + err, notes := doFixDeleteRemoteUserBranch(repo, remoteRef) + if err != nil { + log.Printf("%-13.13s %-55.55s %v noteslen(%d)\n", "need --fix", repo.FullPath, err, len(notes.all)) + } + return notes } -// git push --delete origin jcarr -// git push origin :refs/remotes/origin/jcarr -func doFixDeleteRemoteUserBranch(repo *gitpb.Repo, remoteRef *gitpb.GitTag, localRef *gitpb.GitTag) (error, *notesList) { - return nil, nil +// notes.addNote("SAFE", repo, remoteUser, line) +func (notes *notesList) addNote(note string, repo *gitpb.Repo, ref *gitpb.GitTag, cmd []string, line string) { + newnote := new(DeleteBranchNotes) + newnote.Note = note + newnote.Refname = ref.Refname + newnote.Fullpath = repo.FullPath + newnote.Cmd = cmd + parts := strings.Split(line, "%00") // git log doesn't actually convert %00 to NULL + if len(parts) != 4 { + log.Info("len", len(parts)) + panic("nope") + } + newnote.H = parts[0] + newnote.Ae = parts[1] + newnote.As = parts[2] + newnote.S = parts[3] + // newnote.Hash = parts[0] + log.Printf("%-5.5s %7.7s %-55.55s %v\n", note, newnote.H, newnote.Fullpath, cmd) + notes.all = append(notes.all, newnote) +} + +type notesList struct { + all []*DeleteBranchNotes +} + +type DeleteBranchNotes struct { + Note string + Refname string + Fullpath string + Cmd []string + // git log variable names + H string + S string + Ae string + As string } // git branch -D refs/heads/jcarr @@ -65,14 +105,19 @@ func doFixDeleteUserLocalBranch(repo *gitpb.Repo, remoteRef *gitpb.GitTag, local localDevel := repo.NewCompareRef(dref) // Is the localUser completely inside the remoteUser branch? - hashok, hashbad, cmd1, cmd2, err := remoteUser.DeleteBranch(localUser) + hashok, hashbad, cmd1, cmd2, err := remoteUser.CompareBranch(localUser) for _, line := range hashok { notes.addNote("OK", repo, remoteUser.GetRef(), cmd1, line) } for _, line := range hashbad { notes.addNote("BAD", repo, localUser.GetRef(), cmd2, line) } - if err == nil { + if err != nil { + log.Printf("%-13.13s %-55.55s err='%v' %s %v\n", "CMD ERR", repo.FullPath, err, "NOT SAFE TO DELETE. Reload()?", cmd1) + log.Printf("%-13.13s %-55.55s err='%v' %s %v\n", "CMD ERR", repo.FullPath, err, "NOT SAFE TO DELETE. Reload()?", cmd2) + return err, notes + } + if len(hashbad) == 0 { // git update-ref -d refs/heads/jcarr cmd := []string{"git", "update-ref", "-d", localUser.GetRefname()} log.Printf("%-13.13s %-55.55s %v %s\n", "CMD OK", repo.FullPath, cmd1, "") @@ -87,11 +132,11 @@ func doFixDeleteUserLocalBranch(repo *gitpb.Repo, remoteRef *gitpb.GitTag, local } return nil, notes } - return log.Errorf("argv needs --fix"), notes + return ErrorNeedArgvFix, notes } // Is the localUser completely inside the localDevel branch? - hashok, hashbad, cmd1, cmd2, err = localDevel.DeleteBranch(localUser) + hashok, hashbad, cmd1, cmd2, err = localDevel.CompareBranch(localUser) for _, line := range hashok { notes.addNote("OK", repo, localDevel.GetRef(), cmd1, line) } @@ -99,7 +144,12 @@ func doFixDeleteUserLocalBranch(repo *gitpb.Repo, remoteRef *gitpb.GitTag, local notes.addNote("BAD", repo, localUser.GetRef(), cmd2, line) } // git update-ref -d refs/heads/jcarr - if err == nil { + if err != nil { + log.Printf("%-13.13s %-55.55s err='%v' %s %v\n", "CMD ERR", repo.FullPath, err, "NOT SAFE TO DELETE. Reload()?", cmd1) + log.Printf("%-13.13s %-55.55s err='%v' %s %v\n", "CMD ERR", repo.FullPath, err, "NOT SAFE TO DELETE. Reload()?", cmd2) + return err, notes + } + if len(hashbad) == 0 { cmd := []string{"git", "update-ref", "-d", localUser.GetRefname()} log.Printf("%-13.13s %-55.55s %v %s\n", "CMD OK", repo.FullPath, cmd1, "") log.Printf("%-13.13s %-55.55s %v %s\n", "CMD OK", repo.FullPath, cmd2, "") @@ -112,48 +162,49 @@ func doFixDeleteUserLocalBranch(repo *gitpb.Repo, remoteRef *gitpb.GitTag, local me.sh.BadExit(s, err) } } - return nil, notes - } else { - log.Printf("%-13.13s %-55.55s %v %s %v\n", "CMD ERR", repo.FullPath, err, "NOT SAFE TO DELETE. Reload()?", cmd1) - log.Printf("%-13.13s %-55.55s %v %s %v\n", "CMD ERR", repo.FullPath, err, "NOT SAFE TO DELETE. Reload()?", cmd2) + return ErrorNeedArgvFix, notes } - // log.Printf("%-13.13s %-55.55s %v %s\n", "NOT SAFE", repo.FullPath, localUser.GetRefname(), "NOT SAFE TO DELETE") return log.Errorf("NOT SAFE"), notes } -// notes.addNote("SAFE", repo, remoteUser, line) -func (notes *notesList) addNote(note string, repo *gitpb.Repo, ref *gitpb.GitTag, cmd []string, line string) { - newnote := new(DeleteBranchNotes) - newnote.Note = note - newnote.Refname = ref.Refname - newnote.Fullpath = repo.FullPath - newnote.Cmd = cmd - parts := strings.Split(line, "%00") // git log doesn't actually convert %00 to NULL - if len(parts) != 4 { - log.Info("len", len(parts)) - panic("nope") - } - newnote.H = parts[0] - newnote.Ae = parts[1] - newnote.As = parts[2] - newnote.S = parts[3] - // newnote.Hash = parts[0] - log.Printf("%-5.5s %7.7s %-55.55s %v\n", note, newnote.H, newnote.Fullpath, cmd) - notes.all = append(notes.all, newnote) -} +// git push --delete origin jcarr +// git push origin :refs/remotes/origin/jcarr +func doFixDeleteRemoteUserBranch(repo *gitpb.Repo, remoteRef *gitpb.GitTag) (error, *notesList) { + notes := new(notesList) -type notesList struct { - all []*DeleteBranchNotes -} + // get remote user & local devel branches + remoteUser := repo.NewCompareRef(remoteRef) + dref := repo.GetLocalDevelRef() + localDevel := repo.NewCompareRef(dref) -type DeleteBranchNotes struct { - Note string - Refname string - Fullpath string - Cmd []string - // git log variable names - H string - S string - Ae string - As string + // Is the remoteUser completely inside the localDevel branch? + hashok, hashbad, cmd1, cmd2, err := localDevel.CompareBranch(remoteUser) + for _, line := range hashok { + notes.addNote("OK", repo, localDevel.GetRef(), cmd1, line) + } + for _, line := range hashbad { + notes.addNote("BAD", repo, remoteUser.GetRef(), cmd2, line) + } + // git update-ref -d refs/heads/jcarr + if err != nil { + log.Printf("%-13.13s %-55.55s err='%v' %s %v\n", "CMD ERR", repo.FullPath, err, "NOT SAFE TO DELETE. Reload()?", cmd1) + log.Printf("%-13.13s %-55.55s err='%v' %s %v\n", "CMD ERR", repo.FullPath, err, "NOT SAFE TO DELETE. Reload()?", cmd2) + return err, notes + } + if len(hashbad) == 0 { + cmd := []string{"git", "push", "origin", ":" + remoteUser.GetRefname()} + log.Printf("%-13.13s %-55.55s %v %s\n", "CMD OK", repo.FullPath, cmd1, "") + log.Printf("%-13.13s %-55.55s %v %s\n", "CMD OK", repo.FullPath, cmd2, "") + log.Printf("%-13.13s %-55.55s %v %s\n", "SAFE TO DELETE", repo.FullPath, cmd, "add --fix") + if argv.Fix { + err := repo.RunVerbose(cmd) + if err != nil { + log.Info(remoteUser.GetRefname(), repo.FullPath) + s := "remote user branch could not be deleted" + me.sh.BadExit(s, err) + } + } + return ErrorNeedArgvFix, notes + } + return log.Errorf("NOT SAFE"), notes } |
