// 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/lib/gadgets" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) // An app to submit patches for the 30 GO GUI repos func makeModeMasterWin() *gadgets.GenericWindow { win := gadgets.NewGenericWindow("Release", "tools") grid := win.Group.RawGrid() checkout := grid.NewButton("git checkout master", func() { win.Disable() defer win.Enable() }) gitpull := grid.NewButton("git pull", func() { win.Disable() defer win.Enable() }) grid.NextRow() cleanUser := grid.NewButton("Clean user branches", func() { win.Disable() defer win.Enable() if err := doCleanUser(); err != nil { log.Info("Clean user branches failed", err) } }) cleanDevel := grid.NewButton("Clean devel branches", func() { win.Disable() defer win.Enable() if err := doCleanDevel(); err != nil { log.Info("Clean devel branches failed", err) } }) grid.NextRow() f := func() { total, count, nope, err := IsEverythingOnMaster() if nope == 0 { checkout.Disable() gitpull.Enable() } else { log.Printf("Master branch check. %d total repos. (%d ok) (%d not on master branch) err=%v\n", total, count, nope, err) checkout.Enable() } var localuser bool // are there still local user branches var localdevel bool // are there still local devel branches all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() if repo.IsLocalBranch(repo.GetUserBranchName()) { localuser = true } if repo.IsLocalBranch(repo.GetDevelBranchName()) { localdevel = true } } if localuser { cleanUser.Enable() } else { cleanUser.Disable() } if localdevel { cleanDevel.Enable() } else { cleanDevel.Disable() } } grid.NewButton("check repo state", func() { win.Disable() defer win.Enable() f() }) grid.NewButton("reset user branches (?)", func() { resetUserBranchesWindow() }) return win } func resetUserBranchesWindow() { found := gitpb.NewRepos() all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() uname := repo.GetUserBranchName() dname := repo.GetDevelBranchName() if repo.GetCurrentBranchName() == uname { log.Info("Repo is on the user branch. Can't delete it.", repo.GetGoPath()) continue } b1 := repo.CountDiffObjects(uname, dname) b2 := repo.CountDiffObjects(dname, uname) log.Info("user vs devel count", b1, b2) if b1 == 0 && b2 == 0 { cmd := []string{"git", "branch", "-D", uname} log.Info(repo.GetGoPath(), cmd) repo.RunVerbose(cmd) repo.Reload() continue } found.Append(repo) } win := gadgets.RawBasicWindow("reset user branches") win.Make() win.Show() win.Custom = func() { // sets the hidden flag to false so Toggle() works win.Hide() } box := win.Box().NewBox("bw vbox", false) group := box.NewGroup("test buttons") hbox := group.Box().Horizontal() hbox.NewButton("force delete user branch", func() { win.Disable() defer win.Enable() all := found.SortByFullPath() for all.Scan() { repo := all.Next() brname := repo.GetUserBranchName() cmd := []string{"git", "branch", "-D", brname} log.Info(repo.GetGoPath(), cmd) repo.RunVerbose(cmd) repo.Reload() } me.forge.SetConfigSave(true) me.forge.ConfigSave() }) t := makeStandardReposGrid(found) t.SetParent(box) t.ShowTable() }