From 824c54d205be24ca1324963f71927afd7573b72e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 18 Jan 2025 03:59:05 -0600 Subject: [PATCH] more branch debugging --- Makefile | 2 +- doExamine.go | 101 +++++++++++++++++++++------------------------------ 2 files changed, 42 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index 3534d50..e4af688 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M) info: install # forge dirty - forge examine + forge examine fix vet: @GO111MODULE=off go vet diff --git a/doExamine.go b/doExamine.go index 60104df..c1d3d54 100644 --- a/doExamine.go +++ b/doExamine.go @@ -92,6 +92,30 @@ func examineBranch(repo *gitpb.Repo) error { 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)) log.Info(err) return nil @@ -124,27 +148,23 @@ func showNotDevel(repo *gitpb.Repo) ([]string, error) { cmd = append(cmd, repo.CurrentTag.Hash) cmd = append(cmd, "--not") cmd = append(cmd, "devel") - r, err := repo.RunStrictNew(cmd) - if err != nil { - 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 + r, err := repo.RunVerboseOnError(cmd) + return r.Stdout, err } // count all objects only in branch1 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 cmd = append(cmd, "git") cmd = append(cmd, "log") @@ -152,47 +172,23 @@ func countDiffObjects(repo *gitpb.Repo, branch1, branch2 string) int { cmd = append(cmd, branch1) cmd = append(cmd, "--not") cmd = append(cmd, branch2) - r, err := repo.RunStrictNew(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) + return cmd } +*/ // count all objects only in branch1 func gitPushStrict(repo *gitpb.Repo, branchName string) error { var cmd []string cmd = append(cmd, "git") cmd = append(cmd, "push") - err := gitRun(repo, cmd) + _, err := repo.RunVerbose(cmd) if err != nil { cmd = []string{"git", "whatchanged", repo.CurrentTag.Hash, "-1"} - gitRun(repo, cmd) + repo.RunVerbose(cmd) } 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 { b1 := countDiffObjects(repo, branchName, "origin/"+branchName) b2 := countDiffObjects(repo, "origin/"+branchName, branchName) @@ -210,18 +206,3 @@ func requiresGitPush(repo *gitpb.Repo, branchName string) error { } 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 -}