// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 package main import ( "errors" "go.wit.com/log" ) func doDefaultBehavior() (string, error) { log.Info("forge is in mode", me.forge.GetMode()) if me.forge.IsModeUnknown() { panic("forge is UNKNOWN. this should have never happened") } // DEFAULT BEHAVIOR CHANGES BETWEEN MODES if me.forge.IsModeNormal() || me.forge.IsModeUser() { // PROBABLY YOU ARE WRITING CODE // got to the end with nothing to do (?) found := findWorkRepos() if found.Len() == 0 { return "you have no repos with patches (list them all with --show)", nil } found.SortNamespace() // footer := fmt.Sprintf("findWorkRepos() found %d", found.Len()) // return "doDefaultBehavior() :" + footer, nil footer := me.forge.PrintDefaultTB(found) return "repos with unsaved changes: (list them all with --show) " + footer, nil } if me.forge.IsModeMaster() { // PROBABLY YOU ARE PUBLISHING / MERGING CODE err := defaultBehaviorMaster() if err != nil { return "has problems", err } return "default master behavior is ok", nil } // PROBABLY A NEW USER found := findAll() footer := me.forge.PrintDefaultTB(found) return "new user: " + footer, nil } func defaultBehaviorMaster() error { var reallybad bool // 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 := cloneReposWithPatches() if found.Len() == 0 { log.Info("you currently have no repos with patches") return nil } footer := found.PrintDefaultTB() log.Info("default master table", footer) // warn about dirty repos not in master branches for repo := range found.IterAll() { if repo.CheckDirty() { if repo.GetCurrentBranchName() != repo.GetUserBranchName() { repo.State = "NOT USER" reallybad = true } // return log.Errorf("%s repo is dirty", repo.FullPath) } } if reallybad { return errors.New("\nYOU ARE MAKING EDITS ON NON USER BRANCHES\n") } return nil } /* func defaultBehavior() 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") } // check if any are dirty for repo := range found.IterAll() { if repo.CheckDirty() { return log.Errorf("%s repo is dirty", repo.FullPath) } } // check the hashes for repo := range found.IterAll() { if err := hashesMatch(repo); err != nil { return err } } // move them all the the master branch var bad bool for repo := range found.IterAll() { if repo.GetCurrentBranchName() != repo.GetMasterBranchName() { repo.CheckoutMaster() bad = true } } if bad { return log.Errorf("some repos had to be switched to the master branch") } if !argv.Force { return log.Errorf("notsure. it might be safe to publish(?)") } return nil } */