summaryrefslogtreecommitdiff
path: root/reload.go
blob: 0168ea87c0ceea2adb6ce90425cc52ea27a8bc03 (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
package gitpb

import (
	"strings"

	"go.wit.com/log"
)

func (repo *Repo) Reload() error {
	repo.Tags = new(GitTags)
	repo.reloadGitTags()

	repo.GoDeps = new(GoDeps)
	repo.ParseGoSum()

	repo.setLastTag()
	repo.setCurrentBranchName()
	repo.setRepoType()

	// everything has been checked, now save the mtime's
	repo.RepoChanged()
	return nil
}

func (repo *Repo) SetDevelBranchName(bname string) {
	repo.DevelBranchName = bname
}

func (repo *Repo) SetUserBranchName(bname string) {
	repo.UserBranchName = bname
}

// updates LastTag // todo, get this from the protobuf
func (repo *Repo) setLastTag() {
	cmd := []string{"git", "rev-list", "--tags", "--max-count=1"}
	result := repo.RunQuiet(cmd)
	// log.Info("getLastTagVersion()", result.Stdout)

	if len(result.Stdout) != 1 {
		log.Log(GITPBWARN, "git LastTag() error:", result.Stdout)
		repo.LastTag = ""
		return
	}

	hash := result.Stdout[0]

	cmd = []string{"git", "describe", "--tags", "--always", hash}
	result = repo.RunQuiet(cmd)

	if len(result.Stdout) != 1 {
		log.Log(GITPBWARN, "git LastTag() error:", result.Stdout)
		repo.LastTag = ""
		return
	}

	repo.LastTag = result.Stdout[0]
}

func (repo *Repo) setCurrentBranchName() {
	repo.CurrentBranchName = ""
	r := repo.RunQuiet([]string{"git", "branch", "--show-current"})
	output := strings.Join(r.Stdout, "\n")
	if r.Error != nil {
		log.Log(GITPBWARN, "GetCurrentBranchName() not in a git repo?", r.Error, repo.GetGoPath())
		log.Log(GITPBWARN, "GetCurrentBranchName() output might have worked anyway:", output)
	}
	repo.CurrentBranchName = strings.TrimSpace(output)
}

// always spawns 'git' and always should spawn 'git'
func (repo *Repo) setCurrentBranchVersion() {
	repo.CurrentBranchVersion = ""
	if repo == nil {
		log.Info("repo.GetCurrentBranchVersion() repo == nil")
		return
	}
	r := repo.RunQuiet([]string{"git", "describe", "--tags", "--always"})
	output := strings.Join(r.Stdout, "\n")
	if r.Error != nil {
		log.Log(GITPBWARN, "GetCurrentBranchVersion() not in a git repo?", r.Error, repo.GetGoPath())
		log.Log(GITPBWARN, "GetCurrentBranchVersion() output might have worked anyway:", output)
	}
	repo.CurrentBranchVersion = strings.TrimSpace(output)
}