'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
dirty: install
forge dirty --all
forge dirty
restart:
reset

View File

@ -6,17 +6,21 @@ 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"`
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"`

View File

@ -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

View File

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

View File

@ -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()

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)
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
}