2024-01-09 01:16:00 -06:00
|
|
|
package main
|
|
|
|
|
2024-02-21 08:32:59 -06:00
|
|
|
// An app to submit patches for the 30 GO GUI repos
|
2024-01-09 10:21:58 -06:00
|
|
|
|
2024-02-21 08:32:59 -06:00
|
|
|
import (
|
2025-01-06 15:44:56 -06:00
|
|
|
"os"
|
2024-12-14 13:12:42 -06:00
|
|
|
"strings"
|
2024-12-02 06:59:56 -06:00
|
|
|
|
|
|
|
"go.wit.com/dev/alexflint/arg"
|
2024-12-24 02:26:54 -06:00
|
|
|
"go.wit.com/gui"
|
2025-01-11 07:45:16 -06:00
|
|
|
"go.wit.com/lib/gui/shell"
|
2024-12-02 06:59:56 -06:00
|
|
|
"go.wit.com/lib/protobuf/forgepb"
|
2024-12-05 12:29:47 -06:00
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
2024-01-09 02:00:51 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-09 01:16:00 -06:00
|
|
|
)
|
|
|
|
|
2024-12-02 06:59:56 -06:00
|
|
|
// sent via -ldflags
|
|
|
|
var VERSION string
|
|
|
|
var BUILDTIME string
|
|
|
|
|
2025-01-07 17:16:03 -06:00
|
|
|
// used for shell auto completion
|
|
|
|
var ARGNAME string = "forge"
|
|
|
|
|
2024-12-13 16:17:36 -06:00
|
|
|
// using this for now. triggers config save
|
|
|
|
var configSave bool
|
|
|
|
|
2024-12-17 06:36:00 -06:00
|
|
|
func getVersion(repo *gitpb.Repo, name string) string {
|
|
|
|
cmd := []string{"git", "describe", "--tags", "--always", name}
|
|
|
|
result := repo.RunQuiet(cmd)
|
|
|
|
output := strings.Join(result.Stdout, "\n")
|
|
|
|
log.Info("cmd =", cmd, output)
|
|
|
|
|
|
|
|
return strings.TrimSpace(output)
|
|
|
|
}
|
|
|
|
|
2024-01-09 01:16:00 -06:00
|
|
|
func main() {
|
2024-02-21 08:32:59 -06:00
|
|
|
me = new(mainType)
|
2024-12-02 06:59:56 -06:00
|
|
|
me.pp = arg.MustParse(&argv)
|
2025-01-06 15:44:56 -06:00
|
|
|
|
|
|
|
if argv.Bash {
|
|
|
|
argv.doBash()
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
if len(argv.BashAuto) != 0 {
|
|
|
|
argv.doBashAuto()
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2024-12-14 13:12:42 -06:00
|
|
|
me.urlbase = argv.URL
|
2024-12-24 03:35:19 -06:00
|
|
|
if me.urlbase == "" {
|
|
|
|
me.urlbase = "https://go.wit.com/"
|
|
|
|
}
|
2024-12-14 13:12:42 -06:00
|
|
|
me.urlbase = strings.Trim(me.urlbase, "/") // track down why trailing '/' makes http POST not work
|
2024-12-02 06:59:56 -06:00
|
|
|
|
|
|
|
// load the ~/.config/forge/ config
|
|
|
|
me.forge = forgepb.Init()
|
2024-12-05 12:29:47 -06:00
|
|
|
me.found = new(gitpb.Repos)
|
2024-01-18 05:03:04 -06:00
|
|
|
|
2025-01-06 20:57:52 -06:00
|
|
|
// first find the repos or gopaths to operate on
|
|
|
|
if argv.Config != nil {
|
|
|
|
doConfig()
|
|
|
|
okExit("")
|
|
|
|
}
|
|
|
|
|
2025-01-11 07:45:16 -06:00
|
|
|
if argv.Commit != nil {
|
|
|
|
pwd, _ := os.Getwd()
|
|
|
|
repo := me.forge.Repos.FindByFullPath(pwd)
|
|
|
|
if repo == nil {
|
|
|
|
log.Info("what branch are you on?: todo: examine this")
|
|
|
|
okExit("")
|
|
|
|
}
|
|
|
|
if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
|
|
|
|
me.found.Append(repo)
|
|
|
|
me.forge.PrintHumanTable(me.found)
|
|
|
|
log.Info("")
|
|
|
|
log.Info("wrong branch. Can not commit on", repo.GetCurrentBranchName())
|
|
|
|
log.Info("")
|
|
|
|
okExit("")
|
|
|
|
}
|
2025-01-11 09:11:30 -06:00
|
|
|
os.Setenv("LESS", "-XR")
|
2025-01-11 08:14:45 -06:00
|
|
|
if err := shell.Exec([]string{"git", "diff"}); err != nil {
|
|
|
|
badExit(err)
|
|
|
|
}
|
|
|
|
if err := shell.ExecCheck([]string{"git", "commit", "--all"}); err != nil {
|
|
|
|
badExit(err)
|
|
|
|
}
|
|
|
|
log.Info("git commit ok. forge done")
|
|
|
|
okExit("")
|
2025-01-11 07:45:16 -06:00
|
|
|
}
|
|
|
|
|
2025-01-06 16:53:13 -06:00
|
|
|
if argv.Checkout != nil {
|
|
|
|
if argv.Checkout.User != nil {
|
2025-01-07 20:28:40 -06:00
|
|
|
if argv.Force {
|
|
|
|
me.forge.CheckoutUserForce()
|
|
|
|
} else {
|
|
|
|
me.forge.CheckoutUser()
|
|
|
|
}
|
2025-01-06 16:53:13 -06:00
|
|
|
me.forge = forgepb.Init()
|
|
|
|
me.found = new(gitpb.Repos)
|
|
|
|
argv.Checkout.User.findRepos()
|
2025-01-08 00:51:53 -06:00
|
|
|
me.forge.PrintHumanTable(me.found)
|
2025-01-06 16:53:13 -06:00
|
|
|
okExit("")
|
|
|
|
}
|
2024-12-23 02:37:48 -06:00
|
|
|
|
2025-01-06 16:53:13 -06:00
|
|
|
if argv.Checkout.Devel != nil {
|
|
|
|
me.forge.CheckoutDevel()
|
|
|
|
me.forge = forgepb.Init()
|
|
|
|
me.found = new(gitpb.Repos)
|
|
|
|
argv.Checkout.Devel.findRepos()
|
2025-01-08 00:51:53 -06:00
|
|
|
me.forge.PrintHumanTable(me.found)
|
2025-01-06 16:53:13 -06:00
|
|
|
okExit("")
|
|
|
|
}
|
2024-12-27 03:39:53 -06:00
|
|
|
|
2025-01-06 16:53:13 -06:00
|
|
|
if argv.Checkout.Master != nil {
|
|
|
|
me.forge.CheckoutMaster()
|
|
|
|
me.forge = forgepb.Init()
|
|
|
|
me.found = new(gitpb.Repos)
|
|
|
|
argv.Checkout.Master.findRepos()
|
2025-01-08 00:51:53 -06:00
|
|
|
me.forge.PrintHumanTable(me.found)
|
2025-01-06 16:53:13 -06:00
|
|
|
}
|
2025-01-06 17:53:20 -06:00
|
|
|
log.Info("make 'user' the default here?")
|
|
|
|
okExit("")
|
2024-12-23 02:37:48 -06:00
|
|
|
}
|
|
|
|
|
2024-12-27 04:36:29 -06:00
|
|
|
if argv.Dirty != nil {
|
2025-01-05 01:18:47 -06:00
|
|
|
findAll() // select all the repos
|
2025-01-05 05:48:02 -06:00
|
|
|
doCheckDirtyAndConfigSave()
|
2025-01-05 01:18:47 -06:00
|
|
|
me.found = new(gitpb.Repos)
|
|
|
|
findDirty()
|
2025-01-08 00:51:53 -06:00
|
|
|
me.forge.PrintHumanTable(me.found)
|
2024-12-25 23:17:24 -06:00
|
|
|
okExit("")
|
|
|
|
}
|
2024-12-24 03:08:06 -06:00
|
|
|
|
2025-01-06 17:53:20 -06:00
|
|
|
if argv.Rescan != nil {
|
2025-01-05 01:18:47 -06:00
|
|
|
me.forge.ScanGoSrc()
|
2025-01-06 17:53:20 -06:00
|
|
|
okExit("")
|
2024-12-25 23:17:24 -06:00
|
|
|
}
|
2024-02-14 13:43:43 -06:00
|
|
|
|
2025-01-08 00:23:04 -06:00
|
|
|
if argv.Show != "" {
|
|
|
|
repo := me.forge.FindByGoPath(argv.Show)
|
2025-01-08 00:51:53 -06:00
|
|
|
me.forge.HumanPrintRepo(repo)
|
2025-01-08 02:40:06 -06:00
|
|
|
// newt := repo.Times.LastUpdate.AsTime()
|
|
|
|
// oldt := repo.Times.MtimeHead.AsTime()
|
|
|
|
if repo.Times.LastUpdate == nil {
|
|
|
|
log.Info("SHOULD RUN Reload() here")
|
|
|
|
repo.Reload()
|
|
|
|
me.forge.HumanPrintRepo(repo)
|
|
|
|
} else {
|
|
|
|
if repo.Times.LastUpdate.Seconds < repo.Times.MtimeHead.Seconds {
|
|
|
|
log.Info("SHOULD RUN Reload() here")
|
|
|
|
}
|
|
|
|
}
|
2025-01-08 00:23:04 -06:00
|
|
|
okExit("")
|
|
|
|
}
|
|
|
|
|
2024-12-27 03:39:53 -06:00
|
|
|
if argv.GitPull != nil {
|
|
|
|
argv.GitPull.findRepos()
|
2024-12-25 23:17:24 -06:00
|
|
|
doGitPull()
|
2025-01-06 17:53:20 -06:00
|
|
|
okExit("")
|
2024-12-25 23:17:24 -06:00
|
|
|
}
|
2024-12-05 14:17:50 -06:00
|
|
|
|
2025-01-06 17:53:20 -06:00
|
|
|
if argv.GitReset != nil {
|
2025-01-05 01:18:47 -06:00
|
|
|
findAll() // select all the repos
|
2024-12-25 23:17:24 -06:00
|
|
|
doGitReset()
|
2025-01-08 10:10:14 -06:00
|
|
|
okExit("reset")
|
2024-12-25 23:17:24 -06:00
|
|
|
}
|
2024-12-13 17:13:07 -06:00
|
|
|
|
2024-12-27 03:39:53 -06:00
|
|
|
if argv.List != nil {
|
|
|
|
argv.List.findRepos()
|
2024-12-25 23:17:24 -06:00
|
|
|
// print out the repos
|
2025-01-08 00:51:53 -06:00
|
|
|
me.forge.PrintHumanTable(me.found)
|
2025-01-08 10:10:14 -06:00
|
|
|
okExit("")
|
2024-12-13 13:17:26 -06:00
|
|
|
}
|
2025-01-06 17:53:20 -06:00
|
|
|
if argv.Patch != nil {
|
2025-01-06 18:14:33 -06:00
|
|
|
if argv.Patch.Show != nil {
|
|
|
|
sendDevelDiff("fixme")
|
2025-01-06 17:53:20 -06:00
|
|
|
// sendMasterDiff()
|
2025-01-08 10:10:14 -06:00
|
|
|
okExit("")
|
2025-01-06 17:53:20 -06:00
|
|
|
}
|
2024-12-13 13:17:26 -06:00
|
|
|
|
2025-01-06 18:14:33 -06:00
|
|
|
if argv.Patch.List != nil {
|
2025-01-06 17:53:20 -06:00
|
|
|
listPatches()
|
2025-01-08 10:10:14 -06:00
|
|
|
okExit("patch list")
|
2025-01-06 17:53:20 -06:00
|
|
|
}
|
2024-12-14 14:09:15 -06:00
|
|
|
}
|
|
|
|
|
2025-01-06 20:57:52 -06:00
|
|
|
// todo: redo this logic using forgepb
|
2024-12-24 03:08:06 -06:00
|
|
|
if configSave {
|
|
|
|
me.forge.ConfigSave()
|
|
|
|
configSave = false
|
|
|
|
}
|
|
|
|
|
2024-12-24 02:26:54 -06:00
|
|
|
// if the user doesn't want to open the GUI and
|
|
|
|
// nothing else was specified to be done,
|
|
|
|
// then just list the table to stdout
|
|
|
|
if gui.NoGui() {
|
2025-01-08 00:51:53 -06:00
|
|
|
me.forge.PrintHumanTable(me.found)
|
2025-01-06 17:53:20 -06:00
|
|
|
okExit("")
|
2024-12-05 12:29:47 -06:00
|
|
|
}
|
2025-01-06 17:53:20 -06:00
|
|
|
|
2024-12-27 03:39:53 -06:00
|
|
|
// open the gui unless the user performed some other
|
2025-01-06 17:53:20 -06:00
|
|
|
// basically, if you run just 'forge' it should open the GUI
|
2025-01-08 04:07:33 -06:00
|
|
|
|
|
|
|
// if opening the GUI, always check git for dirty repos
|
|
|
|
findAll() // select all the repos
|
|
|
|
doCheckDirtyAndConfigSave()
|
2025-01-06 17:53:20 -06:00
|
|
|
doGui()
|
2024-12-17 06:36:00 -06:00
|
|
|
okExit("")
|
2024-01-09 01:16:00 -06:00
|
|
|
}
|