2024-01-09 15:34:53 -06:00
|
|
|
package repostatus
|
|
|
|
|
|
|
|
import (
|
2024-01-11 23:24:09 -06:00
|
|
|
"strings"
|
|
|
|
"unicode/utf8"
|
|
|
|
|
|
|
|
"io/ioutil"
|
2024-01-09 15:34:53 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (rs *RepoStatus) getCurrentBranchName() string {
|
|
|
|
out := run(rs.repopath, "git", "branch --show-current")
|
|
|
|
log.Warn("getCurrentBranchName() =", out)
|
|
|
|
rs.currentBranch.Set(out)
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) getCurrentBranchVersion() string {
|
|
|
|
out := run(rs.repopath, "git", "describe --tags")
|
|
|
|
log.Warn("getCurrentBranchVersion()", out)
|
|
|
|
rs.currentVersion.Set(out)
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) getLastTagVersion() string {
|
|
|
|
out := run(rs.repopath, "git", "rev-list --tags --max-count=1")
|
|
|
|
log.Warn("getLastTagVersion()", out)
|
|
|
|
rs.lasttagrev = out
|
|
|
|
|
|
|
|
lastreal := "describe --tags " + out
|
|
|
|
// out = run(r.path, "git", "describe --tags c871d5ecf051a7dc4e3a77157cdbc0a457eb9ae1")
|
|
|
|
out = run(rs.repopath, "git", lastreal)
|
|
|
|
rs.lasttag.Set(out)
|
2024-01-10 18:18:01 -06:00
|
|
|
rs.tagsDrop.Set(out)
|
2024-01-09 15:34:53 -06:00
|
|
|
// rs.lastLabel.Set(out)
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) populateTags() {
|
|
|
|
tmp := fullpath(rs.repopath + "/.git/refs/tags")
|
|
|
|
log.Warn("populateTags() path =", tmp)
|
|
|
|
for _, tag := range listFiles(tmp) {
|
|
|
|
if rs.tags[tag] == "" {
|
|
|
|
log.Warn("populateTags() Adding new tag", tag)
|
2024-01-10 18:18:01 -06:00
|
|
|
rs.tagsDrop.Add(tag)
|
2024-01-09 15:34:53 -06:00
|
|
|
rs.tags[tag] = "origin"
|
|
|
|
}
|
|
|
|
}
|
2024-01-10 18:18:01 -06:00
|
|
|
// rs.tagsDrop.Set(rs.lasttagrev)
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
|
|
|
|
2024-01-11 15:56:50 -06:00
|
|
|
/*
|
|
|
|
.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
|
|
|
|
}
|
|
|
|
|
2024-01-09 15:34:53 -06:00
|
|
|
func (rs *RepoStatus) checkDirty() bool {
|
|
|
|
out := run(rs.repopath, "git", "diff-index HEAD")
|
|
|
|
if out == "" {
|
|
|
|
log.Warn("checkDirty() no", rs.repopath)
|
|
|
|
rs.dirtyLabel.Set("no")
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
log.Warn("checkDirty() true", rs.repopath)
|
|
|
|
rs.dirtyLabel.Set("dirty")
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-01-11 15:56:50 -06:00
|
|
|
func (rs *RepoStatus) checkoutBranch(level string, branch string) {
|
2024-01-09 15:34:53 -06:00
|
|
|
if rs.checkDirty() {
|
|
|
|
log.Warn("checkoutBranch() checkDirty() == true for repo", rs.repopath, "looking for branch:", branch)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
out := run(rs.repopath, "git", "checkout " + branch)
|
|
|
|
log.Warn(rs.repopath, "git checkout " + branch, "returned", out)
|
|
|
|
|
|
|
|
realname := rs.getCurrentBranchName()
|
|
|
|
realversion := rs.getCurrentBranchVersion()
|
|
|
|
log.Warn(rs.repopath, "realname =", realname, "realversion =", realversion)
|
2024-01-11 15:56:50 -06:00
|
|
|
|
|
|
|
switch level {
|
|
|
|
case "master":
|
2024-01-09 15:34:53 -06:00
|
|
|
rs.masterBranch.Set(realversion)
|
2024-01-11 15:56:50 -06:00
|
|
|
case "devel":
|
|
|
|
rs.develBranch.Set(realversion)
|
|
|
|
case "user":
|
|
|
|
rs.jcarrBranch.Set(realversion)
|
|
|
|
default:
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-11 23:24:09 -06:00
|
|
|
|
|
|
|
func (rs *RepoStatus) checkBranches() bool {
|
|
|
|
var hashCheck string
|
|
|
|
var perfect bool = true
|
|
|
|
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
|
|
|
|
|
|
|
|
// 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" {
|
|
|
|
log.Warn("skip HEAD fullfile", fullfile)
|
|
|
|
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)
|
|
|
|
_, _, output := runCmd(rs.repopath, cmd)
|
|
|
|
// git show -s --format=%ci <hash> will give you the time
|
|
|
|
// log.Warn(fullfile)
|
|
|
|
if hash == hashCheck {
|
|
|
|
log.Warn(hash, output, b)
|
|
|
|
} else {
|
|
|
|
log.Warn(hash, output, b, "NOT THE SAME")
|
|
|
|
perfect = false
|
|
|
|
parts := strings.Split(b, "/")
|
|
|
|
log.Warn("git push", parts)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return perfect
|
|
|
|
}
|