summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-14 18:45:29 -0600
committerJeff Carr <[email protected]>2024-12-14 18:45:29 -0600
commitf43311c36c178ec0509846eda92b810f7e38799e (patch)
tree69d37bbef61220a2047f091159fa37820a249596
parenta8f7adee19c9087bf3434f7d4d6a4d205c7a1a42 (diff)
add --strict for release management purposesv0.0.6
-rw-r--r--argv.go2
-rw-r--r--exit.go3
-rw-r--r--main.go45
3 files changed, 31 insertions, 19 deletions
diff --git a/argv.go b/argv.go
index 71ae968..571c26f 100644
--- a/argv.go
+++ b/argv.go
@@ -14,7 +14,7 @@ type args struct {
Notes bool `arg:"--metadata" help:"save as git metadata (notes)"`
Restore bool `arg:"--restore" default:"true" help:"restore from git metadata"`
Force bool `arg:"--force" help:"remove the old one"`
- Pure bool `arg:"--pure" default:"false" help:"never leave go.* files unless things are perfect"`
+ Strict bool `arg:"--strict" default:"false" help:"never make go.* files unless everything is perfect"`
}
func (args) Version() string {
diff --git a/exit.go b/exit.go
index 0f34ce3..81224c3 100644
--- a/exit.go
+++ b/exit.go
@@ -18,7 +18,8 @@ func badExit(check *gitpb.Repo, err error) {
log.DaemonMode(true)
log.Info("go-mod-clean failed: ", err, forge.GetGoSrc())
if check != nil {
- if argv.Pure {
+ if argv.Strict {
+ // if in strict mode, remove the go.mod and go.sum
eraseGoMod(check)
}
}
diff --git a/main.go b/main.go
index bac1afb..61bf9b2 100644
--- a/main.go
+++ b/main.go
@@ -94,6 +94,7 @@ func saveAsMetadata(repo *gitpb.Repo) error {
}
func doMain(repo *gitpb.Repo) error {
+ var perfect bool = true
if !repo.IsValid() {
log.Info(repo.GoPath, "is invalid. fix your repos.pb file with 'forge' first")
log.Info("")
@@ -127,12 +128,14 @@ func doMain(repo *gitpb.Repo) error {
}
if repo.GetMasterBranchName() != repo.GetCurrentBranchName() {
- log.Info("")
- log.Info("You can only run go-mod-clean on a git master branch.")
- log.Info("Publishing go.mod & go.sum files must come from from git version tag")
- log.Info("Anything else doesn't make sense.")
- log.Info("")
- return errors.New(repo.GoPath + " not in the git master branch")
+ perfect = false
+ if argv.Strict {
+ log.Info("")
+ log.Info("You are not operating on your git master branch.")
+ log.Info("Publishing go.mod & go.sum files must come from from git version tag on the master branch")
+ log.Info("")
+ return errors.New(repo.GoPath + " not in the git master branch")
+ }
}
ok, err := repoIgnoresGoMod(repo)
@@ -147,17 +150,22 @@ func doMain(repo *gitpb.Repo) error {
// continue and attempt to create go.mod and go.sum
} else {
if forge.Config.IsReadOnly(repo.GoPath) {
- log.Info("skipping read only", repo.GoPath)
+ log.Info("you can not push to read only repositories.", repo.GoPath)
+ log.Info("change your .config/forge/ to indicate you own this repository")
return nil
}
+ perfect = false
// continue and attempt to create go.mod and go.sum
}
if repo.CheckDirty() {
- log.Info("")
- log.Info("You can not run this on dirty branches.")
- log.Info("")
- return errors.New(repo.GoPath + " git repo is dirty")
+ perfect = false
+ if argv.Strict {
+ log.Info("")
+ log.Info("You can not continue on a dirty git repo.")
+ log.Info("")
+ return errors.New(repo.GoPath + " git repo is dirty")
+ }
}
log.Info(repo.GoPath, "GOING TO MAKE NEW go.* FILES")
@@ -190,12 +198,15 @@ func doMain(repo *gitpb.Repo) error {
return err
}
- // put the files in the notes section in git
- // this way, git commits are not messed up
- // with this autogenerated code
- if err := saveAsMetadata(repo); err != nil {
- log.Info("save go.mod as git metadata failed", repo.GoPath, err)
- return err
+ // if everything is perfect, save them as git metadata
+ if perfect {
+ // put the files in the notes section in git
+ // this way, git commits are not messed up
+ // with this autogenerated code
+ if err := saveAsMetadata(repo); err != nil {
+ log.Info("save go.mod as git metadata failed", repo.GoPath, err)
+ return err
+ }
}
// everything worked!