autotypist/git.go

93 lines
1.8 KiB
Go

// This is a simple example
package main
import (
"strings"
"go.wit.com/log"
// "go.wit.com/gui/gui"
// "go.wit.com/gui/gadgets"
// "go.wit.com/apps/control-panel-dns/smartwindow"
)
func (r *repo) checkoutBranch(branch string) {
if ! r.checkDirty() {
out := run(r.path, "git", "checkout " + branch)
log.Warn(r.path, "git checkout " + branch, "returned", out)
}
r.getCurrentBranchName()
r.getCurrentBranchVersion()
}
func (r *repo) getBranch() {
out := run(r.path, "git", "branch --show-current")
r.bLabel.SetText(out)
}
func (r *repo) checkDirty() bool {
out := run(r.path, "git", "diff-index HEAD")
if out == "" {
r.sLabel.SetText("")
r.pButton.Disable()
return false
} else {
r.sLabel.SetText("dirty")
r.pButton.Enable()
return true
}
}
func (r *repo) getLastTagVersion() string {
out := run(r.path, "git", "rev-list --tags --max-count=1")
out = strings.TrimSpace(out)
r.lasttagrev = out
lastreal := "describe --tags " + out
// out = run(r.path, "git", "describe --tags c871d5ecf051a7dc4e3a77157cdbc0a457eb9ae1")
out = run(r.path, "git", lastreal)
r.lasttag = out
r.lastLabel.SetText(out)
return out
}
func (r *repo) getCurrentBranchName() string {
out := run(r.path, "git", "branch --show-current")
r.bLabel.SetText(out)
return out
}
func (r *repo) getCurrentBranchVersion() string {
log.Info("r.path", r.path)
out := run(r.path, "git", "describe --tags")
r.vLabel.SetText(out)
return out
}
func (r *repo) populateTags() {
r.tags = listFiles(fullpath(r.path + "/.git/refs/tags"))
for _, tag := range r.tags {
r.tagsDrop.AddText(tag)
}
r.tagsDrop.SetText(r.lasttag)
}
func (r *repo) scan() {
r.getLastTagVersion()
r.getCurrentBranchName()
r.getCurrentBranchVersion()
r.checkDirty()
r.populateTags()
}
func checkrepos() {
for i, r := range allrepos {
log.Warn("scannning", i, r.path)
r.scan()
}
}