2024-01-09 15:34:53 -06:00
|
|
|
package repostatus
|
|
|
|
|
|
|
|
import (
|
2024-02-16 17:55:13 -06:00
|
|
|
"errors"
|
2024-02-24 05:27:58 -06:00
|
|
|
"fmt"
|
2024-02-16 20:36:31 -06:00
|
|
|
"os/user"
|
2024-01-11 23:24:09 -06:00
|
|
|
"strings"
|
2024-02-22 15:29:22 -06:00
|
|
|
"time"
|
2024-01-11 23:24:09 -06:00
|
|
|
"unicode/utf8"
|
|
|
|
|
2024-01-18 00:57:43 -06:00
|
|
|
"io/ioutil"
|
2024-01-18 16:20:11 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
2024-01-09 15:34:53 -06:00
|
|
|
)
|
|
|
|
|
2024-01-13 20:30:33 -06:00
|
|
|
func (rs *RepoStatus) GetCurrentBranchName() string {
|
2024-01-17 03:59:13 -06:00
|
|
|
return rs.currentBranch.String()
|
2024-01-13 20:30:33 -06:00
|
|
|
}
|
2024-01-16 04:47:44 -06:00
|
|
|
|
2024-01-13 20:30:33 -06:00
|
|
|
func (rs *RepoStatus) GetCurrentBranchVersion() string {
|
2024-01-17 03:59:13 -06:00
|
|
|
return rs.currentVersion.String()
|
2024-01-13 20:30:33 -06:00
|
|
|
}
|
2024-01-16 04:47:44 -06:00
|
|
|
|
2024-02-22 17:19:29 -06:00
|
|
|
func (rs *RepoStatus) LastGitPull() (time.Time, error) {
|
|
|
|
return rs.mtime(".git/FETCH_HEAD")
|
|
|
|
}
|
|
|
|
|
2024-02-22 15:29:22 -06:00
|
|
|
func (rs *RepoStatus) Age() time.Duration {
|
|
|
|
var t *Tag
|
|
|
|
t = rs.NewestTag()
|
|
|
|
|
|
|
|
if t != nil {
|
|
|
|
log.Log(REPO, "newest tag:", t.date.String(), t.tag.String(), t.Name())
|
|
|
|
return t.Age()
|
|
|
|
}
|
|
|
|
|
|
|
|
const gitLayout = "Mon Jan 2 15:04:05 2006 -0700"
|
|
|
|
const madeuptime = "Mon Jun 3 15:04:05 2013 -0700"
|
|
|
|
tagTime, _ := time.Parse(gitLayout, madeuptime)
|
|
|
|
return time.Since(tagTime)
|
|
|
|
}
|
|
|
|
|
2024-02-22 17:19:29 -06:00
|
|
|
func (rs *RepoStatus) GitPull() error {
|
2024-02-24 04:50:31 -06:00
|
|
|
currentName := rs.GetCurrentBranchName()
|
|
|
|
if rs.IsOnlyLocalTag(currentName) {
|
|
|
|
log.Log(REPOWARN, rs.Path(), "can not git pull on local only branch", currentName)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var found bool = false
|
|
|
|
// okay, it's not local. Is it mapped in .git/config ?
|
|
|
|
for name, branch := range rs.gitConfig.branches {
|
|
|
|
log.Log(WARN, name, "remote:", branch.remote, "merge", branch.merge)
|
|
|
|
if name == currentName {
|
|
|
|
log.Log(WARN, "Found:", name, "remote:", branch.remote, "merge", branch.merge)
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
2024-02-24 05:27:58 -06:00
|
|
|
if !found {
|
2024-02-24 04:50:31 -06:00
|
|
|
return errors.New("git config error")
|
|
|
|
}
|
2024-02-22 17:19:29 -06:00
|
|
|
var cmd []string
|
|
|
|
cmd = append(cmd, "git", "pull")
|
2024-02-24 04:50:31 -06:00
|
|
|
err, output := rs.RunCmd(cmd)
|
|
|
|
if err != nil {
|
|
|
|
output = "git error_,,,_a_,,,_b_,,,c"
|
|
|
|
}
|
2024-02-22 17:19:29 -06:00
|
|
|
if err == nil {
|
2024-02-23 00:10:30 -06:00
|
|
|
log.Log(REPOWARN, "git pull ran", rs.Path())
|
|
|
|
log.Log(REPOWARN, "git pull output", output)
|
2024-02-22 17:19:29 -06:00
|
|
|
} else {
|
2024-02-23 00:10:30 -06:00
|
|
|
log.Log(REPOWARN, "git pull error", rs.Path(), err)
|
2024-02-22 17:19:29 -06:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-22 05:24:31 -06:00
|
|
|
/*
|
|
|
|
// this isn't right
|
2024-02-15 22:50:50 -06:00
|
|
|
func (rs *RepoStatus) LastTagAge() (time.Time, string) {
|
|
|
|
return time.Now(), rs.lasttag.String()
|
|
|
|
}
|
2024-02-22 05:24:31 -06:00
|
|
|
*/
|
2024-02-15 22:50:50 -06:00
|
|
|
|
2024-01-13 20:30:33 -06:00
|
|
|
func (rs *RepoStatus) GetLastTagVersion() string {
|
2024-01-17 03:59:13 -06:00
|
|
|
return rs.lasttag.String()
|
2024-01-13 20:30:33 -06:00
|
|
|
}
|
|
|
|
|
2024-02-16 17:55:13 -06:00
|
|
|
// stores the current branch name
|
|
|
|
func (rs *RepoStatus) checkCurrentBranchName() string {
|
|
|
|
currentname := rs.currentBranch.String()
|
2024-01-23 15:20:54 -06:00
|
|
|
out := run(rs.realPath.String(), "git", "branch --show-current")
|
2024-02-16 17:55:13 -06:00
|
|
|
if currentname == out {
|
|
|
|
// nothing changed
|
|
|
|
return currentname
|
|
|
|
}
|
2024-01-19 12:36:52 -06:00
|
|
|
rs.currentBranch.SetValue(out)
|
2024-02-16 17:55:13 -06:00
|
|
|
if currentname == "" {
|
|
|
|
return out // don't note if there was nothing before
|
|
|
|
}
|
|
|
|
rs.NoteChange("current branch has changed from " + currentname + " to " + out)
|
2024-01-09 15:34:53 -06:00
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2024-02-16 17:55:13 -06:00
|
|
|
func (rs *RepoStatus) gitDescribeByHash(hash string) (string, error) {
|
|
|
|
if hash == "" {
|
|
|
|
return "", errors.New("hash was blank")
|
|
|
|
}
|
|
|
|
err, out := rs.RunCmd([]string{"git", "describe", "--tags", "--always", hash})
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("not in a git repo or bad hash?", err, rs.Path())
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
return out, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) gitDescribeByName(name string) (string, error) {
|
2024-02-16 11:41:29 -06:00
|
|
|
name = strings.TrimSpace(name)
|
|
|
|
|
|
|
|
if name == "" {
|
|
|
|
// git will return the current tag
|
2024-02-16 17:55:13 -06:00
|
|
|
err, out := rs.RunCmd([]string{"git", "describe", "--tags", "--always"})
|
2024-02-16 11:41:29 -06:00
|
|
|
if err != nil {
|
|
|
|
log.Warn("not in a git repo?", err, rs.Path())
|
|
|
|
return "", err
|
|
|
|
}
|
2024-02-16 17:55:13 -06:00
|
|
|
out = strings.TrimSpace(out)
|
2024-02-16 11:41:29 -06:00
|
|
|
return out, err
|
|
|
|
}
|
2024-02-16 17:55:13 -06:00
|
|
|
if !rs.LocalTagExists(name) {
|
|
|
|
// tag does not exist
|
|
|
|
return "", errors.New("git fatal: Not a valid object name")
|
|
|
|
}
|
|
|
|
cmd := []string{"git", "describe", "--tags", "--always", name}
|
|
|
|
err, out := rs.RunCmd(cmd)
|
2024-02-16 11:41:29 -06:00
|
|
|
if err != nil {
|
2024-02-16 17:55:13 -06:00
|
|
|
log.Warn("cmd =", cmd)
|
|
|
|
log.Warn("err =", err)
|
|
|
|
log.Warn("not in a git repo or bad tag?", rs.Path())
|
2024-02-16 11:41:29 -06:00
|
|
|
return "", err
|
|
|
|
}
|
2024-02-16 17:55:13 -06:00
|
|
|
out = strings.TrimSpace(out)
|
2024-02-16 11:41:29 -06:00
|
|
|
return out, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: don't run git every time?
|
2024-02-16 17:55:13 -06:00
|
|
|
func (rs *RepoStatus) checkCurrentBranchVersion() string {
|
|
|
|
out, _ := rs.gitDescribeByName("")
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "checkCurrentBranchVersion()", out)
|
2024-01-19 12:36:52 -06:00
|
|
|
rs.currentVersion.SetValue(out)
|
2024-01-09 15:34:53 -06:00
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2024-02-16 17:55:13 -06:00
|
|
|
// this should get the most recent tag
|
|
|
|
func (rs *RepoStatus) setLastTagVersion() {
|
|
|
|
hash := run(rs.realPath.String(), "git", "rev-list --tags --max-count=1")
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "getLastTagVersion()", hash)
|
2024-02-16 17:55:13 -06:00
|
|
|
|
|
|
|
name, _ := rs.gitDescribeByHash(hash)
|
|
|
|
rs.lasttag.SetText(name)
|
|
|
|
return
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) populateTags() {
|
2024-01-23 15:20:54 -06:00
|
|
|
tmp := rs.realPath.String() + "/.git/refs/tags"
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "populateTags() path =", tmp)
|
2024-01-09 15:34:53 -06:00
|
|
|
for _, tag := range listFiles(tmp) {
|
|
|
|
if rs.tags[tag] == "" {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "populateTags() Adding new tag", tag)
|
2024-02-14 00:09:58 -06:00
|
|
|
// rs.tagsDrop.AddText(tag)
|
2024-01-09 15:34:53 -06:00
|
|
|
rs.tags[tag] = "origin"
|
|
|
|
}
|
|
|
|
}
|
2024-01-17 03:59:13 -06:00
|
|
|
// rs.tagsDrop.SetText(rs.lasttagrev)
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
|
|
|
|
2024-01-11 15:56:50 -06:00
|
|
|
func (rs *RepoStatus) getBranches() []string {
|
|
|
|
var all []string
|
|
|
|
var heads []string
|
|
|
|
var remotes []string
|
2024-01-23 15:20:54 -06:00
|
|
|
heads = listFiles(rs.realPath.String() + "/.git/refs/heads")
|
|
|
|
remotes = listFiles(rs.realPath.String() + "/.git/refs/remotes")
|
2024-01-11 15:56:50 -06:00
|
|
|
|
|
|
|
all = heads
|
|
|
|
|
|
|
|
all = append(all, remotes...)
|
|
|
|
|
|
|
|
for _, branch := range all {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "getBranches()", branch)
|
2024-01-11 15:56:50 -06:00
|
|
|
}
|
|
|
|
return all
|
|
|
|
}
|
|
|
|
|
2024-02-16 20:36:31 -06:00
|
|
|
// returns quickly based on the last time it was checked
|
|
|
|
func (rs *RepoStatus) IsDirty() bool {
|
2024-02-24 05:37:53 -06:00
|
|
|
if rs.dirtyLabel.String() == "no" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
2024-02-16 20:36:31 -06:00
|
|
|
}
|
|
|
|
|
2024-01-13 20:30:33 -06:00
|
|
|
func (rs *RepoStatus) CheckDirty() bool {
|
2024-02-24 05:27:58 -06:00
|
|
|
var start string = rs.dirtyLabel.String()
|
2024-01-30 10:08:07 -06:00
|
|
|
cmd := []string{"git", "status"}
|
2024-02-24 05:37:53 -06:00
|
|
|
err, out := rs.RunCmd(cmd)
|
2024-01-15 22:55:19 -06:00
|
|
|
if err != nil {
|
2024-02-12 06:23:31 -06:00
|
|
|
log.Warn("CheckDirty() status cmd =", cmd)
|
|
|
|
log.Warn("CheckDirty() status out =", out)
|
|
|
|
log.Warn("CheckDirty() status err =", err)
|
|
|
|
log.Error(err, "CheckDirty() git status error")
|
2024-01-19 12:36:52 -06:00
|
|
|
rs.dirtyLabel.SetValue("error")
|
2024-02-24 05:27:58 -06:00
|
|
|
if start != "error" {
|
2024-02-24 11:56:02 -06:00
|
|
|
rs.NoteChange("git status is in error " + fmt.Sprint(err))
|
2024-02-24 05:27:58 -06:00
|
|
|
}
|
2024-01-15 22:55:19 -06:00
|
|
|
return true
|
|
|
|
}
|
2024-01-30 10:08:07 -06:00
|
|
|
|
|
|
|
last := out[strings.LastIndex(out, "\n")+1:]
|
|
|
|
|
|
|
|
if last == "nothing to commit, working tree clean" {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "CheckDirty() no", rs.realPath.String())
|
2024-01-19 12:36:52 -06:00
|
|
|
rs.dirtyLabel.SetValue("no")
|
2024-02-24 05:27:58 -06:00
|
|
|
if start != "no" {
|
2024-02-24 11:56:02 -06:00
|
|
|
log.Log(REPOWARN, "is no longer dirty")
|
|
|
|
rs.NoteChange("is no longer dirty")
|
2024-02-24 05:27:58 -06:00
|
|
|
}
|
2024-01-09 15:34:53 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-01-26 11:53:22 -06:00
|
|
|
|
2024-01-19 12:36:52 -06:00
|
|
|
rs.dirtyLabel.SetValue("dirty")
|
2024-02-24 05:27:58 -06:00
|
|
|
if start != "dirty" {
|
2024-02-24 11:56:02 -06:00
|
|
|
log.Log(REPOWARN, "is now dirty")
|
|
|
|
rs.NoteChange("is now dirty")
|
2024-02-24 05:27:58 -06:00
|
|
|
}
|
2024-01-15 22:55:19 -06:00
|
|
|
return true
|
2024-01-09 15:34:53 -06:00
|
|
|
|
|
|
|
}
|
2024-02-16 17:55:13 -06:00
|
|
|
func (rs *RepoStatus) CheckoutBranch(bname string) bool {
|
|
|
|
if rs.CheckDirty() {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, rs.realPath.String(), "is dirty")
|
2024-02-22 05:24:31 -06:00
|
|
|
log.Info(bname, "is dirty", rs.Path())
|
2024-02-16 17:55:13 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !rs.TagExists(bname) {
|
|
|
|
// tag does not exist
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "repo does not have branch", bname, rs.Path())
|
2024-02-16 17:55:13 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
cName := rs.GetCurrentBranchName()
|
|
|
|
if cName == bname {
|
|
|
|
// already on branch
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
cmd := []string{"git", "checkout", bname}
|
|
|
|
err, b, output := RunCmd(rs.realPath.String(), cmd)
|
|
|
|
if err != nil {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, err, b, output)
|
2024-02-16 17:55:13 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
rs.checkCurrentBranchName()
|
|
|
|
rs.checkCurrentBranchVersion()
|
|
|
|
return true
|
2024-01-16 04:47:44 -06:00
|
|
|
}
|
2024-01-31 00:19:39 -06:00
|
|
|
|
|
|
|
func (rs *RepoStatus) CheckoutMaster() bool {
|
|
|
|
if rs.CheckDirty() {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, rs.realPath.String(), "is dirty")
|
2024-01-31 00:19:39 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
mName := rs.GetMasterBranchName()
|
2024-02-16 20:36:31 -06:00
|
|
|
if rs.CheckoutBranch(mName) {
|
|
|
|
return true
|
2024-01-31 00:19:39 -06:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2024-01-16 04:47:44 -06:00
|
|
|
|
2024-02-10 16:32:39 -06:00
|
|
|
func (rs *RepoStatus) CheckoutDevel() bool {
|
|
|
|
devel := rs.develWorkingName.String()
|
|
|
|
// user := rs.userWorkingName.String()
|
2024-02-16 11:41:29 -06:00
|
|
|
if devel == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if rs.CheckDirty() {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, rs.realPath.String(), "is dirty")
|
2024-02-16 11:41:29 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-02-10 16:32:39 -06:00
|
|
|
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "checkoutBranch", devel)
|
2024-02-10 16:32:39 -06:00
|
|
|
rs.checkoutBranch("devel", devel)
|
2024-02-24 05:37:53 -06:00
|
|
|
// log.Log(REPO, "checkoutBranch", user)
|
2024-02-10 16:32:39 -06:00
|
|
|
// rs.checkoutBranch("user", user)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-02-16 11:41:29 -06:00
|
|
|
func (rs *RepoStatus) CheckoutUser() bool {
|
|
|
|
bName := rs.GetUserBranchName()
|
|
|
|
if bName == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if rs.CheckDirty() {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, rs.realPath.String(), "is dirty")
|
2024-02-16 11:41:29 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
cmd := []string{"git", "checkout", bName}
|
|
|
|
err, b, output := RunCmd(rs.realPath.String(), cmd)
|
|
|
|
if err != nil {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, err, b, output)
|
2024-02-16 11:41:29 -06:00
|
|
|
}
|
|
|
|
|
2024-02-16 20:36:31 -06:00
|
|
|
realname := rs.GetCurrentBranchName()
|
|
|
|
realversion := rs.GetCurrentBranchVersion()
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, rs.realPath.String(), "realname =", realname, "realversion =", realversion)
|
2024-02-16 11:41:29 -06:00
|
|
|
|
|
|
|
if realname != bName {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "git checkout failed", rs.realPath.String(), bName, "!=", realname)
|
2024-02-16 11:41:29 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
rs.userBranchVersion.SetValue(realversion)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-11 15:56:50 -06:00
|
|
|
func (rs *RepoStatus) checkoutBranch(level string, branch string) {
|
2024-01-13 20:30:33 -06:00
|
|
|
if rs.CheckDirty() {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "checkoutBranch() checkDirty() == true for repo", rs.realPath.String(), "looking for branch:", branch)
|
2024-01-09 15:34:53 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-23 15:20:54 -06:00
|
|
|
out := run(rs.realPath.String(), "git", "checkout "+branch)
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, rs.realPath.String(), "git checkout "+branch, "returned", out)
|
2024-01-09 15:34:53 -06:00
|
|
|
|
2024-02-16 20:36:31 -06:00
|
|
|
realname := rs.GetCurrentBranchName()
|
|
|
|
realversion := rs.GetCurrentBranchVersion()
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, rs.realPath.String(), "realname =", realname, "realversion =", realversion)
|
2024-01-11 15:56:50 -06:00
|
|
|
|
|
|
|
switch level {
|
|
|
|
case "master":
|
2024-02-16 20:36:31 -06:00
|
|
|
rs.mainBranchVersion.SetValue(realversion)
|
2024-01-11 15:56:50 -06:00
|
|
|
case "devel":
|
2024-01-19 12:36:52 -06:00
|
|
|
rs.develBranchVersion.SetValue(realversion)
|
2024-01-11 15:56:50 -06:00
|
|
|
case "user":
|
2024-01-19 12:36:52 -06:00
|
|
|
rs.userBranchVersion.SetValue(realversion)
|
2024-01-11 15:56:50 -06:00
|
|
|
default:
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-11 23:24:09 -06:00
|
|
|
|
2024-02-16 11:41:29 -06:00
|
|
|
// attempt's to guess at what master is.
|
|
|
|
// TODO: fix this properly
|
2024-02-16 20:36:31 -06:00
|
|
|
func (rs *RepoStatus) guessMainWorkingName() {
|
|
|
|
if !rs.Ready() {
|
2024-01-25 02:23:56 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-16 20:36:31 -06:00
|
|
|
if rs.TagExists("guimaster") {
|
|
|
|
rs.mainWorkingName.SetText("guimaster")
|
|
|
|
rs.mainBranchVersion.SetLabel("guimaster")
|
2024-01-25 02:23:56 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-16 20:36:31 -06:00
|
|
|
if rs.TagExists("master") {
|
|
|
|
rs.mainWorkingName.SetText("master")
|
|
|
|
rs.mainBranchVersion.SetLabel("master")
|
2024-01-25 02:23:56 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-16 20:36:31 -06:00
|
|
|
if rs.TagExists("main") {
|
|
|
|
rs.mainWorkingName.SetText("main")
|
|
|
|
rs.mainBranchVersion.SetLabel("main")
|
2024-02-14 13:48:46 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-02-16 20:36:31 -06:00
|
|
|
// figure out what to do here
|
|
|
|
rs.mainWorkingName.SetText("FIXME")
|
|
|
|
rs.mainBranchVersion.SetLabel("FIXME")
|
|
|
|
}
|
2024-01-25 01:30:01 -06:00
|
|
|
|
2024-02-16 20:36:31 -06:00
|
|
|
func (rs *RepoStatus) guessDevelWorkingName() {
|
|
|
|
if rs.TagExists("guidevel") {
|
|
|
|
rs.develWorkingName.SetValue("guidevel")
|
|
|
|
rs.develBranchVersion.SetLabel("guidevel")
|
2024-01-25 01:30:01 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-16 20:36:31 -06:00
|
|
|
if rs.TagExists("devel") {
|
|
|
|
rs.develWorkingName.SetValue("devel")
|
|
|
|
rs.develBranchVersion.SetLabel("devel")
|
|
|
|
return
|
2024-01-25 01:30:01 -06:00
|
|
|
}
|
2024-01-13 23:29:27 -06:00
|
|
|
|
2024-02-16 20:36:31 -06:00
|
|
|
// figure out what to do here
|
|
|
|
rs.develWorkingName.SetValue("develFIXME")
|
|
|
|
rs.develBranchVersion.SetLabel("develFIXME")
|
2024-01-13 23:29:27 -06:00
|
|
|
}
|
|
|
|
|
2024-02-16 20:36:31 -06:00
|
|
|
func (rs *RepoStatus) setUserWorkingName() {
|
|
|
|
usr, _ := user.Current()
|
|
|
|
uname := usr.Username
|
|
|
|
if rs.TagExists(uname) {
|
|
|
|
rs.userWorkingName.SetValue(uname)
|
|
|
|
rs.userBranchVersion.SetLabel(uname)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
rs.userWorkingName.SetValue("need to create " + uname)
|
|
|
|
rs.userBranchVersion.SetLabel("need to create " + uname)
|
2024-01-13 23:29:27 -06:00
|
|
|
}
|
|
|
|
|
2024-01-13 20:30:33 -06:00
|
|
|
// returns "master", "devel", os.Username, etc
|
2024-01-19 18:25:37 -06:00
|
|
|
func (rs *RepoStatus) GetMasterBranchName() string {
|
2024-01-25 01:30:01 -06:00
|
|
|
name := rs.mainWorkingName.String()
|
2024-01-13 20:30:33 -06:00
|
|
|
return name
|
|
|
|
}
|
2024-01-19 18:25:37 -06:00
|
|
|
func (rs *RepoStatus) GetDevelBranchName() string {
|
2024-01-25 01:30:01 -06:00
|
|
|
name := rs.develWorkingName.String()
|
2024-01-13 20:30:33 -06:00
|
|
|
return name
|
|
|
|
}
|
2024-01-25 01:30:01 -06:00
|
|
|
|
2024-01-19 18:25:37 -06:00
|
|
|
func (rs *RepoStatus) GetUserBranchName() string {
|
2024-01-25 01:30:01 -06:00
|
|
|
name := rs.userWorkingName.String()
|
2024-01-13 20:30:33 -06:00
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns the git versions like "1.3-2-laksdjf" or whatever
|
|
|
|
func (rs *RepoStatus) GetMasterVersion() string {
|
2024-02-16 20:36:31 -06:00
|
|
|
name := rs.mainBranchVersion.String()
|
2024-01-13 20:30:33 -06:00
|
|
|
return name
|
|
|
|
}
|
|
|
|
func (rs *RepoStatus) GetDevelVersion() string {
|
2024-01-17 03:59:13 -06:00
|
|
|
name := rs.develBranchVersion.String()
|
2024-01-13 20:30:33 -06:00
|
|
|
return name
|
|
|
|
}
|
|
|
|
func (rs *RepoStatus) GetUserVersion() string {
|
2024-01-17 03:59:13 -06:00
|
|
|
name := rs.userBranchVersion.String()
|
2024-01-13 20:30:33 -06:00
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2024-02-16 17:55:13 -06:00
|
|
|
func (rs *RepoStatus) setMasterVersion(s string) {
|
|
|
|
old := rs.GetMasterVersion()
|
|
|
|
if old == s {
|
2024-01-19 18:25:37 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-16 20:36:31 -06:00
|
|
|
rs.mainBranchVersion.SetValue(s)
|
2024-02-16 17:55:13 -06:00
|
|
|
if old == "" {
|
|
|
|
return // don't note if there was nothing before
|
|
|
|
}
|
|
|
|
rs.NoteChange("master branch has been changed from " + old + " to " + s)
|
2024-01-19 18:25:37 -06:00
|
|
|
}
|
|
|
|
|
2024-02-16 17:55:13 -06:00
|
|
|
func (rs *RepoStatus) setDevelVersion(s string) {
|
|
|
|
old := rs.GetDevelVersion()
|
|
|
|
if old == s {
|
2024-01-19 18:25:37 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-16 17:55:13 -06:00
|
|
|
if old == "" {
|
|
|
|
// don't note nothing
|
|
|
|
} else {
|
|
|
|
rs.NoteChange("devel branch has been changed from " + old + " to " + s)
|
|
|
|
}
|
2024-01-19 18:25:37 -06:00
|
|
|
rs.develBranchVersion.SetValue(s)
|
|
|
|
}
|
|
|
|
|
2024-02-16 17:55:13 -06:00
|
|
|
func (rs *RepoStatus) setUserVersion(s string) {
|
|
|
|
old := rs.GetUserVersion()
|
|
|
|
if old == s {
|
2024-01-19 18:25:37 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-16 17:55:13 -06:00
|
|
|
if old == "" {
|
|
|
|
// don't note nothing
|
|
|
|
} else {
|
|
|
|
rs.NoteChange("user branch has been changed from " + old + " to " + s)
|
|
|
|
}
|
2024-01-19 18:25:37 -06:00
|
|
|
rs.userBranchVersion.SetValue(s)
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:29:10 -06:00
|
|
|
func (rs *RepoStatus) GitState() string {
|
|
|
|
return rs.gitState.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) CheckGitState() string {
|
|
|
|
rs.setState()
|
|
|
|
return rs.gitState.String()
|
|
|
|
}
|
|
|
|
|
2024-01-19 18:25:37 -06:00
|
|
|
func (rs *RepoStatus) GetStatus() string {
|
2024-02-19 16:29:10 -06:00
|
|
|
return rs.gitState.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) setState() {
|
2024-01-19 18:25:37 -06:00
|
|
|
rs.changed = false
|
|
|
|
if rs.CheckDirty() {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "CheckDirty() true")
|
2024-02-19 16:29:10 -06:00
|
|
|
rs.gitState.SetText("dirty")
|
|
|
|
return
|
2024-01-19 18:25:37 -06:00
|
|
|
}
|
2024-02-16 20:36:31 -06:00
|
|
|
if rs.GetUserVersion() != rs.GetDevelVersion() {
|
2024-02-19 16:29:10 -06:00
|
|
|
rs.gitState.SetText("merge to devel")
|
|
|
|
return
|
2024-01-19 18:25:37 -06:00
|
|
|
}
|
2024-02-16 20:36:31 -06:00
|
|
|
if rs.GetDevelVersion() != rs.GetMasterVersion() {
|
2024-02-19 16:29:10 -06:00
|
|
|
rs.gitState.SetText("merge to main")
|
|
|
|
return
|
2024-01-20 21:18:03 -06:00
|
|
|
}
|
2024-02-16 20:36:31 -06:00
|
|
|
if rs.lasttag.String() != rs.GetMasterVersion() {
|
2024-02-19 16:29:10 -06:00
|
|
|
rs.gitState.SetText("unchanged")
|
|
|
|
return
|
2024-01-19 18:25:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if rs.CheckBranches() {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "Branches are Perfect")
|
2024-02-19 16:29:10 -06:00
|
|
|
rs.gitState.SetText("PERFECT")
|
|
|
|
return
|
2024-01-19 18:25:37 -06:00
|
|
|
}
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, rs.String(), "Branches are not Perfect")
|
2024-02-19 16:29:10 -06:00
|
|
|
rs.gitState.SetText("unknown branches")
|
2024-01-19 18:25:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-18 17:37:50 -06:00
|
|
|
// TODO: make this report the error somewhere
|
2024-02-14 02:35:47 -06:00
|
|
|
// This is supposed to check all the branches to make sure
|
|
|
|
// the are the same. that was originally what this was for
|
|
|
|
// now I think it's jsut probably dumb old code that doesn't
|
|
|
|
// need to be here
|
|
|
|
|
|
|
|
// actually, this is to attempt to verify absolutely everything
|
|
|
|
// is pushed upstream before doing a rm -rf ~/go/src
|
|
|
|
// TODO: revisit this code in the autotypist later
|
2024-01-13 20:30:33 -06:00
|
|
|
func (rs *RepoStatus) CheckBranches() bool {
|
2024-01-11 23:24:09 -06:00
|
|
|
var hashCheck string
|
|
|
|
var perfect bool = true
|
|
|
|
all := rs.getBranches()
|
2024-01-23 15:20:54 -06:00
|
|
|
path := rs.realPath.String() + "/.git/refs/"
|
2024-01-11 23:24:09 -06:00
|
|
|
for _, b := range all {
|
|
|
|
parts := strings.Split(b, "/")
|
|
|
|
rdir := "heads"
|
|
|
|
if len(parts) == 2 {
|
|
|
|
rdir = "remotes"
|
|
|
|
}
|
|
|
|
fullfile := path + "/" + rdir + "/" + b
|
|
|
|
|
|
|
|
// check if the ref name is "HEAD". if so, skip
|
|
|
|
runeCount := utf8.RuneCountInString(fullfile)
|
|
|
|
// Convert the string to a slice of runes
|
|
|
|
runes := []rune(fullfile)
|
|
|
|
// Slice the last 4 runes
|
|
|
|
lastFour := runes[runeCount-4:]
|
|
|
|
if string(lastFour) == "HEAD" {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "skip HEAD fullfile", fullfile)
|
2024-01-11 23:24:09 -06:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
content, _ := ioutil.ReadFile(fullfile)
|
|
|
|
hash := strings.TrimSpace(string(content))
|
|
|
|
if hashCheck == "" {
|
|
|
|
hashCheck = hash
|
|
|
|
}
|
|
|
|
var cmd []string
|
|
|
|
cmd = append(cmd, "git", "show", "-s", "--format=%ci", hash)
|
2024-02-14 02:35:47 -06:00
|
|
|
err, output := rs.RunCmd(cmd)
|
|
|
|
if err != nil {
|
|
|
|
// log.Log(WARN, "cmd failed", cmd, "err =", err, "in", rs.String())
|
|
|
|
}
|
2024-01-11 23:24:09 -06:00
|
|
|
// git show -s --format=%ci <hash> will give you the time
|
2024-02-24 05:37:53 -06:00
|
|
|
// log.Log(REPO, fullfile)
|
2024-01-11 23:24:09 -06:00
|
|
|
if hash == hashCheck {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, hash, output, b)
|
2024-01-11 23:24:09 -06:00
|
|
|
} else {
|
2024-02-14 02:35:47 -06:00
|
|
|
// log.Log(WARN, rs.String(), hash, output, b)
|
|
|
|
// log.Log(WARN, "UNKNOWN BRANCHES IN THIS REPO", cmd)
|
2024-01-25 22:59:49 -06:00
|
|
|
rs.versionCmdOutput.SetText("UNKNOWN BRANCHES")
|
2024-01-11 23:24:09 -06:00
|
|
|
perfect = false
|
2024-02-14 02:35:47 -06:00
|
|
|
// parts := strings.Split(b, "/")
|
|
|
|
// log.Warn("git push", parts)
|
2024-01-11 23:24:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return perfect
|
|
|
|
}
|