add --strict for release management purposes
This commit is contained in:
parent
a8f7adee19
commit
f43311c36c
2
argv.go
2
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 {
|
||||
|
|
3
exit.go
3
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)
|
||||
}
|
||||
}
|
||||
|
|
45
main.go
45
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!
|
||||
|
|
Loading…
Reference in New Issue