summaryrefslogtreecommitdiff
path: root/doFix.deleteuser.go
diff options
context:
space:
mode:
Diffstat (limited to 'doFix.deleteuser.go')
-rw-r--r--doFix.deleteuser.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/doFix.deleteuser.go b/doFix.deleteuser.go
index dde0ac9..991f886 100644
--- a/doFix.deleteuser.go
+++ b/doFix.deleteuser.go
@@ -91,6 +91,26 @@ func (notes *notesList) addNote(note string, repo *gitpb.Repo, ref *gitpb.GitTag
notes.all = append(notes.all, newnote)
}
+func (notes *notesList) addTextNote(note string, repo *gitpb.Repo, refname string, cmd []string, line string) {
+ newnote := new(DeleteBranchNotes)
+ newnote.Note = note
+ newnote.Refname = 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
}
@@ -310,3 +330,57 @@ func doFixDeleteLocalUserByMaster(repo *gitpb.Repo, localRef *gitpb.GitTag) (err
return log.Errorf("NOT SAFE"), notes
}
+
+// todo: these names are all horrible
+// delete localRef if it's completely contained in the masterRef
+func safeDelete(repo *gitpb.Repo, deleteHash string, keepHash string) error {
+ notes := new(notesList)
+
+ // compare the branches
+ hashok, hashbad, cmd1, cmd2, err := repo.CompareHashes(keepHash, deleteHash)
+
+ if err != nil {
+ // things are really really messed up. might be 'branchless' at this point (?)
+ 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
+ }
+
+ // things only in the master branch (safe to ignore)
+ for _, line := range hashok {
+ notes.addTextNote("OK", repo, "in keepHash", cmd1, line)
+ }
+
+ // things still only in the local branch (bad to delete)
+ for _, line := range hashbad {
+ // notes.addTextNote("BAD", repo, localRef.GetRef(), cmd2, line)
+ notes.addTextNote("BAD", repo, "in deleteHash", cmd2, line)
+ 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")
+ }
+ findThisHash := parts[0]
+ log.Info(findThisHash, deleteHash, "need to figure out the patchID for this to be deleted hash")
+ }
+
+ if len(hashbad) == 0 {
+ // todo: force checkout to local master branch
+ // before doing this
+ cmd := []string{"git", "update-ref", "-d", deleteHash}
+ 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(deleteHash, repo.FullPath)
+ s := "local user branch could not be deleted"
+ me.sh.BadExit(s, err)
+ }
+ }
+ return ErrorNeedArgvFix
+ }
+
+ return log.Errorf("NOT SAFE")
+}