diff options
| -rw-r--r-- | argv.go | 7 | ||||
| -rw-r--r-- | doConfig.go | 5 | ||||
| -rw-r--r-- | doDev.go | 305 | ||||
| -rw-r--r-- | doFix.deleteuser.go | 312 | ||||
| -rw-r--r-- | doFix.go | 3 |
5 files changed, 319 insertions, 313 deletions
@@ -60,8 +60,9 @@ type ShowCmd struct { } type FixCmd struct { - Urls bool `arg:"--urls" help:"check for changes in repo urls"` - Untracked bool `arg:"--untracked" help:"git untracked file list"` + Urls bool `arg:"--urls" help:"check for changes in repo urls"` + Untracked bool `arg:"--untracked" help:"git untracked file list"` + DeleteUser bool `arg:"--delete-user" help:"delete all user branches (checks for safety)"` } func (ShowCmd) Examples() string { @@ -96,7 +97,6 @@ type DevCmd struct { Build *EmptyCmd `arg:"subcommand:build" help:"build this repo"` Install *EmptyCmd `arg:"subcommand:install" help:"build & install this repo"` Generate string `arg:"--generate" help:"run go generate"` - DeleteUser bool `arg:"--delete-user" help:"delete all user branches (checks for safety)"` BuildForge bool `arg:"--forge-rebuild" help:"download all the forge sources and rebuild forge"` URL string `arg:"--connect" help:"forge url"` Prune bool `arg:"--prune" help:"'git fetch --prune' everywhere"` @@ -158,7 +158,6 @@ type MergeCmd struct { type ConfigCmd struct { Add *ConfigAddCmd `arg:"subcommand:add" help:"add a config setting"` - Fix *EmptyCmd `arg:"subcommand:fix" help:"fix .config/forge/ and/or repos.pb protobuf file"` List *EmptyCmd `arg:"subcommand:list" help:"list your config settings"` Delete string `arg:"--delete" help:"delete this repo"` Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"` diff --git a/doConfig.go b/doConfig.go index 1fe1d59..d1b7adc 100644 --- a/doConfig.go +++ b/doConfig.go @@ -18,11 +18,6 @@ func doConfig() { okExit("") } - if cfg.Fix != nil { - log.Info("todo") - okExit("") - } - /* if cfg.Register != "" { if err := doRegister(cfg.Register); err == nil { @@ -6,18 +6,13 @@ package main import ( "errors" "fmt" - "strings" - - "go.wit.com/lib/protobuf/forgepb" - "go.wit.com/lib/protobuf/gitpb" - "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) { + // a GO language thing for compiling. if argv.Dev.Generate != "" { found := me.forge.Repos.FindByNamespace(argv.Dev.Generate) if found == nil { @@ -40,303 +35,5 @@ func doDev() (string, error) { } return "", nil } - if argv.Dev.DeleteUser { - found := gitpb.NewRepos() - setForgeMode(forgepb.ForgeMode_MASTER) - for repo := range me.forge.Repos.IterByNamespace() { - uremoteref := repo.GetRemoteTag(repo.GetUserBranchName()) - if uremoteref == nil { - localRef := repo.IsBranchLocal(repo.GetUserBranchName()) - if localRef == nil { - // user branches don't exist - continue - } - log.Info("branch is only local") - if err, _ := doFixDeleteLocalUserByDevel(repo, localRef); err == nil { - // must have deleted it by devel - continue - } - if err, _ := doFixDeleteLocalUserByMaster(repo, localRef); err == nil { - // must have deleted it by master - continue - } - continue - } - found.Repos = append(found.Repos, repo) - if !repo.IsMasterBranch() { - if argv.Fix { - log.Info("you just be in the master branch to run --fix") - repo.State = "needs master branch" - continue - } - } - doFixDeleteUserBranches(repo, uremoteref) - } - me.forge.PrintHumanTable(found) - return "", nil - } return "", nil } - -func doFixPrint(s string, path string, cmd string) { - log.Printf("%-13.13s %-55.55s %s\n", s, path, cmd) -} - -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) - doFixPrint("LOCAL USER", repo.FullPath, localTag.Refname+" local branch exists") - 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)) - } - } - 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 -} - -// 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 -// git update-ref -d refs/heads/jcarr -func doFixDeleteUserLocalBranch(repo *gitpb.Repo, remoteRef *gitpb.GitTag, localRef *gitpb.GitTag) (error, *notesList) { - notes := new(notesList) - - // get local user, remote user & local devel branches - dref := repo.GetLocalDevelRef() - localUser := repo.NewCompareRef(localRef) - remoteUser := repo.NewCompareRef(remoteRef) - localDevel := repo.NewCompareRef(dref) - - // Is the localUser completely inside the remoteUser branch? - 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 { - 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, "") - 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(localUser.GetRefname(), repo.FullPath) - s := "local user branch could not be deleted" - me.sh.BadExit(s, err) - } - return nil, notes - } - return ErrorNeedArgvFix, notes - } - - // Is the localUser completely inside the localDevel branch? - hashok, hashbad, cmd1, cmd2, err = localDevel.CompareBranch(localUser) - for _, line := range hashok { - notes.addNote("OK", repo, localDevel.GetRef(), cmd1, line) - } - for _, line := range hashbad { - notes.addNote("BAD", repo, localUser.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", "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, "") - 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(localUser.GetRefname(), repo.FullPath) - s := "local user branch could not be deleted" - me.sh.BadExit(s, err) - } - } - return ErrorNeedArgvFix, notes - } - return log.Errorf("NOT SAFE"), notes -} - -// 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) - - // get remote user & local devel branches - remoteUser := repo.NewCompareRef(remoteRef) - dref := repo.GetLocalDevelRef() - localDevel := repo.NewCompareRef(dref) - - // 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 -} - -// deletes local user branch if it's entirely in devel -func doFixDeleteLocalUserByDevel(repo *gitpb.Repo, localRef *gitpb.GitTag) (error, *notesList) { - notes := new(notesList) - - localUser := repo.NewCompareRef(localRef) - dref := repo.GetLocalDevelRef() - if dref == nil { - return fmt.Errorf("no local devel"), notes - } - localDevel := repo.NewCompareRef(dref) - - // Is the localUser completely inside the localDevel branch? - hashok, hashbad, cmd1, cmd2, err := localDevel.CompareBranch(localUser) - for _, line := range hashok { - notes.addNote("OK", repo, localDevel.GetRef(), cmd1, line) - } - for _, line := range hashbad { - notes.addNote("BAD", repo, localUser.GetRef(), cmd2, line) - } - 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, "") - 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(localUser.GetRefname(), repo.FullPath) - s := "local user branch could not be deleted" - me.sh.BadExit(s, err) - } - } - return ErrorNeedArgvFix, notes - } - return log.Errorf("NOT SAFE"), notes -} - -// deletes local user branch if it's entirely in master -func doFixDeleteLocalUserByMaster(repo *gitpb.Repo, localRef *gitpb.GitTag) (error, *notesList) { - notes := new(notesList) - - localUser := repo.NewCompareRef(localRef) - mref := repo.GetLocalMasterRef() - if mref == nil { - return fmt.Errorf("no local master"), notes - } - localMaster := repo.NewCompareRef(mref) - - // Is the localUser completely inside the localMaster branch? - hashok, hashbad, cmd1, cmd2, err := localMaster.CompareBranch(localUser) - for _, line := range hashok { - notes.addNote("OK", repo, localMaster.GetRef(), cmd1, line) - } - - for _, line := range hashbad { - notes.addNote("BAD", repo, localUser.GetRef(), cmd2, line) - } - - 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, "") - 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(localUser.GetRefname(), repo.FullPath) - s := "local user branch could not be deleted" - me.sh.BadExit(s, err) - } - } - return ErrorNeedArgvFix, notes - } - - return log.Errorf("NOT SAFE"), notes -} diff --git a/doFix.deleteuser.go b/doFix.deleteuser.go new file mode 100644 index 0000000..84d6610 --- /dev/null +++ b/doFix.deleteuser.go @@ -0,0 +1,312 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "fmt" + "strings" + + "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func doDeleteUser() (string, error) { + found := gitpb.NewRepos() + setForgeMode(forgepb.ForgeMode_MASTER) + for repo := range me.forge.Repos.IterByNamespace() { + uremoteref := repo.GetRemoteTag(repo.GetUserBranchName()) + if uremoteref == nil { + localRef := repo.IsBranchLocal(repo.GetUserBranchName()) + if localRef == nil { + // user branches don't exist + continue + } + log.Info("branch is only local") + if err, _ := doFixDeleteLocalUserByDevel(repo, localRef); err == nil { + // must have deleted it by devel + continue + } + if err, _ := doFixDeleteLocalUserByMaster(repo, localRef); err == nil { + // must have deleted it by master + continue + } + continue + } + found.Repos = append(found.Repos, repo) + if !repo.IsMasterBranch() { + if argv.Fix { + log.Info("you just be in the master branch to run --fix") + repo.State = "needs master branch" + continue + } + } + doFixDeleteUserBranches(repo, uremoteref) + } + me.forge.PrintHumanTable(found) + return "", nil +} + +func doFixPrint(s string, path string, cmd string) { + log.Printf("%-13.13s %-55.55s %s\n", s, path, cmd) +} + +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) + doFixPrint("LOCAL USER", repo.FullPath, localTag.Refname+" local branch exists") + 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)) + } + } + 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 +} + +// 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 +// git update-ref -d refs/heads/jcarr +func doFixDeleteUserLocalBranch(repo *gitpb.Repo, remoteRef *gitpb.GitTag, localRef *gitpb.GitTag) (error, *notesList) { + notes := new(notesList) + + // get local user, remote user & local devel branches + dref := repo.GetLocalDevelRef() + localUser := repo.NewCompareRef(localRef) + remoteUser := repo.NewCompareRef(remoteRef) + localDevel := repo.NewCompareRef(dref) + + // Is the localUser completely inside the remoteUser branch? + 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 { + 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, "") + 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(localUser.GetRefname(), repo.FullPath) + s := "local user branch could not be deleted" + me.sh.BadExit(s, err) + } + return nil, notes + } + return ErrorNeedArgvFix, notes + } + + // Is the localUser completely inside the localDevel branch? + hashok, hashbad, cmd1, cmd2, err = localDevel.CompareBranch(localUser) + for _, line := range hashok { + notes.addNote("OK", repo, localDevel.GetRef(), cmd1, line) + } + for _, line := range hashbad { + notes.addNote("BAD", repo, localUser.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", "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, "") + 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(localUser.GetRefname(), repo.FullPath) + s := "local user branch could not be deleted" + me.sh.BadExit(s, err) + } + } + return ErrorNeedArgvFix, notes + } + return log.Errorf("NOT SAFE"), notes +} + +// 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) + + // get remote user & local devel branches + remoteUser := repo.NewCompareRef(remoteRef) + dref := repo.GetLocalDevelRef() + localDevel := repo.NewCompareRef(dref) + + // 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 +} + +// deletes local user branch if it's entirely in devel +func doFixDeleteLocalUserByDevel(repo *gitpb.Repo, localRef *gitpb.GitTag) (error, *notesList) { + notes := new(notesList) + + localUser := repo.NewCompareRef(localRef) + dref := repo.GetLocalDevelRef() + if dref == nil { + return fmt.Errorf("no local devel"), notes + } + localDevel := repo.NewCompareRef(dref) + + // Is the localUser completely inside the localDevel branch? + hashok, hashbad, cmd1, cmd2, err := localDevel.CompareBranch(localUser) + for _, line := range hashok { + notes.addNote("OK", repo, localDevel.GetRef(), cmd1, line) + } + for _, line := range hashbad { + notes.addNote("BAD", repo, localUser.GetRef(), cmd2, line) + } + 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, "") + 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(localUser.GetRefname(), repo.FullPath) + s := "local user branch could not be deleted" + me.sh.BadExit(s, err) + } + } + return ErrorNeedArgvFix, notes + } + return log.Errorf("NOT SAFE"), notes +} + +// deletes local user branch if it's entirely in master +func doFixDeleteLocalUserByMaster(repo *gitpb.Repo, localRef *gitpb.GitTag) (error, *notesList) { + notes := new(notesList) + + localUser := repo.NewCompareRef(localRef) + mref := repo.GetLocalMasterRef() + if mref == nil { + return fmt.Errorf("no local master"), notes + } + localMaster := repo.NewCompareRef(mref) + + // Is the localUser completely inside the localMaster branch? + hashok, hashbad, cmd1, cmd2, err := localMaster.CompareBranch(localUser) + for _, line := range hashok { + notes.addNote("OK", repo, localMaster.GetRef(), cmd1, line) + } + + for _, line := range hashbad { + notes.addNote("BAD", repo, localUser.GetRef(), cmd2, line) + } + + 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, "") + 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(localUser.GetRefname(), repo.FullPath) + s := "local user branch could not be deleted" + me.sh.BadExit(s, err) + } + } + return ErrorNeedArgvFix, notes + } + + return log.Errorf("NOT SAFE"), notes +} @@ -19,6 +19,9 @@ func doFix() (string, error) { if argv.Fixer.Untracked { return doRemoveUntrackedFiles() } + if argv.Fixer.DeleteUser { + return doDeleteUser() + } return "", nil } |
