'forge dirty' will find and list only dirty repos

This commit is contained in:
Jeff Carr 2025-01-05 01:18:47 -06:00
parent c25a7ea736
commit 18ee541f89
6 changed files with 75 additions and 41 deletions

View File

@ -77,7 +77,7 @@ patches-apply-230233: install
forge --apply /tmp/2024.12.27.230233.submitted.pb forge --apply /tmp/2024.12.27.230233.submitted.pb
dirty: install dirty: install
forge dirty --all forge dirty
restart: restart:
reset reset

40
argv.go
View File

@ -6,33 +6,37 @@ package main
var argv args var argv args
type EmptyCmd struct {
}
type FindCmd struct { type FindCmd struct {
All bool `arg:"--all" help:"select every repo (the default)"` All bool `arg:"--all" help:"select every repo (the default)"`
Mine bool `arg:"--mine" help:"your repos as defined in the forge config"` Mine bool `arg:"--mine" help:"your repos as defined in the forge config"`
Favorites bool `arg:"--favorites" help:"your repos configured as favorites"` Favorites bool `arg:"--favorites" help:"your repos configured as favorites"`
Private bool `arg:"--private" help:"your private repos from your .config/forge/"` 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"` // ReadOnly bool `arg:"--readonly" help:"include read-only repos"`
} }
type args struct { type args struct {
List *FindCmd `arg:"subcommand:list" help:"just show a table of the current state"` 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"` Dirty *EmptyCmd `arg:"subcommand:dirty" help:"check if your git repos are dirty"`
User *FindCmd `arg:"subcommand:user" help:"git checkout user"` User *FindCmd `arg:"subcommand:user" help:"git checkout user"`
Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"` Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"`
Master *FindCmd `arg:"subcommand:master" help:"git checkout master"` Master *FindCmd `arg:"subcommand:master" help:"git checkout master"`
GitPull *FindCmd `arg:"subcommand:pull" help:"run 'git pull'"` GitPull *FindCmd `arg:"subcommand:pull" help:"run 'git pull'"`
Config *FindCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"` Config *FindCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"`
ListPatchSet bool `arg:"--list-patchset" help:"list patch sets"` ListPatchSet bool `arg:"--list-patchset" help:"list patch sets"`
DryRun bool `arg:"--dry-run" help:"show what would be run"` DryRun bool `arg:"--dry-run" help:"show what would be run"`
Fix bool `arg:"--fix" help:"fix config, save config & exit"` Fix bool `arg:"--fix" help:"fix config, save config & exit"`
Delete string `arg:"--delete" help:"delete this repo"` Delete string `arg:"--delete" help:"delete this repo"`
URL string `arg:"--connect" help:"gowebd url"` URL string `arg:"--connect" help:"gowebd url"`
Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"` 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'"` GitReset bool `arg:"--git-reset" help:"run 'git reset --hard'"`
Scan bool `arg:"--scan" help:"reload protobuf from .git/"` Scan bool `arg:"--scan" help:"reload protobuf from .git/"`
Force bool `arg:"--force" help:"force redo things"` Force bool `arg:"--force" help:"force redo things"`
PatchSet string `arg:"--patchset" help:"make patch set"` PatchSet string `arg:"--patchset" help:"make patch set"`
Apply string `arg:"--apply" help:"apply a patch set"` Apply string `arg:"--apply" help:"apply a patch set"`
} }
func (args) Version() string { func (args) Version() string {

View File

@ -8,7 +8,9 @@ import (
"go.wit.com/log" "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: // 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 // All this does is output human readable text formatted to be viewable on
@ -34,7 +36,7 @@ func doCobol() {
log.DaemonMode(true) log.DaemonMode(true)
// log.Info(standardStart5("gopath", "cur name", "master", "user", "repo type")) // 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() all := me.found.SortByFullPath()
for all.Scan() { for all.Scan() {
repo := all.Next() repo := all.Next()
@ -76,7 +78,7 @@ func standardStart8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 string)
len1 := 40 len1 := 40
len2 := 12 len2 := 12
len3 := 6 len3 := 6
len4 := 16 len4 := 12
len5 := 16 len5 := 16
len6 := 16 len6 := 16
len7 := 16 len7 := 16
@ -103,27 +105,27 @@ func standardStart8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 string)
if len(arg5) > len5 { if len(arg5) > len5 {
arg5 = arg5[:len5] arg5 = arg5[:len5]
} }
s += "%-" + fmt.Sprintf("%d", len5) + "s " s += "%-" + fmt.Sprintf("%d", len5) + "s "
if len(arg6) > len6 { if len(arg6) > len6 {
arg6 = arg6[:len6] arg6 = arg6[:len6]
} }
s += "%-" + fmt.Sprintf("%d", len6) + "s " s += "%-" + fmt.Sprintf("%d", len6) + "s "
if len(arg7) > len7 { if len(arg7) > len7 {
arg7 = arg7[:len7] arg7 = arg7[:len7]
} }
s += "%-" + fmt.Sprintf("%d", len7) + "s " s += "%-" + fmt.Sprintf("%d", len7) + "s "
if len(arg8) > len8 { if len(arg8) > len8 {
arg8 = arg8[:len8] arg8 = arg8[:len8]
} }
s += "%-" + fmt.Sprintf("%d", len8) + "s" s += "%-" + fmt.Sprintf("%d", len8) + "s "
if len(arg9) > len9 { if len(arg9) > len9 {
arg9 = 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) return fmt.Sprintf(s, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
} }

View File

@ -8,10 +8,6 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
func doScan() {
me.forge.ScanGoSrc()
}
func doGitPull() { func doGitPull() {
allerr := me.found.RillGitPull(40, 5) allerr := me.found.RillGitPull(40, 5)

View File

@ -1,6 +1,16 @@
package main 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() { func (f *FindCmd) findRepos() {
if f == nil { if f == nil {
findMine() findMine()
@ -8,7 +18,7 @@ func (f *FindCmd) findRepos() {
} }
if f.All { if f.All {
findAll(f) findAll()
return return
} }
@ -21,21 +31,28 @@ func (f *FindCmd) findRepos() {
findMine() findMine()
return return
} }
if f.Favorites { if f.Favorites {
findFavorites() findFavorites()
return return
} }
findAll(f) if f.Dirty {
findDirty()
return
}
findAll()
} }
/*
func findRepos(fargv *FindCmd) { func findRepos(fargv *FindCmd) {
if fargv == nil { if fargv == nil {
findMine() findMine()
return return
} }
if fargv.All { if fargv.All {
findAll(fargv) findAll()
return return
} }
@ -55,6 +72,7 @@ func findRepos(fargv *FindCmd) {
findMine() findMine()
} }
*/
func findPrivate() { func findPrivate() {
all := me.forge.Repos.SortByFullPath() 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() { func findFavorites() {
// log.Printf("get favorites %s\n", me.forge.GetGoSrc()) // log.Printf("get favorites %s\n", me.forge.GetGoSrc())
all := me.forge.Repos.SortByFullPath() 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() all := me.forge.Repos.SortByFullPath()
for all.Scan() { for all.Scan() {
repo := all.Next() repo := all.Next()

10
main.go
View File

@ -109,15 +109,17 @@ func main() {
// now, do something to all of them (or just print out a table of them) // now, do something to all of them (or just print out a table of them)
var done bool = false var done bool = false
if argv.Dirty != nil { if argv.Dirty != nil {
argv.Dirty.findRepos() findAll() // select all the repos
doCheckDirty() doCheckDirty()
me.found = new(gitpb.Repos)
findDirty()
doCobol()
okExit("") okExit("")
done = true done = true
} }
if argv.Scan { if argv.Scan {
findRepos(argv.List) me.forge.ScanGoSrc()
doScan()
done = true done = true
} }
@ -128,7 +130,7 @@ func main() {
} }
if argv.GitReset { if argv.GitReset {
findRepos(argv.List) findAll() // select all the repos
doGitReset() doGitReset()
done = true done = true
} }