repolist/addRepo.go

140 lines
3.4 KiB
Go
Raw Normal View History

2024-02-17 08:39:55 -06:00
package repolist
import (
"strings"
"go.wit.com/gui"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/log"
)
func (r *Repo) Hide() {
r.pLabel.Hide()
r.lastTag.Hide()
r.vLabel.Hide()
r.masterVersion.Hide()
r.develVersion.Hide()
r.userVersion.Hide()
r.dirtyLabel.Hide()
r.endBox.Hide()
// r.statusButton.Hide()
// r.diffButton.Hide()
r.hidden = true
}
func (r *Repo) Hidden() bool {
return r.hidden
}
func (r *Repo) Show() {
r.pLabel.Show()
r.lastTag.Show()
r.vLabel.Show()
r.masterVersion.Show()
r.develVersion.Show()
r.userVersion.Show()
r.dirtyLabel.Show()
r.endBox.Show()
// r.statusButton.Show()
// r.diffButton.Show()
r.hidden = false
}
func (r *RepoList) AddRepo(path string, master string, devel string, user string) *Repo {
return addRepo(r.reposgrid, path, master, devel, user)
}
func addRepo(grid *gui.Node, path string, master string, devel string, user string) *Repo {
_, ok := me.allrepos[path]
if ok {
log.Info("addRepo() already had path", path)
return nil
}
// log.Info("addRepo() attempting to add path", path)
rstatus := repostatus.NewRepoStatusWindow(path)
if rstatus == nil {
// log.Info("path isn't a repo I can figure out yet", path)
// probably this isn't downloaded
return nil
}
newRepo := new(Repo)
newRepo.status = rstatus
path = strings.TrimSuffix(path, "/") // trim any extranous '/' chars put in the config file by the user
if path == "" {
// just an empty line in the config file
return nil
}
newRepo.pLabel = grid.NewLabel(path).SetProgName("path")
newRepo.lastTag = grid.NewLabel("").SetProgName("lastTag")
newRepo.masterVersion = grid.NewLabel("").SetProgName("masterVersion")
newRepo.develVersion = grid.NewLabel("").SetProgName("develVersion")
newRepo.userVersion = grid.NewLabel("").SetProgName("userVersion")
newRepo.dirtyLabel = grid.NewLabel("")
newRepo.vLabel = grid.NewLabel("").SetProgName("current")
newRepo.endBox = grid.NewHorizontalBox("HBOX")
newRepo.endBox.NewButton("Configure", func() {
if newRepo.status == nil {
log.Warn("status window wasn't created")
return
}
newRepo.status.Toggle()
})
newRepo.endBox.NewButton("show diff", func() {
me.reposwin.Disable()
// newRepo.status.XtermNohup([]string{"git diff"})
newRepo.status.Xterm("git diff; bash")
me.reposwin.Enable()
})
newRepo.endBox.NewButton("commit all", func() {
me.reposwin.Disable()
// restore anything staged so everything can be reviewed
newRepo.status.RunCmd([]string{"git", "restore", "--staged", "."})
newRepo.status.XtermWait("git diff")
newRepo.status.XtermWait("git add --all")
newRepo.status.XtermWait("git commit -a")
newRepo.status.XtermWait("git push")
if newRepo.status.CheckDirty() {
// commit was not done, restore diff
newRepo.status.RunCmd([]string{"git", "restore", "--staged", "."})
} else {
newRepo.newScan()
}
me.reposwin.Enable()
})
newRepo.hidden = false
// newRepo.status.SetMainWorkingName(master)
// newRepo.status.SetDevelWorkingName(devel)
// newRepo.status.SetUserWorkingName(user)
var showBuildB bool = false
switch newRepo.status.RepoType() {
case "binary":
// log.Info("compile here. Show()")
showBuildB = true
case "library":
// log.Info("library here. Hide()")
default:
// log.Info("unknown RepoType", newRepo.status.RepoType())
}
if showBuildB {
newRepo.endBox.NewButton("build", func() {
newRepo.status.Build()
})
}
grid.NextRow()
me.allrepos[path] = newRepo
return newRepo
}