summaryrefslogtreecommitdiff
path: root/doSmart.go
diff options
context:
space:
mode:
Diffstat (limited to 'doSmart.go')
-rw-r--r--doSmart.go37
1 files changed, 27 insertions, 10 deletions
diff --git a/doSmart.go b/doSmart.go
index 7ac902f..1f32138 100644
--- a/doSmart.go
+++ b/doSmart.go
@@ -8,45 +8,62 @@ import (
// this will make go.mod and go.sum files, but you have to
// have the files in .gitignore for now
func doSmart(repo *gitpb.Repo) error {
+ // erase the go.mod and go.sum files
+ eraseGoMod(repo)
+
// if the repo has go.mod in the repo...
if err := repo.RepoIgnoresGoMod(); err != nil {
+ if repo.ParseGoSum() {
+ return nil
+ }
log.Info("go-mod-clean can not run on this repo", repo.GetGoPath())
log.Info("go.mod and go.sum must be git metadata to continue")
- repo.ParseGoSum()
+ // return nil
+ }
+ if repo.Exists("go.mod") {
return nil
}
- // erase the go.mod and go.sum files
- eraseGoMod(repo)
-
// try to restore from the git metadata
cname := repo.GetCurrentBranchName()
if err := repo.AutogenRestore(cname); err == nil {
log.Info(repo.GetGoPath(), "files were restored ok from git metadata (notes)")
- configSave = true
+ }
+ if repo.Exists("go.mod") {
return nil
}
// attempt to restore from ~/go/pkg/mod/
if err := restoreFromGoPkg(repo); err == nil {
- configSave = true
+ log.Info(repo.GetGoPath(), "files were restored ok ~/go/mod/")
+ }
+ if repo.Exists("go.mod") {
return nil
}
// actually will re-create go.sum and go.mod now
if err := redoGoMod(repo); err != nil {
- return err
+ log.Info(repo.GetGoPath(), "the files were restored with redoGoMod()")
+ }
+ if repo.Exists("go.mod") {
+ return nil
}
// the first time, it'll attempt to fix some stuff
cleanGoDepsCheckOk(repo)
// try to trim junk
if err := trimGoSum(repo); err != nil {
- return err
+ }
+ if repo.Exists("go.mod") {
+ return nil
}
repo.ParseGoSum()
- // everything worked more or less
- configSave = true
+ if repo.Exists("go.mod") {
+ return nil
+ }
+ // last chance. just run go mod init
+ repo.RunVerbose([]string{"go", "mod", "init"})
+
return nil
}