Compare commits

...

4 Commits

Author SHA1 Message Date
Jeff Carr cfc91c8ba6 rm GOSRC 2025-09-11 23:10:38 -05:00
Jeff Carr 1c8f502c1b rm old code 2025-09-11 06:31:38 -05:00
Jeff Carr a72e9ce5f4 NEVER LEAVE JUNK IN GO REPOS EVER 2025-02-22 19:11:51 -06:00
Jeff Carr 3ab156a9c4 gitpb code is changing 2025-02-21 09:33:58 -06:00
7 changed files with 38 additions and 330 deletions

58
git.go
View File

@ -40,61 +40,3 @@ func (rs *RepoStatus) checkCurrentBranchName() string {
rs.NoteChange("current branch has changed from " + currentname + " to " + out)
return out
}
/*
func (rs *RepoStatus) oldgitDescribeByHash(hash string) (string, error) {
if hash == "" {
return "", errors.New("hash was blank")
}
r := shell.PathRunLog(rs.realPath.String(), []string{"git", "describe", "--tags", "--always", hash}, INFO)
out := strings.Join(r.Stdout, "\n")
if r.Error != nil {
log.Warn("not in a git repo or bad hash?", r.Error, rs.Path())
return out, r.Error
}
return out, r.Error
}
func (rs *RepoStatus) oldgitDescribeByName(name string) (string, error) {
name = strings.TrimSpace(name)
if name == "" {
// git will return the current tag
r := shell.PathRunLog(rs.Path(), []string{"git", "describe", "--tags", "--always"}, INFO)
output := strings.Join(r.Stdout, "\n")
if r.Error != nil {
log.Warn("gitDescribeByName() not in a git repo?", r.Error, rs.Path())
}
return strings.TrimSpace(output), r.Error
}
if !rs.LocalTagExists(name) {
// tag does not exist
return "", errors.New("gitDescribeByName() git fatal: Not a valid object name")
}
cmd := []string{"git", "describe", "--tags", "--always", name}
r := shell.PathRunLog(rs.Path(), cmd, INFO)
output := strings.Join(r.Stdout, "\n")
if r.Error != nil {
log.Warn("cmd =", cmd)
log.Warn("err =", r.Error)
log.Warn("not in a git repo or bad tag?", rs.Path())
}
return strings.TrimSpace(output), r.Error
}
*/
/*
func (rs *RepoStatus) populateTags() {
tmp := rs.realPath.String() + "/.git/refs/tags"
log.Log(REPO, "populateTags() path =", tmp)
for _, tag := range gitpb.ListFiles(tmp) {
if rs.tags[tag] == "" {
log.Log(REPO, "populateTags() Adding new tag", tag)
// rs.tagsDrop.AddText(tag)
rs.tags[tag] = "origin"
}
}
// rs.tagsDrop.SetText(rs.lasttagrev)
}
*/

View File

@ -1,95 +0,0 @@
package repolist
// attempt to make a golang 'interface' for a 'view' of git repos
import (
"context"
"errors"
"fmt"
"go.wit.com/lib/protobuf/virtbuf"
)
// ViewRepoManager is a concrete implementation of the RepoManager interface.
type ViewRepoManager struct {
// client represents a hypothetical API client for interacting with the cloud.
client ViewAPIClient
}
// ViewAPIClient defines the methods required from the API client.
// This is useful if you want to mock this client for testing.
type ViewAPIClient interface {
GetRepoByName(ctx context.Context, name string) (*virtbuf.Cluster, error)
StartRepo(ctx context.Context, clusterID string) error
StopRepo(ctx context.Context, clusterID string) error
ListRepos(ctx context.Context) ([]*virtbuf.Cluster, error)
GetRepoStatus(ctx context.Context, clusterID string) (string, error)
}
// NewViewRepoManager creates a new ViewRepoManager with the provided API client.
func NewViewRepoManager(client ViewAPIClient) *ViewRepoManager {
return &ViewRepoManager{client: client}
}
// FindByName retrieves a cluster by name.
func (m *ViewRepoManager) FindByName(ctx context.Context, name string) (*virtbuf.Cluster, error) {
cluster, err := m.client.GetRepoByName(ctx, name)
if err != nil {
return nil, fmt.Errorf("error finding cluster by name %q: %w", name, err)
}
return cluster, nil
}
// Start initiates the startup process for the specified cluster.
func (m *ViewRepoManager) Start(ctx context.Context, cluster *virtbuf.Cluster) error {
if cluster == nil {
return errors.New("cluster cannot be nil")
}
/*
err := m.client.StartRepo(ctx, cluster.Id)
if err != nil {
return fmt.Errorf("error starting cluster %q: %w", cluster.Id, err)
}
*/
return nil
}
// Stop halts the specified cluster.
func (m *ViewRepoManager) Stop(ctx context.Context, cluster *virtbuf.Cluster) error {
if cluster == nil {
return errors.New("cluster cannot be nil")
}
/*
err := m.client.StopRepo(ctx, cluster.Id)
if err != nil {
return fmt.Errorf("error stopping cluster %q: %w", cluster.Id, err)
}
*/
return nil
}
// List retrieves all available clusters.
func (m *ViewRepoManager) List(ctx context.Context) ([]*virtbuf.Cluster, error) {
/*
clusters, err := m.client.ListRepos(ctx)
if err != nil {
return nil, fmt.Errorf("error listing clusters: %w", err)
}
return clusters, nil
*/
return nil, errors.New("List not done yet")
}
// Status checks the current status of a specified cluster.
func (m *ViewRepoManager) Status(ctx context.Context, cluster *virtbuf.Cluster) (string, error) {
if cluster == nil {
return "", errors.New("cluster cannot be nil")
}
/*
status, err := m.client.GetRepoStatus(ctx, cluster.Id)
if err != nil {
return "", fmt.Errorf("error getting status of cluster %q: %w", cluster.Id, err)
}
*/
return "", nil
}

View File

@ -1,32 +0,0 @@
package repostatus
import (
"strings"
"go.wit.com/log"
)
func (rs *RepoStatus) setGitCommands() {
var line1, line2, line3 []string
var all [][]string
newTag := rs.newversion.String()
line1 = append(line1, "git", "tag", "v"+newTag, "-m", rs.versionMessage.String())
all = append(all, line1)
line2 = append(line2, "git", "push", "--tags")
all = append(all, line2)
line3 = append(line3, "git", "push", "--prune", "--tags")
all = append(all, line3)
rs.versionCmds = all
var tmp []string
// convert to displayable to the user text
for _, line := range all {
s := strings.Join(line, " ")
log.Log(INFO, "s =", s)
tmp = append(tmp, s)
}
rs.versionCmdOutput.SetValue(strings.Join(tmp, "\n"))
}

View File

@ -1,41 +0,0 @@
package repostatus
// reverts master to devel
// used in the unwind process of making GUI releases
/*
func (rs *RepoStatus) RevertMasterToDevel() bool {
if rs.CheckDirty() {
log.Info("sorry, it's still dirty")
return false
}
curName := rs.GetCurrentBranchName()
dName := rs.GetDevelBranchName()
mName := rs.GetMasterBranchName()
if curName != mName {
log.Info("repo is not working from main branch", curName, "!=", mName)
return false
}
log.Info("reset master to devel", curName, rs.String())
var all [][]string
all = append(all, []string{"git", "checkout", dName}) // switch to the devel branch
all = append(all, []string{"git", "branch", "-D", mName})
all = append(all, []string{"git", "branch", mName}) // make a master branch based on devel
all = append(all, []string{"git", "checkout", mName})
all = append(all, []string{"git", "push", "--set-upstream", "--force", "origin", mName})
// don't do anything with tags here
// all = append(all, []string{"git", "tag", "--delete", release.version.String()})
// all = append(all, []string{"git", "push", "--delete", "origin", release.version.String()})
if rs.DoAll(all) {
log.Info("EVERYTHING OK. RERELEASED", rs.String())
return true
}
log.Info("SOMETHING FAILED")
return false
}
*/

View File

@ -1,36 +0,0 @@
package repostatus
import (
"time"
)
// timeFunction takes a function as an argument and returns the execution time.
func timeFunction(f func()) time.Duration {
startTime := time.Now() // Record the start time
f() // Execute the function
return time.Since(startTime) // Calculate the elapsed time
}
func (ls *RepoStatus) SetSpeedActual(s string) {
if !ls.Ready() {
return
}
ls.speedActual.SetValue(s)
}
func (rs *RepoStatus) setSpeed(duration time.Duration) {
s := fmt.Sprint(duration)
if rs.speedActual == nil {
log.Log(WARN, "rs.speedActual == nil")
return
}
rs.speedActual.SetValue(s)
if duration > 200*time.Millisecond {
rs.speed.SetValue("SLOW")
} else if duration > 50*time.Millisecond {
rs.speed.SetValue("OK")
} else {
rs.speed.SetValue("FAST")
}
}

View File

@ -81,45 +81,47 @@ func MakeRepoBranchesWindow(repo *gitpb.Repo) *repoBranchesWindow {
grid.NewGroup("Hash")
grid.NextRow()
for _, b := range repo.GetLocalBranches() {
hash := repo.GetBranchHash(b)
grid.NewLabel(b)
grid.NewLabel(repo.GetBranchVersion(b))
if s, err := repo.GetHashName(hash); err == nil {
grid.NewLabel(s)
} else {
grid.NewLabel("err")
}
grid.NewLabel("local")
/*
for _, b := range repo.GetLocalBranches() {
hash := repo.GetBranchHash(b)
grid.NewLabel(b)
grid.NewLabel(repo.GetBranchVersion(b))
if s, err := repo.GetHashName(hash); err == nil {
grid.NewLabel(s)
} else {
grid.NewLabel("err")
}
grid.NewLabel("local")
grid.NewLabel(hash)
grid.NewButton("Delete", func() {
repo.RunVerbose([]string{"git", "branch", "-D", b})
})
grid.NextRow()
}
for _, b := range repo.GetRemoteBranches() {
hash := repo.GetBranchHash(b)
grid.NewLabel(b)
forgeuse := repo.GetBranchVersion(b)
grid.NewLabel(forgeuse)
if s, err := repo.GetHashName(hash); err == nil {
grid.NewLabel(s)
} else {
grid.NewLabel("")
}
grid.NewLabel("remote")
grid.NewLabel(hash)
if b == "origin/HEAD" || forgeuse == "remote master" {
// can't delete these
} else {
grid.NewButton("Delete Remote", func() {
grid.NewLabel(hash)
grid.NewButton("Delete", func() {
repo.RunVerbose([]string{"git", "branch", "-D", b})
})
grid.NextRow()
}
grid.NextRow()
}
for _, b := range repo.GetRemoteBranches() {
hash := repo.GetBranchHash(b)
grid.NewLabel(b)
forgeuse := repo.GetBranchVersion(b)
grid.NewLabel(forgeuse)
if s, err := repo.GetHashName(hash); err == nil {
grid.NewLabel(s)
} else {
grid.NewLabel("")
}
grid.NewLabel("remote")
grid.NewLabel(hash)
if b == "origin/HEAD" || forgeuse == "remote master" {
// can't delete these
} else {
grid.NewButton("Delete Remote", func() {
})
}
grid.NextRow()
}
*/
return pw
}

View File

@ -57,38 +57,6 @@ func NewRepoStatusWindow(repo *gitpb.Repo) (*RepoStatus, error) {
// show standard git commit and merge controls
rs.drawGitCommands(primarybox)
/*
// save ~/go/src & the whole path strings
rs.path.SetValue(path)
rs.goSrcPath.SetValue(os.Getenv("FORGE_GOSRC"))
rs.realPath.SetValue(rs.pb.GetFullPath())
// add all the tags
// rs.makeTagBox(box2)
// rs.readGitConfig()
if rs.pb.GetReadOnly() {
rs.readOnly.SetValue("true")
} else {
rs.readOnly.SetValue("false")
}
rs.mainWorkingName.SetText(rs.pb.GetMasterBranchName())
rs.mainBranchVersion.SetLabel(rs.pb.GetMasterBranchName())
rs.develWorkingName.SetText(rs.pb.GetDevelBranchName())
rs.develBranchVersion.SetLabel(rs.pb.GetDevelBranchName())
rs.userWorkingName.SetText(rs.pb.GetUserBranchName())
rs.userBranchVersion.SetLabel(rs.pb.GetUserBranchName())
if rs.pb.GetGoPath() == "" {
// not golang repo
} else {
rs.isGoLang.SetText("true")
rs.goPath.SetText(rs.pb.GetGoPath())
}
*/
windowMap[path] = rs
return rs, nil
}