From 18ee541f89be2e9f9a91c54873da87885e8ffdf5 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 5 Jan 2025 01:18:47 -0600 Subject: [PATCH] 'forge dirty' will find and list only dirty repos --- Makefile | 2 +- argv.go | 40 ++++++++++++++++++++++------------------ cobol.go | 18 ++++++++++-------- doCommon.go | 4 ---- findRepos.go | 42 ++++++++++++++++++++++++++++++++++++------ main.go | 10 ++++++---- 6 files changed, 75 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index c7d863c..3d41721 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,7 @@ patches-apply-230233: install forge --apply /tmp/2024.12.27.230233.submitted.pb dirty: install - forge dirty --all + forge dirty restart: reset diff --git a/argv.go b/argv.go index 5b90fc4..99d11cd 100644 --- a/argv.go +++ b/argv.go @@ -6,33 +6,37 @@ package main var argv args +type EmptyCmd struct { +} + type FindCmd struct { All bool `arg:"--all" help:"select every repo (the default)"` Mine bool `arg:"--mine" help:"your repos as defined in the forge config"` Favorites bool `arg:"--favorites" help:"your repos configured as favorites"` Private bool `arg:"--private" help:"your private repos from your .config/forge/"` + Dirty bool `arg:"--dirty" help:"only use dirty git repos"` // ReadOnly bool `arg:"--readonly" help:"include read-only repos"` } type args struct { - List *FindCmd `arg:"subcommand:list" help:"just show a table of the current state"` - Dirty *FindCmd `arg:"subcommand:dirty" help:"check if your git repos are dirty"` - User *FindCmd `arg:"subcommand:user" help:"git checkout user"` - Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"` - Master *FindCmd `arg:"subcommand:master" help:"git checkout master"` - GitPull *FindCmd `arg:"subcommand:pull" help:"run 'git pull'"` - Config *FindCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"` - ListPatchSet bool `arg:"--list-patchset" help:"list patch sets"` - DryRun bool `arg:"--dry-run" help:"show what would be run"` - Fix bool `arg:"--fix" help:"fix config, save config & exit"` - Delete string `arg:"--delete" help:"delete this repo"` - URL string `arg:"--connect" help:"gowebd url"` - Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"` - GitReset bool `arg:"--git-reset" help:"run 'git reset --hard'"` - Scan bool `arg:"--scan" help:"reload protobuf from .git/"` - Force bool `arg:"--force" help:"force redo things"` - PatchSet string `arg:"--patchset" help:"make patch set"` - Apply string `arg:"--apply" help:"apply a patch set"` + List *FindCmd `arg:"subcommand:list" help:"just show a table of the current state"` + Dirty *EmptyCmd `arg:"subcommand:dirty" help:"check if your git repos are dirty"` + User *FindCmd `arg:"subcommand:user" help:"git checkout user"` + Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"` + Master *FindCmd `arg:"subcommand:master" help:"git checkout master"` + GitPull *FindCmd `arg:"subcommand:pull" help:"run 'git pull'"` + Config *FindCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"` + ListPatchSet bool `arg:"--list-patchset" help:"list patch sets"` + DryRun bool `arg:"--dry-run" help:"show what would be run"` + Fix bool `arg:"--fix" help:"fix config, save config & exit"` + Delete string `arg:"--delete" help:"delete this repo"` + URL string `arg:"--connect" help:"gowebd url"` + Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"` + GitReset bool `arg:"--git-reset" help:"run 'git reset --hard'"` + Scan bool `arg:"--scan" help:"reload protobuf from .git/"` + Force bool `arg:"--force" help:"force redo things"` + PatchSet string `arg:"--patchset" help:"make patch set"` + Apply string `arg:"--apply" help:"apply a patch set"` } func (args) Version() string { diff --git a/cobol.go b/cobol.go index 5c54568..e66ba8d 100644 --- a/cobol.go +++ b/cobol.go @@ -8,7 +8,9 @@ import ( "go.wit.com/log" ) -// ah yes, COBOL. what a throwback. for those that know +// you can replace all of COBOL with this amount of GO + +// ah yes, COBOL. what an ancient throwback. for those that know // then you know exactly what is in this file. For those that don't, here it is: // All this does is output human readable text formatted to be viewable on @@ -34,7 +36,7 @@ func doCobol() { log.DaemonMode(true) // log.Info(standardStart5("gopath", "cur name", "master", "user", "repo type")) - log.Info(standardStart8("repopath", "cur name", "age", "target", "master", "devel", "user", "curver", "repo type")) + log.Info(standardStart8("repopath", "cur br", "age", "target", "master", "devel", "user", "curver", "repo type")) all := me.found.SortByFullPath() for all.Scan() { repo := all.Next() @@ -76,7 +78,7 @@ func standardStart8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 string) len1 := 40 len2 := 12 len3 := 6 - len4 := 16 + len4 := 12 len5 := 16 len6 := 16 len7 := 16 @@ -103,27 +105,27 @@ func standardStart8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 string) if len(arg5) > len5 { arg5 = arg5[:len5] } - s += "%-" + fmt.Sprintf("%d", len5) + "s " + s += "%-" + fmt.Sprintf("%d", len5) + "s " if len(arg6) > len6 { arg6 = arg6[:len6] } - s += "%-" + fmt.Sprintf("%d", len6) + "s " + s += "%-" + fmt.Sprintf("%d", len6) + "s " if len(arg7) > len7 { arg7 = arg7[:len7] } - s += "%-" + fmt.Sprintf("%d", len7) + "s " + s += "%-" + fmt.Sprintf("%d", len7) + "s " if len(arg8) > len8 { arg8 = arg8[:len8] } - s += "%-" + fmt.Sprintf("%d", len8) + "s" + s += "%-" + fmt.Sprintf("%d", len8) + "s " if len(arg9) > len9 { arg9 = arg9[:len9] } - s += "%-" + fmt.Sprintf("%d", len9) + "s" + s += "%-" + fmt.Sprintf("%d", len9) + "s " return fmt.Sprintf(s, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) } diff --git a/doCommon.go b/doCommon.go index d3a2ad2..e7ecb70 100644 --- a/doCommon.go +++ b/doCommon.go @@ -8,10 +8,6 @@ import ( "go.wit.com/log" ) -func doScan() { - me.forge.ScanGoSrc() -} - func doGitPull() { allerr := me.found.RillGitPull(40, 5) diff --git a/findRepos.go b/findRepos.go index a55c2c3..03705a7 100644 --- a/findRepos.go +++ b/findRepos.go @@ -1,6 +1,16 @@ package main -// by default, work against every repo +import ( + "go.wit.com/lib/protobuf/gitpb" +) + +// this populates a slice of protobuf records representing each git repo +// var me.found []*gitpb.Repo +// +// so, it makes a subset of repos that are then used performing actions on +// +// by default, it adds every repo + func (f *FindCmd) findRepos() { if f == nil { findMine() @@ -8,7 +18,7 @@ func (f *FindCmd) findRepos() { } if f.All { - findAll(f) + findAll() return } @@ -21,21 +31,28 @@ func (f *FindCmd) findRepos() { findMine() return } + if f.Favorites { findFavorites() return } - findAll(f) + if f.Dirty { + findDirty() + return + } + + findAll() } +/* func findRepos(fargv *FindCmd) { if fargv == nil { findMine() return } if fargv.All { - findAll(fargv) + findAll() return } @@ -55,6 +72,7 @@ func findRepos(fargv *FindCmd) { findMine() } +*/ func findPrivate() { all := me.forge.Repos.SortByFullPath() @@ -78,7 +96,7 @@ func findMine() { } } -// finds repos that are writable +// finds repos the user has marked as favorites in the forge .config func findFavorites() { // log.Printf("get favorites %s\n", me.forge.GetGoSrc()) all := me.forge.Repos.SortByFullPath() @@ -90,7 +108,19 @@ func findFavorites() { } } -func findAll(fargv *FindCmd) { +// finds repos that git is reporting as dirty +func findDirty() { + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + var repo *gitpb.Repo + repo = all.Next() + if repo.IsDirty() { + me.found.AppendUniqueGoPath(repo) + } + } +} + +func findAll() { all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() diff --git a/main.go b/main.go index 25e801e..6ac2a80 100644 --- a/main.go +++ b/main.go @@ -109,15 +109,17 @@ func main() { // now, do something to all of them (or just print out a table of them) var done bool = false if argv.Dirty != nil { - argv.Dirty.findRepos() + findAll() // select all the repos doCheckDirty() + me.found = new(gitpb.Repos) + findDirty() + doCobol() okExit("") done = true } if argv.Scan { - findRepos(argv.List) - doScan() + me.forge.ScanGoSrc() done = true } @@ -128,7 +130,7 @@ func main() { } if argv.GitReset { - findRepos(argv.List) + findAll() // select all the repos doGitReset() done = true }