summaryrefslogtreecommitdiff
path: root/git.go
blob: bc7b283c543cd86ed57304e3f664f7dd5d721a5f (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
83
84
85
86
87
88
89
90
91
92
// 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()
	}
}