summaryrefslogtreecommitdiff
path: root/git.go
blob: ad549e0e3b6ed3e48715b9100709753ce0991d56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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.tagsDrop.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.Add(tag)
			rs.tags[tag] = "origin"
		}
	}
	// rs.tagsDrop.Set(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)
	}
}