trying to fix clone

This commit is contained in:
Jeff Carr 2024-12-15 12:14:22 -06:00
parent b3bfa8915c
commit bab2506d34
3 changed files with 38 additions and 25 deletions

View File

@ -12,7 +12,7 @@ type args struct {
Repo string `arg:"positional" help:"go import path"` Repo string `arg:"positional" help:"go import path"`
AutoWork bool `arg:"--work" default:"false" help:"recreate the go.work file"` AutoWork bool `arg:"--work" default:"false" help:"recreate the go.work file"`
DryRun bool `arg:"--dry-run" help:"show what would be run"` DryRun bool `arg:"--dry-run" help:"show what would be run"`
Recursive bool `arg:"--recursive" default:"false" help:"resursively clone all dependencies"` Recursive bool `arg:"--recursive" default:"false" help:"recursively clone all dependencies"`
Pull bool `arg:"--git-pull" default:"false" help:"run 'git pull'"` Pull bool `arg:"--git-pull" default:"false" help:"run 'git pull'"`
Build bool `arg:"--build" default:"true" help:"try to build it after clone"` Build bool `arg:"--build" default:"true" help:"try to build it after clone"`
Install bool `arg:"--install" default:"false" help:"try to install it after clone"` Install bool `arg:"--install" default:"false" help:"try to install it after clone"`
@ -29,7 +29,7 @@ git clone go repositories
Examples: Examples:
go-clone go.wit.com/apps/go-clone # simply try to git clone this go-clone go.wit.com/apps/go-clone # simply try to git clone this
go-clone --recursive go.wit.com/apps/go-clone # recursively clone all the dependancies go-clone --recursive go.wit.com/apps/go-clone # recursively clone all the dependencies
go-clone --auto-work go.wit.com/apps/go-clone # if you are using a go.work file, recreate the go.work file go-clone --auto-work go.wit.com/apps/go-clone # if you are using a go.work file, recreate the go.work file
go-clone --go-reset # recreate every go.mod and go.sum file go-clone --go-reset # recreate every go.mod and go.sum file
go-clone --git-pull # run 'git pull' in every repo go-clone --git-pull # run 'git pull' in every repo

View File

@ -32,31 +32,9 @@ func clone(gopath string) (*gitpb.Repo, error) {
return nil, err return nil, err
} }
// first try to generate go.mod & go.sum with go-mod-clean if err := makeValidGoSum(pb); err != nil {
if err := pb.ValidGoSum(); err != nil {
// update go.sum and go.mod
if err := pb.RunStrict([]string{"go-mod-clean"}); err != nil {
log.Info("")
log.Info("Do you have go-mod-clean? Otherwise:")
log.Info(" go install go.wit.com/apps/go-mod-clean@latest")
log.Info("")
}
}
// if this fails, just use go mod
if err := pb.ValidGoSum(); err != nil {
if err := pb.RunStrict([]string{"go", "mod", "init", pb.GoPath}); err != nil {
log.Info("go mod init failed", err)
}
if err := pb.RunStrict([]string{"go", "mod", "tidy"}); err != nil {
log.Info("go mod tidy failed", err)
}
}
if err := pb.ValidGoSum(); err != nil {
// have to give up. can't recursive clone without go.mod file
log.Info("could not generate valid go.sum file")
return nil, err return nil, err
} }
pb.ParseGoSum()
// double check it actually downloaded // double check it actually downloaded
fullgitdir := filepath.Join(forge.GetGoSrc(), gopath, ".git") fullgitdir := filepath.Join(forge.GetGoSrc(), gopath, ".git")
@ -128,3 +106,35 @@ func recursiveClone(check *gitpb.Repo) error {
} }
return nil return nil
} }
func makeValidGoSum(check *gitpb.Repo) error {
// first try to generate go.mod & go.sum with go-mod-clean
if err := check.ValidGoSum(); err != nil {
log.Info("try running go-mod-clean")
// update go.sum and go.mod
if err := check.RunStrict([]string{"go-mod-clean"}); err != nil {
log.Info("")
log.Info("Do you have go-mod-clean? Otherwise:")
log.Info(" go install go.wit.com/apps/go-mod-clean@latest")
log.Info("")
}
}
// if this fails, just use go mod
if err := check.ValidGoSum(); err != nil {
cmd := []string{"go", "mod", "init", check.GoPath}
log.Info("try running", cmd)
if err := check.RunStrict(cmd); err != nil {
log.Info("go mod init failed", err)
}
if err := check.RunStrict([]string{"go", "mod", "tidy"}); err != nil {
log.Info("go mod tidy failed", err)
}
}
if err := check.ValidGoSum(); err != nil {
// have to give up. can't recursive clone without go.mod file
log.Info("could not generate valid go.sum file")
return err
}
check.ParseGoSum()
return nil
}

View File

@ -49,6 +49,9 @@ func main() {
} }
autoWork() autoWork()
if argv.Build { if argv.Build {
if err := makeValidGoSum(workingRepo); err != nil {
badExit(err)
}
if err := build(); err != nil { if err := build(); err != nil {
badExit(err) badExit(err)
} }