add --purge to get rid of all notes
This commit is contained in:
parent
4879befeb3
commit
5c156fa55e
32
all.go
32
all.go
|
@ -1,32 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
// rethink this. do not run on non-master git branches
|
|
||||||
func doAll() {
|
|
||||||
if argv.All {
|
|
||||||
if forge.IsGoWork() {
|
|
||||||
var warning []string
|
|
||||||
warning = append(warning, "go-mod-clean --recursive may not work unless you are in ~/go/src")
|
|
||||||
warning = append(warning, "you can continue anyway, but it hasn't been tested as much.")
|
|
||||||
simpleStdin(true, warning)
|
|
||||||
}
|
|
||||||
var warning []string
|
|
||||||
warning = append(warning, "go-mod-clean will recreate go.mod and go.sum")
|
|
||||||
warning = append(warning, "because you have selected --recursive")
|
|
||||||
warning = append(warning, "this will redo _every_ repo. This is probably fine.")
|
|
||||||
warning = append(warning, fmt.Sprintf("You have %d total repositories in %s", forge.Repos.Len(), forge.GetGoSrc()))
|
|
||||||
warning = append(warning, "")
|
|
||||||
warning = append(warning, "However, this will also, at times, do:")
|
|
||||||
warning = append(warning, "")
|
|
||||||
warning = append(warning, "rm -rf ~/go/pkg/")
|
|
||||||
warning = append(warning, "rm -rf ~/.config/go-build/")
|
|
||||||
warning = append(warning, "")
|
|
||||||
warning = append(warning, "Which is also probably fine, but will clear all your build cache and go mod cache")
|
|
||||||
warning = append(warning, "")
|
|
||||||
simpleStdin(false, warning)
|
|
||||||
// purgeGoCaches()
|
|
||||||
}
|
|
||||||
}
|
|
8
argv.go
8
argv.go
|
@ -7,14 +7,12 @@ package main
|
||||||
var argv args
|
var argv args
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
All bool `arg:"--all" default:"false" help:"redo every repo found in go/src or go.work"`
|
|
||||||
Auto bool `arg:"--auto" help:"don't approve via STDIN"`
|
|
||||||
Trim bool `arg:"--trim" default:"true" help:"trim entries from go.sum"`
|
Trim bool `arg:"--trim" default:"true" help:"trim entries from go.sum"`
|
||||||
Verbose bool `arg:"--verbose" help:"show more"`
|
Verbose bool `arg:"--verbose" help:"show more"`
|
||||||
Notes bool `arg:"--metadata" help:"save as git metadata (notes)"`
|
Restore bool `arg:"--restore" help:"only restore from go/pkg/mod/"`
|
||||||
Restore bool `arg:"--restore" default:"true" help:"restore from git metadata"`
|
|
||||||
Force bool `arg:"--force" help:"remove things and redo them no matter what"`
|
Force bool `arg:"--force" help:"remove things and redo them no matter what"`
|
||||||
Strict bool `arg:"--strict" default:"false" help:"never make go.* files unless everything is perfect"`
|
Strict bool `arg:"--strict" help:"never make go.* files unless everything is perfect"`
|
||||||
|
Purge bool `arg:"--purge" help:"purge all the git notes. this might be bad for you."`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (args) Version() string {
|
func (args) Version() string {
|
||||||
|
|
63
main.go
63
main.go
|
@ -1,9 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
|
@ -33,17 +31,6 @@ func main() {
|
||||||
// this lets you configure repos you have read/write access too
|
// this lets you configure repos you have read/write access too
|
||||||
forge = forgepb.Init()
|
forge = forgepb.Init()
|
||||||
|
|
||||||
if argv.All {
|
|
||||||
// run this on every single repo
|
|
||||||
// do this before publishing new golang versions
|
|
||||||
all := forge.Repos.SortByFullPath()
|
|
||||||
for all.Scan() {
|
|
||||||
check = all.Next()
|
|
||||||
if err := doMain(check); err != nil {
|
|
||||||
badExit(check, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// figure out what directory we are running in
|
// figure out what directory we are running in
|
||||||
check = findPwdRepo()
|
check = findPwdRepo()
|
||||||
if check == nil {
|
if check == nil {
|
||||||
|
@ -51,6 +38,20 @@ func main() {
|
||||||
badExit(nil, nil)
|
badExit(nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deletes all the git notes
|
||||||
|
if argv.Purge {
|
||||||
|
purgeNotes(check)
|
||||||
|
okExit(check, "notes gone")
|
||||||
|
}
|
||||||
|
|
||||||
|
if argv.Restore {
|
||||||
|
// attempt to restore from ~/go/pkg/mod/
|
||||||
|
if err := restoreFromGoPkg(check); err != nil {
|
||||||
|
badExit(check, err)
|
||||||
|
}
|
||||||
|
okExit(check, "go.mod and go.sum restored from ~/go/pkg/mod/")
|
||||||
|
}
|
||||||
|
|
||||||
if err := doMain(check); err != nil {
|
if err := doMain(check); err != nil {
|
||||||
badExit(check, err)
|
badExit(check, err)
|
||||||
}
|
}
|
||||||
|
@ -63,7 +64,6 @@ func main() {
|
||||||
badExit(check, err)
|
badExit(check, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if configSave {
|
if configSave {
|
||||||
forge.ConfigSave()
|
forge.ConfigSave()
|
||||||
|
@ -105,41 +105,6 @@ func saveAsMetadata(repo *gitpb.Repo) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func restoreFromGoPkg(repo *gitpb.Repo) error {
|
|
||||||
homedir, err := os.UserHomeDir()
|
|
||||||
if err != nil {
|
|
||||||
badExit(nil, err)
|
|
||||||
}
|
|
||||||
rver := repo.GetMasterVersion()
|
|
||||||
if rver == "" {
|
|
||||||
return errors.New("could not get master version")
|
|
||||||
}
|
|
||||||
modfile := filepath.Join(homedir, "go/pkg/mod", repo.GetGoPath()+"@"+rver, "go.mod")
|
|
||||||
log.Info("mod path should be", modfile)
|
|
||||||
data, err := os.ReadFile(modfile)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
modf, err := os.OpenFile("go.mod", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer modf.Close()
|
|
||||||
modf.Write(data)
|
|
||||||
|
|
||||||
modfile = filepath.Join(homedir, "go/pkg/mod", repo.GetGoPath()+"@"+rver, "go.sum")
|
|
||||||
log.Info("mod path should be", modfile)
|
|
||||||
data, err = os.ReadFile(modfile)
|
|
||||||
if err == nil {
|
|
||||||
sumf, _ := os.OpenFile("go.sum", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
|
||||||
defer sumf.Close()
|
|
||||||
sumf.Write(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// try go.sum, but no error checking since it might not be there
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func doMain(repo *gitpb.Repo) error {
|
func doMain(repo *gitpb.Repo) error {
|
||||||
if argv.Strict {
|
if argv.Strict {
|
||||||
return doStrict(repo)
|
return doStrict(repo)
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func purgeNotes(repo *gitpb.Repo) error {
|
||||||
|
result := repo.Run([]string{"git", "notes", "list"})
|
||||||
|
for _, line := range result.Stdout {
|
||||||
|
parts := strings.Fields(line)
|
||||||
|
log.Info("line:", line, "part", parts[1])
|
||||||
|
blah := repo.Run([]string{"git", "notes", "remove", parts[1]})
|
||||||
|
log.Info(strings.Join(blah.Stdout, "\n"))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func restoreFromGoPkg(repo *gitpb.Repo) error {
|
||||||
|
homedir, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
badExit(nil, err)
|
||||||
|
}
|
||||||
|
rver := repo.GetMasterVersion()
|
||||||
|
if rver == "" {
|
||||||
|
return errors.New("could not get master version")
|
||||||
|
}
|
||||||
|
modfile := filepath.Join(homedir, "go/pkg/mod", repo.GetGoPath()+"@"+rver, "go.mod")
|
||||||
|
log.Info("mod path should be", modfile)
|
||||||
|
data, err := os.ReadFile(modfile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
modf, err := os.OpenFile("go.mod", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer modf.Close()
|
||||||
|
modf.Write(data)
|
||||||
|
|
||||||
|
modfile = filepath.Join(homedir, "go/pkg/mod", repo.GetGoPath()+"@"+rver, "go.sum")
|
||||||
|
log.Info("mod path should be", modfile)
|
||||||
|
data, err = os.ReadFile(modfile)
|
||||||
|
if err == nil {
|
||||||
|
sumf, _ := os.OpenFile("go.sum", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
|
defer sumf.Close()
|
||||||
|
sumf.Write(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// try go.sum, but no error checking since it might not be there
|
||||||
|
return nil
|
||||||
|
}
|
5
stdin.go
5
stdin.go
|
@ -24,10 +24,7 @@ func showOptions(b bool, s []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if b == true, default is to continue with 'Y'
|
// if b == true, default is to continue with 'Y'
|
||||||
func simpleStdin(b bool, s []string) {
|
func simpleStdinOld(b bool, s []string) {
|
||||||
if argv.Auto {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err := errors.New("user cancelled via stdin")
|
err := errors.New("user cancelled via stdin")
|
||||||
showOptions(b, s)
|
showOptions(b, s)
|
||||||
scanner := bufio.NewScanner(os.Stdin)
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
|
Loading…
Reference in New Issue