summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go45
1 files changed, 28 insertions, 17 deletions
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!