summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.go8
-rw-r--r--draw.go182
-rw-r--r--git.go46
-rw-r--r--new.go20
-rw-r--r--structs.go17
-rw-r--r--unix.go22
-rw-r--r--update.go16
7 files changed, 233 insertions, 78 deletions
diff --git a/common.go b/common.go
index bde96ba..1a8c4e2 100644
--- a/common.go
+++ b/common.go
@@ -65,6 +65,14 @@ func (rs *RepoStatus) Ready() bool {
return rs.ready
}
+func (rs *RepoStatus) Horizontal() {
+ rs.window.Horizontal()
+}
+
+func (rs *RepoStatus) Vertical() {
+ rs.window.Vertical()
+}
+
func (rs *RepoStatus) Initialized() bool {
log.Log(CHANGE, "checking Initialized()")
if rs == nil {return false}
diff --git a/draw.go b/draw.go
index fa0edc3..d52482f 100644
--- a/draw.go
+++ b/draw.go
@@ -1,10 +1,12 @@
package repostatus
import (
+ "io/ioutil"
"strconv"
"strings"
"go.wit.com/log"
+ "go.wit.com/gui/gui"
"go.wit.com/gui/gadgets"
)
@@ -12,46 +14,122 @@ import (
// it's assumed you are always passing in a box
func draw(rs *RepoStatus) {
if ! rs.Ready() {return}
- rs.group = rs.window.Box().NewGroup("What GO Knows It Has")
- rs.grid = rs.group.NewGrid("gridnuts", 2, 2)
- rs.grid.SetNext(1,1)
- rs.grid.Margin()
- rs.grid.Pad()
- rs.path = gadgets.NewOneLiner(rs.grid, "path")
- rs.currentBranch = gadgets.NewOneLiner(rs.grid, "branch")
- rs.lasttag = gadgets.NewOneLiner(rs.grid, "last tag")
- rs.currentVersion = gadgets.NewOneLiner(rs.grid, "Version")
- rs.tagsDrop = gadgets.NewBasicDropdown(rs.grid, "existing tags")
- rs.masterBranch = gadgets.NewOneLiner(rs.grid, "master")
- rs.develBranch = gadgets.NewOneLiner(rs.grid, "devel")
- rs.jcarrBranch = gadgets.NewOneLiner(rs.grid, "jcarr")
+ // display the status of the git repository
+ rs.drawGitStatus()
- rs.dirtyLabel = gadgets.NewOneLiner(rs.grid, "dirty")
+ // display the git branches and options
+ rs.drawGitBranches()
- rs.speed = gadgets.NewOneLiner(rs.grid, "refresh speed =")
- rs.speedActual = gadgets.NewOneLiner(rs.grid, "speed actual =")
+ // show standard git commit and merge controls
+ rs.drawGitCommands()
- rs.vgroup = rs.window.Box().NewGroup("git commands")
- newgrid := rs.vgroup.NewGrid("gridnuts", 2, 2)
+ // figure out what the state of the git repository is
+ rs.Update()
+}
+
+func (rs *RepoStatus) drawGitBranches() {
+ rs.gitBranchesGroup = rs.window.Box().NewGroup("branches")
+ newgrid := rs.gitBranchesGroup.NewGrid("gridnuts", 2, 2)
+
+ rs.masterDrop = gadgets.NewBasicDropdown(newgrid, "main branch")
+ rs.develDrop = gadgets.NewBasicDropdown(newgrid, "devel branch")
+ rs.userDrop = gadgets.NewBasicDropdown(newgrid, "user branch")
+ var master = ""
+ all := rs.getBranches()
+ for _, branch := range all {
+ log.Warn("getBranches()", branch)
+ rs.masterDrop.Add(branch)
+ rs.develDrop.Add(branch)
+ rs.userDrop.Add(branch)
+ if branch == "master" {
+ master = "master"
+ }
+ if branch == "main" {
+ master = "main"
+ }
+ }
+ rs.masterDrop.Set(master)
+ // relabel the various gadgets with the right branch name
+ rs.masterBranch.SetLabel(master)
+ rs.major.SetTitle(master)
+
+ rs.develDrop.Set("devel")
+ rs.userDrop.Set("jcarr")
+
+ var count *gui.Node
+
+ newgrid.NewButton("show branches", func() {
+ all := rs.getBranches()
+ i := len(all)
+ count.Set(strconv.Itoa(i))
+ })
+ count = newgrid.NewLabel("")
+ newgrid.NewButton("check branches", func() {
+ all := rs.getBranches()
+ path := fullpath(rs.repopath + "/.git/refs/")
+ for _, b := range all {
+ parts := strings.Split(b, "/")
+ rdir := "heads"
+ if len(parts) == 2 {
+ rdir = "remotes"
+ }
+ fullfile := path + "/" + rdir + "/" + b
+ content, _ := ioutil.ReadFile(fullfile)
+ hash := strings.TrimSpace(string(content))
+ // log.Warn(fullfile)
+ log.Warn(hash, b)
+ }
+ })
+}
+
+func (rs *RepoStatus) drawGitStatus() {
+ rs.gitStatusGroup = rs.window.Box().NewGroup("What GO Knows It Has")
+ newgrid := rs.gitStatusGroup.NewGrid("gridnuts", 2, 2)
+ newgrid.SetNext(1,1)
+ newgrid.Margin()
+ newgrid.Pad()
+
+ rs.path = gadgets.NewOneLiner(newgrid, "path")
+ rs.currentBranch = gadgets.NewOneLiner(newgrid, "branch")
+ rs.lasttag = gadgets.NewOneLiner(newgrid, "last tag")
+ rs.currentVersion = gadgets.NewOneLiner(newgrid, "Version")
+ rs.tagsDrop = gadgets.NewBasicDropdown(newgrid, "existing tags")
+ rs.masterBranch = gadgets.NewOneLiner(newgrid, "master")
+ rs.develBranch = gadgets.NewOneLiner(newgrid, "devel")
+ rs.jcarrBranch = gadgets.NewOneLiner(newgrid, "jcarr")
+
+ rs.dirtyLabel = gadgets.NewOneLiner(newgrid, "dirty")
+
+ rs.speed = gadgets.NewOneLiner(newgrid, "refresh speed =")
+ rs.speedActual = gadgets.NewOneLiner(newgrid, "speed actual =")
+}
+
+func (rs *RepoStatus) drawGitCommands() {
+ rs.gitCommandsGroup = rs.window.Box().NewGroup("git commands")
+ newgrid := rs.gitCommandsGroup.NewGrid("gridnuts", 2, 2)
newgrid.NewButton("update", func() {
rs.Update()
})
- rs.develMerge = newgrid.NewButton("merge devel to master", func() {
- rs.checkoutBranch("master")
- if rs.getCurrentBranchName() != "master" {
+ label := "merge devel to " + rs.masterDrop.Get()
+ rs.develMerge = newgrid.NewButton(label, func() {
+ master := rs.masterDrop.Get()
+ rs.checkoutBranch("master", master)
+ if rs.getCurrentBranchName() != master {
log.Warn("something went wrong switching to the master branch. full stop!")
return
}
- log.Warn("Should merge devel into master here")
- out := run(rs.repopath, "git", "merge devel")
- log.Warn("devel is merged? merginess is complete. perhaps", out)
+ if rs.runGitCommands() {
+ log.Warn("THINGS SEEM OK")
+ } else {
+ log.Warn("SOMETHING WENT WRONG")
+ }
rs.develMerge.Disable() // don't let this run twice for now
})
- rs.major = gadgets.NewBasicCombobox(newgrid, "master")
+ rs.major = gadgets.NewBasicCombobox(newgrid, "major")
rs.major.Custom = func () {
rs.setTag()
rs.generateCmd()
@@ -81,14 +159,15 @@ func draw(rs *RepoStatus) {
return
}
log.Warn("COMMIT IT HERE")
- rs.runGitCommands()
+ if rs.runGitCommands() {
+ log.Warn("THINGS SEEM OK")
+ } else {
+ log.Warn("SOMETHING WENT WRONG")
+ }
})
newgrid.Margin()
newgrid.Pad()
-
- // figure out what the state of the git repository is
- rs.Update()
}
func (rs *RepoStatus) setTag() bool {
@@ -186,6 +265,7 @@ func (rs *RepoStatus) recommend() {
if rs.masterBranch.Get() != rs.develBranch.Get() {
log.Warn("master does not equal devel. merge devel into master")
rs.EnableMergeDevel()
+ rs.setMergeDevelCommands()
return
}
rs.getLastTagVersion()
@@ -229,6 +309,24 @@ func (rs *RepoStatus) generateCmd() bool {
return true
}
+func (rs *RepoStatus) runGitCommands() bool {
+ for _, line := range rs.versionCmds {
+ s := strings.Join(line, " ")
+ log.Warn("NEED TO RUN:", s)
+ err, b, output := runCmd(rs.repopath, line)
+ if err != nil {
+ log.Warn("ABEND EXECUTION")
+ log.Warn("error =", err)
+ log.Warn("output =", output)
+ return false
+ }
+ log.Warn("Returned with b =", b)
+ log.Warn("output was =", output)
+ log.Warn("RUN DONE")
+ }
+ return true
+}
+
func (rs *RepoStatus) setGitCommands() {
var line1, line2, line3 []string
var all [][]string
@@ -253,13 +351,25 @@ func (rs *RepoStatus) setGitCommands() {
rs.versionCmdOutput.Set(strings.Join(tmp, "\n"))
}
-func (rs *RepoStatus) runGitCommands() {
- for _, line := range rs.versionCmds {
+
+func (rs *RepoStatus) setMergeDevelCommands() {
+ var line1, line2 []string
+ var all [][]string
+
+ line1 = append(line1, "git", "merge", "devel")
+ all = append(all, line1)
+ line2 = append(line2, "git", "push")
+ all = append(all, line2)
+
+ rs.versionCmds = all
+
+ var tmp []string
+ // convert to displayable to the user text
+ for _, line := range all {
s := strings.Join(line, " ")
- log.Warn("NEED TO RUN:", s)
- b, output := runCmd(rs.repopath, line)
- log.Warn("Returned with b =", b)
- log.Warn("output was =", output)
- log.Warn("RUN DONE")
+ log.Warn("s =", s)
+ tmp = append(tmp, s)
}
+
+ rs.versionCmdOutput.Set(strings.Join(tmp, "\n"))
}
diff --git a/git.go b/git.go
index ad549e0..f51efe9 100644
--- a/git.go
+++ b/git.go
@@ -45,6 +45,35 @@ func (rs *RepoStatus) populateTags() {
// rs.tagsDrop.Set(rs.lasttagrev)
}
+/*
+.git/refs/remotes
+.git/refs/remotes/github
+.git/refs/remotes/github/devel
+.git/refs/remotes/github/main
+.git/refs/remotes/origin
+.git/refs/remotes/origin/devel
+.git/refs/remotes/origin/main
+.git/refs/remotes/origin/jcarr
+.git/refs/heads
+*/
+
+func (rs *RepoStatus) getBranches() []string {
+ var all []string
+ var heads []string
+ var remotes []string
+ heads = listFiles(fullpath(rs.repopath + "/.git/refs/heads"))
+ remotes = listFiles(fullpath(rs.repopath + "/.git/refs/remotes"))
+
+ all = heads
+
+ all = append(all, remotes...)
+
+ for _, branch := range all {
+ log.Warn("getBranches()", branch)
+ }
+ return all
+}
+
func (rs *RepoStatus) checkDirty() bool {
out := run(rs.repopath, "git", "diff-index HEAD")
if out == "" {
@@ -59,7 +88,7 @@ func (rs *RepoStatus) checkDirty() bool {
}
-func (rs *RepoStatus) checkoutBranch(branch string) {
+func (rs *RepoStatus) checkoutBranch(level string, branch string) {
if rs.checkDirty() {
log.Warn("checkoutBranch() checkDirty() == true for repo", rs.repopath, "looking for branch:", branch)
return
@@ -70,13 +99,14 @@ func (rs *RepoStatus) checkoutBranch(branch string) {
realname := rs.getCurrentBranchName()
realversion := rs.getCurrentBranchVersion()
log.Warn(rs.repopath, "realname =", realname, "realversion =", realversion)
- if realname == "jcarr" {
- rs.jcarrBranch.Set(realversion)
- }
- if realname == "devel" {
- rs.develBranch.Set(realversion)
- }
- if realname == "master" {
+
+ switch level {
+ case "master":
rs.masterBranch.Set(realversion)
+ case "devel":
+ rs.develBranch.Set(realversion)
+ case "user":
+ rs.jcarrBranch.Set(realversion)
+ default:
}
}
diff --git a/new.go b/new.go
index c18480e..3142011 100644
--- a/new.go
+++ b/new.go
@@ -1,8 +1,6 @@
package repostatus
import (
- "go.wit.com/log"
-
"go.wit.com/gui/gui"
"go.wit.com/gui/gadgets"
)
@@ -15,21 +13,7 @@ func New(p *gui.Node, path string) *RepoStatus {
repopath: path,
}
rs.tags = make(map[string]string)
- return rs
-}
-
-func (rs *RepoStatus) InitWindow() {
- if ! rs.Initialized() {
- log.Log(WARN, "not initalized yet (no parent for the window?)")
- return
- }
- if rs.window != nil {
- log.Log(WARN, "You already have a window")
- rs.ready = true
- return
- }
-
- log.Log(WARN, "Creating the Window")
- rs.window = gadgets.NewBasicWindow(rs.parent, "GO Repo Details")
+ rs.window = gadgets.NewBasicWindow(p, "GO Repo Details")
rs.ready = true
+ return rs
}
diff --git a/structs.go b/structs.go
index 844e2b3..8d2c599 100644
--- a/structs.go
+++ b/structs.go
@@ -17,8 +17,8 @@ type RepoStatus struct {
parent *gui.Node
window *gadgets.BasicWindow
- group *gui.Node
- grid *gui.Node
+ // group *gui.Node
+ // grid *gui.Node
// status *gadgets.OneLiner
dirtyLabel *gadgets.OneLiner
@@ -36,16 +36,25 @@ type RepoStatus struct {
develMerge *gui.Node
releaseVersion *gui.Node
- vgroup *gui.Node
+// vgroup *gui.Node
minor *gadgets.BasicCombobox
major *gadgets.BasicCombobox
revision *gadgets.BasicCombobox
+
versionMessage *gadgets.BasicEntry
versionCmds [][]string
- versionCmdOutput *gadgets.OneLiner
+ versionCmdOutput *gadgets.OneLiner
newversion *gui.Node
+ gitBranchesGroup *gui.Node
+ gitStatusGroup *gui.Node
+ gitCommandsGroup *gui.Node
+
+ masterDrop *gadgets.BasicDropdown
+ develDrop *gadgets.BasicDropdown
+ userDrop *gadgets.BasicDropdown
+
speed *gadgets.OneLiner
speedActual *gadgets.OneLiner
}
diff --git a/unix.go b/unix.go
index cc49efc..45a1cbc 100644
--- a/unix.go
+++ b/unix.go
@@ -6,6 +6,7 @@ import (
"os/exec"
"strings"
"regexp"
+ "errors"
"go.wit.com/log"
)
@@ -37,6 +38,7 @@ func run(path string, thing string, cmdline string) string {
return tmp
}
+// goes in one directory so it gets remote branch names
func listFiles(directory string) []string {
var files []string
fileInfo, err := os.ReadDir(directory)
@@ -46,7 +48,15 @@ func listFiles(directory string) []string {
}
for _, file := range fileInfo {
- if !file.IsDir() {
+ if file.IsDir() {
+ dirname := file.Name()
+ newdir, _ := os.ReadDir(directory + "/" + dirname)
+ for _, file := range newdir {
+ if ! file.IsDir() {
+ files = append(files, dirname + "/" + file.Name())
+ }
+ }
+ } else {
files = append(files, file.Name())
}
}
@@ -103,14 +113,14 @@ func splitVersion(version string) (a, b, c string) {
}
}
-func runCmd(path string, parts []string) (bool, string) {
+func runCmd(path string, parts []string) (error, bool, string) {
if len(parts) == 0 {
log.Warn("command line was empty")
- return false, ""
+ return errors.New("empty"), false, ""
}
if parts[0] == "" {
log.Warn("command line was empty")
- return false, ""
+ return errors.New("empty"), false, ""
}
thing := parts[0]
parts = parts[1:]
@@ -128,12 +138,12 @@ func runCmd(path string, parts []string) (bool, string) {
log.Error(err)
log.Warn("output was", output)
log.Warn("cmd exited with error", err)
- return false, string(output)
+ return err, false, string(output)
}
tmp := string(output)
tmp = strings.TrimSpace(tmp)
// Print the output
- return true, tmp
+ return nil, true, tmp
}
diff --git a/update.go b/update.go
index c5fb29a..429bb47 100644
--- a/update.go
+++ b/update.go
@@ -38,16 +38,20 @@ func (rs *RepoStatus) Update() {
return
}
+ master := rs.masterDrop.Get()
+ devel := rs.develDrop.Get()
+ user := rs.userDrop.Get()
+
// rs.checkDirty() this runs
log.Log(WARN, "")
- log.Log(WARN, "checkoutBranch master")
- rs.checkoutBranch("master")
+ log.Log(WARN, "checkoutBranch", master)
+ rs.checkoutBranch("master", master)
log.Log(WARN, "")
- log.Log(WARN, "checkoutBranch devel")
- rs.checkoutBranch("devel")
+ log.Log(WARN, "checkoutBranch", devel)
+ rs.checkoutBranch("devel", devel)
log.Log(WARN, "")
- log.Log(WARN, "checkoutBranch jcarr")
- rs.checkoutBranch("jcarr")
+ log.Log(WARN, "checkoutBranch", user)
+ rs.checkoutBranch("user", user)
rs.recommend()
})