summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--argv.go13
-rw-r--r--doAdd.go10
-rw-r--r--doStats.go82
-rw-r--r--main.go4
5 files changed, 108 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index f757a8e..7924b78 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ BUILDTIME = $(shell date +%s)
# make andlabs # try the andlabs gui plugin (uses GTK)
default: install
- # forge pull check
+ forge verify
# This will re-generate ALL of the needed autogenerated .pb.go files
generate: clean
diff --git a/argv.go b/argv.go
index 7cfbc7b..9ee7460 100644
--- a/argv.go
+++ b/argv.go
@@ -31,7 +31,8 @@ type args struct {
Show *ShowCmd `arg:"subcommand:show" help:"print out things"`
Dev *DevCmd `arg:"subcommand:dev" help:"features under development"`
Add *EmptyCmd `arg:"subcommand:add" help:"Scan directores for git repos"`
- Fixer *FixCmd `arg:"subcommand:fixer" help:"like in the movie"`
+ Fixer *FixCmd `arg:"subcommand:fixer" help:"send in the fixer"`
+ Verify *VerifyCmd `arg:"subcommand:verify" help:"populate stats"`
All bool `arg:"--all" help:"whatever you are doing, do it all over"`
Force bool `arg:"--force" help:"try to strong-arm things"`
Verbose bool `arg:"--verbose" help:"show more output than usual"`
@@ -60,6 +61,11 @@ type FixCmd struct {
Prune bool `arg:"--prune" help:"'git fetch --prune' everywhere"`
}
+type VerifyCmd struct {
+ List bool `arg:"--list" help:"list all stats"`
+ All bool `arg:"--all" help:"do all repos"`
+}
+
func (ShowCmd) Examples() string {
return "forge show dirty\nforge show repos --all"
}
@@ -230,7 +236,10 @@ func (args) Examples() string {
func (a args) SendCompletionStrings(pb *prep.Auto) {
if pb.Cmd == "" {
// these are base autocomplete strings
- pb.SendStrings([]string{"checkout", "clean", "commit", "gui", "merge", "mode", "patch", "pull", "show", "add", "fixer", "--version", "--force", "dev", "normal", "--all"})
+ matches := []string{"checkout", "clean", "commit", "merge", "patch", "normal", "pull"}
+ matches = append(matches, "show", "add", "fixer", "dev", "verify", "mode", "gui")
+ matches = append(matches, "--version", "--force", "--all")
+ pb.SendStrings(matches)
} else {
// autogenerate the strings for the subcommand using github.com/alexflint/go-arg
pb.GenerateSubCommandStrings(pb.Goargs...)
diff --git a/doAdd.go b/doAdd.go
index 49b4db6..7267eb5 100644
--- a/doAdd.go
+++ b/doAdd.go
@@ -11,6 +11,16 @@ import (
"go.wit.com/log"
)
+func workingDirToRepo() *gitpb.Repo {
+ wd, _ := os.Getwd()
+ for repo := range me.forge.Repos.IterAll() {
+ if strings.HasPrefix(repo.FullPath, wd) {
+ return repo
+ }
+ }
+ return nil
+}
+
func doAdd() error {
wd, _ := os.Getwd()
found := gitpb.NewRepos()
diff --git a/doStats.go b/doStats.go
new file mode 100644
index 0000000..ded473c
--- /dev/null
+++ b/doStats.go
@@ -0,0 +1,82 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+import (
+ "errors"
+ "strings"
+
+ "go.wit.com/lib/protobuf/gitpb"
+ "go.wit.com/log"
+)
+
+func doVerify() (string, error) {
+ if argv.Verify.All {
+ for r := range me.forge.Repos.IterByFullPath() {
+ if r.Stats == nil {
+ doStats(r)
+ return r.FullPath, nil
+ }
+ }
+ return "verify ran everywhere", nil
+ }
+
+ repo := workingDirToRepo()
+ if repo == nil {
+ return "no repo", errors.New("working dir isn't a repo I know about")
+ }
+
+ return doStats(repo)
+}
+
+func doStats(r *gitpb.Repo) (string, error) {
+ var allerr error
+ // collect the stats
+ err := collectStats(r)
+ allerr = errors.Join(allerr, err)
+
+ // build()
+ return "verify ran", nil
+}
+
+func collectStats(r *gitpb.Repo) error {
+ if r.Stats == nil {
+ r.Stats = new(gitpb.Stats)
+ }
+ if hasOrigin(r) {
+ log.Info("repo doesn't have origin")
+ }
+ last100(r)
+ return nil
+}
+
+// git show-ref --verify refs/remotes/origin/HEAD
+func hasOrigin(r *gitpb.Repo) bool {
+ // git show-ref refs/remotes/origin/HEAD
+ return true
+}
+
+var standardFmts []string = []string{"H", "T", "at", "ct", "f"}
+var standardSeperator string = "___FORGE___"
+
+func makeFmts() string {
+ // fmts := strings.Fields(config.GetPanic("standardFmts"))
+ // fmts := strings.Fields(config.GetPanic("standardSeperator"))
+ var news []string
+ for _, fmtvar := range standardFmts {
+ news = append(news, "%"+fmtvar)
+ }
+ return "--format=" + strings.Join(news, standardSeperator)
+}
+
+func last100(r *gitpb.Repo) error {
+ cmd := []string{"git", "log", "-n", "10", makeFmts(), "origin/" + r.GetMasterBranchName()}
+ log.Info("Run:", cmd)
+ cmdout := r.Run(cmd)
+ for i, line := range cmdout.Stdout {
+ parts := strings.Split(line, standardSeperator)
+ log.Printf("LINE:%d %v\n", i, parts)
+ }
+ return nil
+}
diff --git a/main.go b/main.go
index a5ac2fa..6154705 100644
--- a/main.go
+++ b/main.go
@@ -121,6 +121,10 @@ func main() {
if argv.Patch != nil {
s, err = doPatch()
}
+
+ if argv.Verify != nil {
+ s, err = doVerify()
+ }
//// end standard argv subcommand processing here ////
// if the gui starts, it doesn't yet go to the end normally