diff --git a/Makefile b/Makefile index 23f818c..3534d50 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ VERSION = $(shell git describe --tags) -BUILDTIME = $(shell date +%Y.%m.%d) +BUILDTIME = $(shell date +%Y.%m.%d_%H%M) info: install # forge dirty diff --git a/argv.go b/argv.go index 3d0b617..5d8923e 100644 --- a/argv.go +++ b/argv.go @@ -22,7 +22,7 @@ type args struct { Rescan *EmptyCmd `arg:"subcommand:rescan" help:"recreate the git protobuf repos.pb file"` Delete *EmptyCmd `arg:"subcommand:delete" help:"untrack a repo"` Commit *EmptyCmd `arg:"subcommand:commit" help:"smart 'git commit' (errors out if on wrong branch)"` - Examine *EmptyCmd `arg:"subcommand:examine" help:"examine branches"` + Examine *ExamineCmd `arg:"subcommand:examine" help:"examine branches"` URL string `arg:"--connect" help:"gowebd url"` All bool `arg:"--all" help:"git commit --all"` Show string `arg:"--show" help:"show a repo"` @@ -36,10 +36,16 @@ type EmptyCmd struct { type testCmd string +type ExamineCmd struct { + Fix *EmptyCmd `arg:"subcommand:fix" help:"try to auto fix branches"` + Show *EmptyCmd `arg:"subcommand:show" help:"show a specific patch"` + Submit string `arg:"--submit" help:"name of patchset"` +} + type PatchCmd struct { List *EmptyCmd `arg:"subcommand:list" help:"list available patches"` Show *EmptyCmd `arg:"subcommand:show" help:"show a specific patch"` - Submit string `arg:"--submit" help:"name of patchset"` + Submit string `arg:"--submit" help:"submit a new patchset with name"` } type ConfigAddCmd struct { diff --git a/argvAutoshell.go b/argvAutoshell.go index 2cfc004..a32c2fd 100644 --- a/argvAutoshell.go +++ b/argvAutoshell.go @@ -27,22 +27,24 @@ func (args) doBashAuto() { fmt.Println("--all") case "config": fmt.Println("add fix list delete") + case "delete": + argv.Delete.deleteMatch() + case "dirty": + fmt.Println("--show-files") + case "examine": + fmt.Println("fix") case "list": fmt.Println("--all --mine --favorites --private") case "pull": fmt.Println("--all --mine --favorites --private") case "patch": fmt.Println("list --submit show") - case "dirty": - fmt.Println("--show-files") case "user": fmt.Println("--force") case "devel": fmt.Println("--force") case "master": fmt.Println("--force") - case "delete": - argv.Delete.deleteMatch() default: if argv.BashAuto[0] == ARGNAME { // list the subcommands here diff --git a/doExamine.go b/doExamine.go index f3f1dd1..60104df 100644 --- a/doExamine.go +++ b/doExamine.go @@ -1,7 +1,9 @@ package main import ( + "fmt" "slices" + "strings" "time" "go.wit.com/lib/gui/shell" @@ -50,7 +52,12 @@ func doExamine() bool { ctime := tag.Creatordate.AsTime() dur := time.Since(ctime) log.Printf("UNKNOWN BRANCH %-50s %s %4s %s\n", repo.GetFullPath(), tag.Hash, shell.FormatDuration(dur), tag.Refname) - showNotDevel(repo) + err := examineBranch(repo) + if argv.Examine.Fix != nil { + if err != nil { + badExit(err) + } + } me.found.AppendByGoPath(repo) } @@ -68,7 +75,48 @@ func isNormal(repo *gitpb.Repo) bool { return false } -func showNotDevel(repo *gitpb.Repo) error { +func examineBranch(repo *gitpb.Repo) error { + dcount, err := showNotDevel(repo) + if err != nil { + return err + } + if repo.CurrentTag == nil { + return fmt.Errorf("repo.CurrentTag == nil") + } + + if repo.CurrentTag.Refname == "jcarr" { + return requiresGitPush(repo, "jcarr") + } + + if repo.CurrentTag.Refname == "origin/jcarr" { + return requiresGitPush(repo, "jcarr") + } + + err = fmt.Errorf("examineBranch() branch differs, but not sure how to fix it yet == %d", len(dcount)) + log.Info(err) + return nil +} + +func checkJcarr(repo *gitpb.Repo) int { + b1 := countDiffObjects(repo, "jcarr", "origin/jcarr") + b2 := countDiffObjects(repo, "origin/jcarr", "jcarr") + log.Info("jcarr vs origin count", b1, b2) + if b1 == 0 && b2 == 0 { + return 0 + } + if b1 != 0 { + log.Info("jcarr vs origin count b1 != 0, b2 ==", b1, b2) + log.Info("THIS MEANS THE LOCAL BRANCH NEEDS GIT PUSH TO ORIGIN BRANCH ==", b1, b2) + return b1 + } + if b2 != 0 { + log.Info("jcarr vs origin count b2 != 0, b1 ==", b2, b1) + return b2 + } + return -1 +} + +func showNotDevel(repo *gitpb.Repo) ([]string, error) { var cmd []string cmd = append(cmd, "git") cmd = append(cmd, "log") @@ -79,16 +127,101 @@ func showNotDevel(repo *gitpb.Repo) error { r, err := repo.RunStrictNew(cmd) if err != nil { log.Info("Error", cmd, err) - return 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 +func countDiffObjects(repo *gitpb.Repo, branch1, branch2 string) int { + var cmd []string + cmd = append(cmd, "git") + cmd = append(cmd, "log") + cmd = append(cmd, "--format=\"%H\"") + 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) +} + +// 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) + if err != nil { + cmd = []string{"git", "whatchanged", repo.CurrentTag.Hash, "-1"} + gitRun(repo, 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) + log.Info("jcarr vs origin count", b1, b2) + if b1 == 0 && b2 == 0 { return nil } - if len(r.Stdout) != 0 { - for i, line := range r.Stdout { - log.Info(i, line) + if b1 != 0 { + log.Info("jcarr vs origin count b1 != 0, b2 ==", b1, b2) + log.Info("THIS MEANS THE LOCAL BRANCH NEEDS GIT PUSH TO ORIGIN BRANCH ==", b1) + if argv.Examine.Fix != nil { + return gitPushStrict(repo, branchName) } + 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 +}