diff options
| author | Jeff Carr <[email protected]> | 2024-12-13 18:59:40 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-12-13 18:59:40 -0600 |
| commit | 22c29b3625f4fac9a345cc3734625f71cc90244e (patch) | |
| tree | 4bd394903a30e917658fb2b9b80ea91115af663b | |
| parent | 3a83cf030d6037790f1a57bb224f6bf55054a120 (diff) | |
better logic for valid go.mod filesv0.0.1
| -rw-r--r-- | isTracked.go | 4 | ||||
| -rw-r--r-- | main.go | 25 |
2 files changed, 19 insertions, 10 deletions
diff --git a/isTracked.go b/isTracked.go index 391ecd5..414414b 100644 --- a/isTracked.go +++ b/isTracked.go @@ -32,7 +32,7 @@ func isIgnored(file string) (bool, error) { return false, fmt.Errorf("error checking ignored status: %v", err) } -func repoOwnsGoMod(repo *gitpb.Repo) (bool, error) { +func repoIgnoresGoMod(repo *gitpb.Repo) (bool, error) { os.Chdir(repo.FullPath) file := "go.mod" @@ -44,7 +44,7 @@ func repoOwnsGoMod(repo *gitpb.Repo) (bool, error) { if tracked { fmt.Printf("%s %s is tracked by Git.\n", repo.GoPath, file) - return true, nil + return false, nil } ignored, err := isIgnored(file) @@ -42,7 +42,7 @@ func main() { } } else { // figure out what directory we are running in - check := findPwdRepo() + check = findPwdRepo() if check == nil { log.Info("this directory isn't in a golang project (not in ~/go/src nor a go.work file)") os.Exit(-1) @@ -103,13 +103,11 @@ func doMain(repo *gitpb.Repo) error { } else { log.Info(repo.GoPath, "is valid according to forge") } - if err := repo.ValidGoSum(); err == nil { - log.Info(repo.GoPath, "go.mod and go.sum are already valid") - return nil - } // skip restore if --force if !argv.Force { + // erase the go.mod and go.sum files + eraseGoMod(repo) cname := repo.GetCurrentBranchName() // try to restore from the git metadata if err := repo.AutogenRestore(cname); err != nil { @@ -122,6 +120,12 @@ func doMain(repo *gitpb.Repo) error { } } + // double check here. use --force to remake them + if err := repo.ValidGoSum(); err == nil { + log.Info(repo.GoPath, "go.mod and go.sum are already valid") + return nil + } + if repo.GetMasterBranchName() != repo.GetCurrentBranchName() { log.Info("") log.Info("You can only run go-mod-clean on a git master branch.") @@ -131,19 +135,22 @@ func doMain(repo *gitpb.Repo) error { return errors.New(repo.GoPath + " not in the git master branch") } - ok, err := repoOwnsGoMod(repo) + ok, err := repoIgnoresGoMod(repo) if err != nil { + log.Info(repo.GoPath, "some wierd git error happened. investigate.", err) return err } // if ok, then git owns 'go.mod' and we can't really do anything // todo: ignore this with --force if ok { - return nil + log.Info(repo.GoPath, "git says it does not own go.mod") + // continue and attempt to create go.mod and go.sum } else { if forge.Config.IsReadOnly(repo.GoPath) { log.Info("skipping read only", repo.GoPath) return nil } + // continue and attempt to create go.mod and go.sum } if repo.CheckDirty() { @@ -153,7 +160,9 @@ func doMain(repo *gitpb.Repo) error { return errors.New(repo.GoPath + " git repo is dirty") } - // re-create go.sum and go.mod + log.Info(repo.GoPath, "GOING TO MAKE NEW go.* FILES") + + // actually will re-create go.sum and go.mod now if err := redoGoMod(repo); err != nil { return err } |
