2025-02-21 09:13:54 -06:00
|
|
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by the GPL 3.0
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2025-02-21 10:21:13 -06:00
|
|
|
"fmt"
|
2025-02-22 03:40:37 -06:00
|
|
|
"os"
|
2025-02-21 09:13:54 -06:00
|
|
|
"sync"
|
|
|
|
|
|
|
|
"go.wit.com/lib/gadgets"
|
|
|
|
"go.wit.com/lib/protobuf/forgepb"
|
2025-02-21 09:33:45 -06:00
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
2025-02-21 09:13:54 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
|
|
|
|
"go.wit.com/gui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type repoProblemsWindow struct {
|
|
|
|
once sync.Once // only init() the window once
|
|
|
|
win *gadgets.BasicWindow // the patches window
|
|
|
|
stack *gui.Node // the top box set as vertical
|
|
|
|
shelf *gui.Node // the first box in the stack, set as horizontal
|
|
|
|
grid *gui.Node // the list of available patches
|
|
|
|
// summary *patchSummary // summary of current patches
|
|
|
|
setgrid *gui.Node // the list of each patchset
|
|
|
|
pset *forgepb.Patchset // the patchset in question
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: autogenerate these or make them standared 'gui' package functions
|
|
|
|
// make this an go interface somehow
|
|
|
|
|
|
|
|
// is the window hidden right now?
|
|
|
|
func (w *repoProblemsWindow) Hidden() bool {
|
|
|
|
return w.win.Hidden()
|
|
|
|
}
|
|
|
|
|
|
|
|
// switches between the window being visable or hidden on the desktop
|
|
|
|
func (w *repoProblemsWindow) Toggle() {
|
|
|
|
if w.Hidden() {
|
|
|
|
w.Show()
|
|
|
|
} else {
|
|
|
|
w.Hide()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// hides the window completely
|
|
|
|
func (w *repoProblemsWindow) Show() {
|
|
|
|
w.win.Show()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *repoProblemsWindow) Hide() {
|
|
|
|
w.win.Hide()
|
|
|
|
}
|
|
|
|
|
|
|
|
// should be the first box/widget in the window
|
|
|
|
// greys out the window to the user
|
|
|
|
func (w *repoProblemsWindow) Disable() {
|
|
|
|
w.stack.Disable()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *repoProblemsWindow) Enable() {
|
|
|
|
w.stack.Enable()
|
|
|
|
}
|
|
|
|
|
|
|
|
// you can only have one of these
|
|
|
|
func makeRepoProblemsWindow() *repoProblemsWindow {
|
|
|
|
pw := new(repoProblemsWindow)
|
|
|
|
|
|
|
|
// sync.Once()
|
|
|
|
pw.win = gadgets.RawBasicWindow("Potential Repo Problems")
|
|
|
|
pw.win.Make()
|
2025-02-21 15:37:28 -06:00
|
|
|
pw.win.Show()
|
2025-02-21 09:13:54 -06:00
|
|
|
|
|
|
|
pw.stack = pw.win.Box().NewBox("bw vbox", false)
|
|
|
|
pw.win.Custom = func() {
|
|
|
|
// sets the hidden flag to false so Toggle() works
|
|
|
|
pw.win.Hide()
|
|
|
|
}
|
2025-02-21 09:33:45 -06:00
|
|
|
pw.stack.NewGroup("things (these don't work yet)")
|
2025-02-21 09:13:54 -06:00
|
|
|
|
|
|
|
grid := pw.stack.RawGrid()
|
2025-02-21 10:21:13 -06:00
|
|
|
var found *gitpb.Repos
|
|
|
|
var txt string
|
|
|
|
|
2025-02-21 10:30:55 -06:00
|
|
|
found = develBehindMasterProblem()
|
|
|
|
txt = fmt.Sprintf("devel is behind master (%d)", found.Len())
|
|
|
|
grid.NewButton(txt, func() {
|
2025-02-21 16:10:33 -06:00
|
|
|
win := gadgets.RawBasicWindow("devel branches that are out of sync with master")
|
2025-02-21 15:37:28 -06:00
|
|
|
win.Make()
|
|
|
|
win.Show()
|
|
|
|
win.Custom = func() {
|
|
|
|
// sets the hidden flag to false so Toggle() works
|
|
|
|
win.Hide()
|
|
|
|
}
|
2025-02-21 16:10:33 -06:00
|
|
|
box := win.Box().NewBox("bw vbox", false)
|
2025-02-21 15:37:28 -06:00
|
|
|
|
2025-02-21 16:10:33 -06:00
|
|
|
found := develBehindMasterProblem()
|
|
|
|
group := box.NewGroup("test buttons")
|
2025-02-22 03:40:37 -06:00
|
|
|
hbox := group.Box().Horizontal()
|
|
|
|
hbox.NewButton("git merge master devel", func() {
|
|
|
|
all := found.SortByFullPath()
|
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
|
|
|
mname := repo.GetMasterBranchName()
|
|
|
|
dname := repo.GetDevelBranchName()
|
2025-02-22 04:46:45 -06:00
|
|
|
if dname != repo.GetCurrentBranchName() {
|
|
|
|
log.Info("Repo is not on the devel branch", repo.GetGoPath())
|
|
|
|
}
|
|
|
|
cmd := []string{"git", "merge", mname}
|
2025-02-22 03:40:37 -06:00
|
|
|
log.Info(repo.GetGoPath(), cmd)
|
2025-02-22 04:46:45 -06:00
|
|
|
repo.RunVerbose(cmd)
|
2025-02-22 03:40:37 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
hbox.NewButton("test", func() {
|
2025-02-21 15:37:28 -06:00
|
|
|
})
|
|
|
|
|
2025-02-21 16:10:33 -06:00
|
|
|
t := makeStandardReposGrid(found)
|
|
|
|
t.SetParent(box)
|
|
|
|
t.ShowTable()
|
2025-02-21 10:30:55 -06:00
|
|
|
})
|
|
|
|
|
2025-02-21 10:21:13 -06:00
|
|
|
found = remoteUserBranchProblem()
|
|
|
|
txt = fmt.Sprintf("user branch is remote (%d)", found.Len())
|
|
|
|
grid.NewButton(txt, func() {
|
2025-02-21 16:10:33 -06:00
|
|
|
win := gadgets.RawBasicWindow("repos that seem to have remote 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)
|
|
|
|
|
2025-02-21 10:21:13 -06:00
|
|
|
found := remoteUserBranchProblem()
|
2025-02-21 16:10:33 -06:00
|
|
|
group := box.NewGroup("test buttons")
|
2025-02-22 03:40:37 -06:00
|
|
|
hbox := group.Box().Horizontal()
|
|
|
|
hbox.NewButton("git branch delete", func() {
|
2025-02-21 16:35:21 -06:00
|
|
|
win.Disable()
|
|
|
|
defer win.Enable()
|
2025-02-21 16:10:33 -06:00
|
|
|
all := found.SortByFullPath()
|
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
2025-02-21 16:35:21 -06:00
|
|
|
brname := repo.GetUserBranchName()
|
|
|
|
// git push origin --delete jcarr
|
2025-02-22 03:40:37 -06:00
|
|
|
os.Setenv("GIT_TERMINAL_PROMPT", "0")
|
2025-02-21 16:35:21 -06:00
|
|
|
cmd := []string{"git", "push", "origin", "--delete", brname}
|
2025-02-22 03:40:37 -06:00
|
|
|
log.Info("You may want to run:", repo.GetGoPath(), cmd)
|
2025-02-21 16:35:21 -06:00
|
|
|
repo.RunVerbose(cmd)
|
2025-02-22 03:40:37 -06:00
|
|
|
os.Unsetenv("GIT_TERMINAL_PROMPT")
|
2025-02-21 16:35:21 -06:00
|
|
|
|
|
|
|
// git branch --delete --remote origin/jcarr
|
|
|
|
cmd = []string{"git", "branch", "--delete", "--remote", "origin/" + brname}
|
|
|
|
log.Info(repo.GetGoPath(), cmd)
|
|
|
|
repo.RunVerbose(cmd)
|
2025-02-21 16:55:17 -06:00
|
|
|
repo.Reload()
|
2025-02-21 16:10:33 -06:00
|
|
|
}
|
2025-02-21 16:55:17 -06:00
|
|
|
me.forge.SetConfigSave(true)
|
|
|
|
me.forge.ConfigSave()
|
2025-02-21 16:10:33 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
t := makeStandardReposGrid(found)
|
|
|
|
t.SetParent(box)
|
|
|
|
t.ShowTable()
|
2025-02-21 09:13:54 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
grid.NewButton("unknown branches", func() {
|
|
|
|
log.Info("not done yet")
|
|
|
|
})
|
|
|
|
grid.NextRow()
|
|
|
|
|
2025-02-21 10:21:13 -06:00
|
|
|
found = develRemoteProblem()
|
|
|
|
txt = fmt.Sprintf("remote devel != local devel (%d)", found.Len())
|
|
|
|
grid.NewButton(txt, func() {
|
|
|
|
found := develRemoteProblem()
|
2025-02-21 16:35:21 -06:00
|
|
|
makeStandardReposWindow(txt, found)
|
2025-02-21 09:13:54 -06:00
|
|
|
})
|
|
|
|
|
2025-02-21 10:21:13 -06:00
|
|
|
found = masterRemoteProblem()
|
|
|
|
txt = fmt.Sprintf("remote master != local master (%d)", found.Len())
|
|
|
|
grid.NewButton(txt, func() {
|
|
|
|
found := masterRemoteProblem()
|
2025-02-21 16:35:21 -06:00
|
|
|
makeStandardReposWindow(txt, found)
|
2025-02-21 09:13:54 -06:00
|
|
|
})
|
|
|
|
grid.NextRow()
|
|
|
|
|
|
|
|
return pw
|
|
|
|
}
|
2025-02-21 10:21:13 -06:00
|
|
|
|
2025-02-21 10:30:55 -06:00
|
|
|
func develBehindMasterProblem() *gitpb.Repos {
|
|
|
|
log.Info("not done yet")
|
|
|
|
found := new(gitpb.Repos)
|
|
|
|
all := me.forge.Repos.SortByFullPath()
|
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
|
|
|
if repo.GetDevelVersion() == repo.GetMasterVersion() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
found.AppendByGoPath(repo)
|
|
|
|
|
|
|
|
}
|
|
|
|
return found
|
|
|
|
}
|
|
|
|
|
2025-02-21 10:21:13 -06:00
|
|
|
func remoteUserBranchProblem() *gitpb.Repos {
|
|
|
|
found := new(gitpb.Repos)
|
|
|
|
all := me.forge.Repos.SortByFullPath()
|
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
|
|
|
username := repo.GetUserBranchName()
|
|
|
|
if repo.IsBranchRemote(username) {
|
|
|
|
found.AppendByGoPath(repo)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return found
|
|
|
|
}
|
|
|
|
|
|
|
|
func develRemoteProblem() *gitpb.Repos {
|
|
|
|
found := new(gitpb.Repos)
|
|
|
|
all := me.forge.Repos.SortByFullPath()
|
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
|
|
|
brname := repo.GetDevelBranchName()
|
|
|
|
if !repo.IsBranchRemote(brname) {
|
|
|
|
// log.Info("repo does not have remote devel branch", repo.GetGoPath())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
lhash := repo.GetLocalHash(brname)
|
|
|
|
rhash := repo.GetRemoteHash(brname)
|
|
|
|
// log.Info(lhash, rhash, repo.GetGoPath())
|
|
|
|
if lhash == "" || rhash == "" {
|
|
|
|
// something is wrong if either of these are blank
|
|
|
|
found.AppendByGoPath(repo)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if lhash == rhash {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
found.AppendByGoPath(repo)
|
|
|
|
|
|
|
|
}
|
|
|
|
return found
|
|
|
|
}
|
|
|
|
|
|
|
|
func masterRemoteProblem() *gitpb.Repos {
|
|
|
|
found := new(gitpb.Repos)
|
|
|
|
all := me.forge.Repos.SortByFullPath()
|
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
|
|
|
brname := repo.GetMasterBranchName()
|
|
|
|
if !repo.IsBranchRemote(brname) {
|
|
|
|
// log.Info("repo does not have remote devel branch", repo.GetGoPath())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
lhash := repo.GetLocalHash(brname)
|
|
|
|
rhash := repo.GetRemoteHash(brname)
|
|
|
|
// log.Info(lhash, rhash, repo.GetGoPath())
|
|
|
|
if lhash == "" || rhash == "" {
|
|
|
|
// something is wrong if either of these are blank
|
|
|
|
found.AppendByGoPath(repo)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if lhash == rhash {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
found.AppendByGoPath(repo)
|
|
|
|
|
|
|
|
}
|
|
|
|
return found
|
|
|
|
}
|