summaryrefslogtreecommitdiff
path: root/git.go
blob: 4e0c39450750ece97c25387e069166752dc2f88e (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
93
94
95
96
97
98
99
100
package repostatus

// most everything here needs to be deprecated now
func (rs *RepoStatus) Path() string {
	return rs.realPath.String()
}

/*
func (rs *RepoStatus) GitState() string {
	return rs.gitState.String()
}
*/

func (rs *RepoStatus) GetStatus() string {
	return rs.gitState.String()
}

func (rs *RepoStatus) GetLastTagVersion() string {
	return rs.lasttag.String()
}

func (rs *RepoStatus) displayCurrentBranchName() string {
	out := rs.pb.GetCurrentBranchName()
	rs.currentBranch.SetValue(out)
	return out
}

// stores the current branch name
func (rs *RepoStatus) checkCurrentBranchName() string {
	currentname := rs.currentBranch.String()
	out := rs.pb.GetCurrentBranchName()
	if currentname == out {
		// nothing changed
		return currentname
	}
	rs.currentBranch.SetValue(out)
	if currentname == "" {
		return out // don't note if there was nothing before
	}
	rs.NoteChange("current branch has changed from " + currentname + " to " + out)
	return out
}

/*
func (rs *RepoStatus) oldgitDescribeByHash(hash string) (string, error) {
	if hash == "" {
		return "", errors.New("hash was blank")
	}
	r := shell.PathRunLog(rs.realPath.String(), []string{"git", "describe", "--tags", "--always", hash}, INFO)
	out := strings.Join(r.Stdout, "\n")
	if r.Error != nil {
		log.Warn("not in a git repo or bad hash?", r.Error, rs.Path())
		return out, r.Error
	}
	return out, r.Error
}

func (rs *RepoStatus) oldgitDescribeByName(name string) (string, error) {
	name = strings.TrimSpace(name)

	if name == "" {
		// git will return the current tag
		r := shell.PathRunLog(rs.Path(), []string{"git", "describe", "--tags", "--always"}, INFO)
		output := strings.Join(r.Stdout, "\n")
		if r.Error != nil {
			log.Warn("gitDescribeByName() not in a git repo?", r.Error, rs.Path())
		}
		return strings.TrimSpace(output), r.Error
	}
	if !rs.LocalTagExists(name) {
		// tag does not exist
		return "", errors.New("gitDescribeByName() git fatal: Not a valid object name")
	}
	cmd := []string{"git", "describe", "--tags", "--always", name}
	r := shell.PathRunLog(rs.Path(), cmd, INFO)
	output := strings.Join(r.Stdout, "\n")
	if r.Error != nil {
		log.Warn("cmd =", cmd)
		log.Warn("err =", r.Error)
		log.Warn("not in a git repo or bad tag?", rs.Path())
	}

	return strings.TrimSpace(output), r.Error
}
*/

/*
func (rs *RepoStatus) populateTags() {
	tmp := rs.realPath.String() + "/.git/refs/tags"
	log.Log(REPO, "populateTags() path =", tmp)
	for _, tag := range gitpb.ListFiles(tmp) {
		if rs.tags[tag] == "" {
			log.Log(REPO, "populateTags() Adding new tag", tag)
			// rs.tagsDrop.AddText(tag)
			rs.tags[tag] = "origin"
		}
	}
	// rs.tagsDrop.SetText(rs.lasttagrev)
}
*/