repolist/newRepo.go

142 lines
3.3 KiB
Go

package repolist
import (
"errors"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
func (r *RepoRow) Hidden() bool {
return r.hidden
}
func (r *RepoRow) Hide() {
r.pLabel.Hide()
r.lastTag.Hide()
r.currentName.Hide()
r.currentVersion.Hide()
r.masterVersion.Hide()
r.develVersion.Hide()
r.userVersion.Hide()
r.gitState.Hide()
r.endBox.Hide()
r.targetV.Hide()
r.hidden = true
}
func (r *RepoRow) Show() {
r.pLabel.Show()
r.lastTag.Show()
r.currentName.Show()
r.currentVersion.Show()
r.masterVersion.Show()
r.develVersion.Show()
r.userVersion.Show()
r.gitState.Show()
r.endBox.Show()
r.targetV.Show()
r.hidden = false
}
func (r *RepoRow) Show2() {
r.pLabel.Show()
r.lastTag.Show()
r.currentName.Show()
r.currentVersion.Show()
r.masterVersion.Show()
r.develVersion.Show()
r.userVersion.Show()
r.gitState.Show()
r.endBox.Show()
r.targetV.Show()
r.hidden = false
}
// adds a gui row to the table based off the repo protobuf
func (r *RepoList) AddRepo(pb *gitpb.Repo) (*RepoRow, error) {
log.Info("isdir() start")
if !pb.IsDirectory() {
// this directory doesn't exist anymore
// was moved, or isn't in the ~/go/src or wherever go.work is
return nil, errors.New("path is gone: " + pb.FullPath)
}
log.Info("isdir() end")
test, ok := r.allrepos[pb.GetGoPath()]
if ok {
// this repo gopath was already added
return test, nil
}
log.Info("isdir() end 2")
status, err := repostatus.NewRepoStatusWindow(pb)
if err != nil {
return nil, err
}
log.Info("isdir() end 3")
newRepo := new(RepoRow)
newRepo.Status = status
newRepo.pb = pb
newRepo.Status.InitOk = false
newRepo.pLabel = r.reposgrid.NewLabel(pb.GoPath).SetProgName("path")
newRepo.hidden = false
r.allrepos[pb.GoPath] = newRepo
// newRepo.NewScan()
newRepo.lastTag = r.reposgrid.NewLabel("")
newRepo.masterVersion = r.reposgrid.NewLabel("")
newRepo.develVersion = r.reposgrid.NewLabel("")
newRepo.userVersion = r.reposgrid.NewLabel("")
newRepo.gitState = r.reposgrid.NewLabel("")
newRepo.currentName = r.reposgrid.NewLabel("")
newRepo.currentVersion = r.reposgrid.NewLabel("")
newRepo.endBox = r.reposgrid.NewHorizontalBox("HBOX")
newRepo.endBox.NewButton("Configure", func() {
newRepo.Status.Toggle()
})
newRepo.endBox.NewButton("show diff", func() {
r.reposbox.Disable()
log.Log(REPOWARN, "show diff currentName =", newRepo.currentName.String())
log.Log(REPOWARN, "show diff masterVersion =", newRepo.masterVersion.String())
// newRepo.Status.XtermNohup([]string{"git diff"})
newRepo.Status.Xterm("git diff; bash")
r.reposbox.Enable()
})
newRepo.endBox.NewButton("commit all", func() {
if !newRepo.Status.IsUserBranch() {
log.Log(REPOWARN, "can not commit on non user branch")
return
}
r.reposbox.Disable()
// restore anything staged so everything can be reviewed
newRepo.Status.Run([]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.Run([]string{"git", "restore", "--staged", "."})
} else {
newRepo.NewScan()
}
r.reposbox.Enable()
})
r.reposgrid.NextRow()
newRepo.Status.InitOk = true
return newRepo, nil
}