summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-15 12:14:22 -0600
committerJeff Carr <[email protected]>2024-12-15 12:14:22 -0600
commitbab2506d348a634ad35f81a09675c9beed493d2b (patch)
tree799b8bcadd628af1f856811512db31c1389c0dc2
parentb3bfa8915c1cc39bb36094829273d43621eb39ee (diff)
trying to fix clonev0.6.28
-rw-r--r--argv.go4
-rw-r--r--clone.go56
-rw-r--r--main.go3
3 files changed, 38 insertions, 25 deletions
diff --git a/argv.go b/argv.go
index cb23077..057f967 100644
--- a/argv.go
+++ b/argv.go
@@ -12,7 +12,7 @@ type args struct {
Repo string `arg:"positional" help:"go import path"`
AutoWork bool `arg:"--work" default:"false" help:"recreate the go.work file"`
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'"`
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"`
@@ -29,7 +29,7 @@ git clone go repositories
Examples:
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 --go-reset # recreate every go.mod and go.sum file
go-clone --git-pull # run 'git pull' in every repo
diff --git a/clone.go b/clone.go
index 4c7cac9..4c1a1ac 100644
--- a/clone.go
+++ b/clone.go
@@ -32,31 +32,9 @@ func clone(gopath string) (*gitpb.Repo, error) {
return nil, err
}
- // first try to generate go.mod & go.sum with go-mod-clean
- 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")
+ if err := makeValidGoSum(pb); err != nil {
return nil, err
}
- pb.ParseGoSum()
// double check it actually downloaded
fullgitdir := filepath.Join(forge.GetGoSrc(), gopath, ".git")
@@ -128,3 +106,35 @@ func recursiveClone(check *gitpb.Repo) error {
}
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
+}
diff --git a/main.go b/main.go
index b84987a..aded69d 100644
--- a/main.go
+++ b/main.go
@@ -49,6 +49,9 @@ func main() {
}
autoWork()
if argv.Build {
+ if err := makeValidGoSum(workingRepo); err != nil {
+ badExit(err)
+ }
if err := build(); err != nil {
badExit(err)
}