From 2f925f6215c1feb8093a6c1811c85fa9a611ee91 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 4 Oct 2025 16:19:44 -0500 Subject: start default behavior functions --- defaultBehavior.go | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 defaultBehavior.go (limited to 'defaultBehavior.go') diff --git a/defaultBehavior.go b/defaultBehavior.go new file mode 100644 index 0000000..c215aa2 --- /dev/null +++ b/defaultBehavior.go @@ -0,0 +1,72 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "go.wit.com/log" +) + +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 +} + +func defaultBehaviorMaster() 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 nil + } + // warn about dirty repos not in master branches + for repo := range found.IterAll() { + if repo.CheckDirty() { + if repo.GetCurrentBranchName() != repo.GetUserBranchName() { + repo.State = "DIRTY REPO NOT IN USER BRANCH" + } + // return log.Errorf("%s repo is dirty", repo.FullPath) + } + } + me.forge.PrintDefaultTB(found) + return nil +} -- cgit v1.2.3