diff options
| -rw-r--r-- | argv.go | 1 | ||||
| -rw-r--r-- | doMerge.go | 49 | ||||
| -rw-r--r-- | exit.go | 9 | ||||
| -rw-r--r-- | main.go | 4 | ||||
| -rw-r--r-- | structs.go | 2 |
5 files changed, 61 insertions, 4 deletions
@@ -139,6 +139,7 @@ type MergeCmd struct { Devel *EmptyCmd `arg:"subcommand:devel" help:"merge user to devel"` Master *EmptyCmd `arg:"subcommand:master" help:"merge devel to master"` Publish *EmptyCmd `arg:"subcommand:publish" help:"increment versions and publish master branch"` + Check *EmptyCmd `arg:"subcommand:check" help:"check if merge is complete and ready to publish"` } type ConfigCmd struct { @@ -52,6 +52,12 @@ func doMerge() error { log.Printf("Merged %d master branches in %s\n", repos.Len(), shell.FormatDuration(dur)) okExit("") } + if argv.Merge.Check != nil { + if err := safeToPublish(); err != nil { + me.sh.BadExit("Merge is not complete. Not safe to Publish.", err) + } + okExit("") + } if showWorkRepos() { // found some repos at least } else { @@ -63,6 +69,49 @@ func doMerge() error { return nil } +func hashesMatch(repo *gitpb.Repo) error { + uhash := repo.ActualGetUserHash() + dhash := repo.ActualGetDevelHash() + mhashl, mhashr := repo.ActualGetMasterHash() + // log.Info(uhash, dhash, mhashl, mhashr) + if uhash != dhash { + return log.Errorf("user does not match devel") + } + if dhash != mhashl { + return log.Errorf("devel does not match mater") + } + if mhashl != mhashr { + return log.Errorf("local master branch does not match remote branch") + } + return nil +} + +func safeToPublish() error { + // always run dirty first + me.forge.CheckDirtyQuiet() + + // if no option is given to patch, list out the + // repos that have patches ready in them + found := findReposWithPatches() + if found.Len() == 0 { + log.Info("you currently have no repos with patches") + return log.Errorf("no repos to publish") + } + for repo := range found.IterAll() { + if err := hashesMatch(repo); err != nil { + return err + } + if repo.CheckDirty() { + return log.Errorf("%s repo is dirty", repo.FullPath) + } + if repo.GetCurrentBranchName() != repo.GetMasterBranchName() { + return log.Errorf("%s repo is not on master branch", repo.FullPath) + } + return log.Errorf("%s todo: check if repo is completely merged", repo.FullPath) + } + return log.Errorf("notsure") +} + func doMergeReport() *forgepb.Patches { found := forgepb.NewPatches() for repo := range me.forge.Repos.IterAll() { @@ -23,7 +23,14 @@ func okExit(thing string) { } func badExit(err error) { - log.Info("forge failed: ", err, me.forge.Config.ReposDir) + log.Info(err) + log.Info("forge failed") + os.Exit(-1) +} + +func newBadExit(msg string, err error) { + log.Info(err) + log.Info(msg) os.Exit(-1) } @@ -43,8 +43,8 @@ func main() { me = new(mainType) // the current os.Argv processing with go-args - me.myGui = prep.Gui() // adds the GUI package args support - me.auto = prep.Bash(&argv) // adds auto complete to go-args + me.myGui = prep.Gui() // adds the GUI package args support + me.sh = prep.Bash(&argv) // adds shell auto complete to go-args // the current forge init process me.forge = forgepb.Init() // init forge.pb @@ -28,7 +28,7 @@ func myServer() string { // this app's variables type mainType struct { // pp *arg.Parser // for parsing the command line args. Yay to alexflint! - auto *prep.Auto // more experiments for bash handling + sh *prep.Auto // shell autocomplete forge *forgepb.Forge // for holding the forge protobuf files myGui *prep.GuiPrep // for initializing the GUI toolkits foundPaths []string // stores gopaths to act on (when doing go-clone) |
