more branch debugging

This commit is contained in:
Jeff Carr 2025-01-18 03:59:05 -06:00
parent a04e1784d1
commit 824c54d205
2 changed files with 42 additions and 61 deletions

View File

@ -3,7 +3,7 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
info: install info: install
# forge dirty # forge dirty
forge examine forge examine fix
vet: vet:
@GO111MODULE=off go vet @GO111MODULE=off go vet

View File

@ -92,6 +92,30 @@ func examineBranch(repo *gitpb.Repo) error {
return requiresGitPush(repo, "jcarr") return requiresGitPush(repo, "jcarr")
} }
if len(dcount) == 0 {
err = fmt.Errorf("examineBranch() branch differs. patch diff len == 0. PROBABLY DELETE BRANCH %s", repo.CurrentTag.Refname)
log.Info(err)
cmd := repo.ConstructGitDiffLog(repo.CurrentTag.Refname, repo.GetMasterBranchName())
if argv.Examine.Fix == nil {
log.Info(repo.GetGoPath(), cmd)
} else {
if _, err := repo.RunVerbose(cmd); err != nil {
return err
}
}
cmd = repo.ConstructGitDiffLog(repo.GetMasterBranchName(), repo.CurrentTag.Refname)
if argv.Examine.Fix == nil {
log.Info(repo.GetGoPath(), cmd)
} else {
if _, err := repo.RunVerbose(cmd); err != nil {
return err
}
}
cmd = []string{"git", "branch", "-D", repo.CurrentTag.Refname}
log.Info(repo.GetGoPath(), "TRY THIS:", cmd)
log.Info(repo.GetGoPath(), "TODO: CHECK REMOTE BRANCH DOES NOT EXIST")
return err
}
err = fmt.Errorf("examineBranch() branch differs, but not sure how to fix it yet == %d", len(dcount)) err = fmt.Errorf("examineBranch() branch differs, but not sure how to fix it yet == %d", len(dcount))
log.Info(err) log.Info(err)
return nil return nil
@ -124,27 +148,23 @@ func showNotDevel(repo *gitpb.Repo) ([]string, error) {
cmd = append(cmd, repo.CurrentTag.Hash) cmd = append(cmd, repo.CurrentTag.Hash)
cmd = append(cmd, "--not") cmd = append(cmd, "--not")
cmd = append(cmd, "devel") cmd = append(cmd, "devel")
r, err := repo.RunStrictNew(cmd) r, err := repo.RunVerboseOnError(cmd)
if err != nil { return r.Stdout, err
log.Info("Error", cmd, err)
return r.Stdout, err
}
if r == nil {
log.Info("Error r == nil", cmd, err)
return nil, fmt.Errorf("r == nil")
}
/*
if len(r.Stdout) != 0 {
for i, line := range r.Stdout {
log.Info(i, line)
}
}
*/
return r.Stdout, nil
} }
// count all objects only in branch1 // count all objects only in branch1
func countDiffObjects(repo *gitpb.Repo, branch1, branch2 string) int { func countDiffObjects(repo *gitpb.Repo, branch1, branch2 string) int {
cmd := repo.ConstructGitDiffLog(branch1, branch2)
r, err := repo.RunVerboseOnError(cmd)
if err != nil {
return -1
}
log.Info("countDiffObjects()", cmd, len(r.Stdout), strings.Join(r.Stdout, " "))
return len(r.Stdout)
}
/*
func constructGitDiffLog(repo *gitpb.Repo, branch1, branch2 string) []string {
var cmd []string var cmd []string
cmd = append(cmd, "git") cmd = append(cmd, "git")
cmd = append(cmd, "log") cmd = append(cmd, "log")
@ -152,47 +172,23 @@ func countDiffObjects(repo *gitpb.Repo, branch1, branch2 string) int {
cmd = append(cmd, branch1) cmd = append(cmd, branch1)
cmd = append(cmd, "--not") cmd = append(cmd, "--not")
cmd = append(cmd, branch2) cmd = append(cmd, branch2)
r, err := repo.RunStrictNew(cmd) return cmd
if err != nil {
log.Info("Error", cmd, err)
return -1
}
if r == nil {
log.Info("Error r == nil", cmd, err)
return -1
}
/*
if len(r.Stdout) != 0 {
for i, line := range r.Stdout {
log.Info(i, line)
}
}
*/
log.Info("countDiffObjects()", cmd, len(r.Stdout), strings.Join(r.Stdout, " "))
return len(r.Stdout)
} }
*/
// count all objects only in branch1 // count all objects only in branch1
func gitPushStrict(repo *gitpb.Repo, branchName string) error { func gitPushStrict(repo *gitpb.Repo, branchName string) error {
var cmd []string var cmd []string
cmd = append(cmd, "git") cmd = append(cmd, "git")
cmd = append(cmd, "push") cmd = append(cmd, "push")
err := gitRun(repo, cmd) _, err := repo.RunVerbose(cmd)
if err != nil { if err != nil {
cmd = []string{"git", "whatchanged", repo.CurrentTag.Hash, "-1"} cmd = []string{"git", "whatchanged", repo.CurrentTag.Hash, "-1"}
gitRun(repo, cmd) repo.RunVerbose(cmd)
} }
return err return err
} }
func gitPushStrictExit(repo *gitpb.Repo, branchName string) {
err := gitPushStrict(repo, branchName)
if err == nil {
return
}
badExit(err)
}
func requiresGitPush(repo *gitpb.Repo, branchName string) error { func requiresGitPush(repo *gitpb.Repo, branchName string) error {
b1 := countDiffObjects(repo, branchName, "origin/"+branchName) b1 := countDiffObjects(repo, branchName, "origin/"+branchName)
b2 := countDiffObjects(repo, "origin/"+branchName, branchName) b2 := countDiffObjects(repo, "origin/"+branchName, branchName)
@ -210,18 +206,3 @@ func requiresGitPush(repo *gitpb.Repo, branchName string) error {
} }
return nil return nil
} }
func gitRun(repo *gitpb.Repo, cmd []string) error {
log.Info("Run:", repo.GetGoPath(), cmd)
r, err := repo.RunStrictNew(cmd)
if err != nil {
log.Info("Error", cmd, err)
}
for _, line := range r.Stdout {
log.Info(line)
}
for _, line := range r.Stderr {
log.Info(line)
}
return err
}