diff options
| author | Jeff Carr <[email protected]> | 2024-01-09 15:34:53 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-09 15:34:53 -0600 |
| commit | 87346d9452b38db517e76e070f11928060bc2b99 (patch) | |
| tree | 2e6ff93e368fda0a1581496985798fe4c1de3569 /git.go | |
initial commit
Diffstat (limited to 'git.go')
| -rw-r--r-- | git.go | 81 |
1 files changed, 81 insertions, 0 deletions
@@ -0,0 +1,81 @@ +package repostatus + +import ( + "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) + // 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) + rs.tagsDrop.AddText(tag) + rs.tags[tag] = "origin" + } + } + rs.tagsDrop.SetText(rs.lasttagrev) +} + +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 + } + +} + +func (rs *RepoStatus) checkoutBranch(branch string) { + 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) + if realname == "jcarr" { + rs.jcarrBranch.Set(realversion) + } + if realname == "devel" { + rs.develBranch.Set(realversion) + } + if realname == "master" { + rs.masterBranch.Set(realversion) + } +} |
