summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--checkDirty.go45
-rw-r--r--currentVersions.go (renamed from gitTag.query.go)78
-rw-r--r--goDep.helpers.go4
-rw-r--r--repo.proto4
5 files changed, 132 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index e730ca1..7bed3b0 100644
--- a/Makefile
+++ b/Makefile
@@ -5,16 +5,14 @@
# go install
-all: gitTag.pb.go goDep.pb.go repo.pb.go
+all: gitTag.pb.go goDep.pb.go repo.pb.go vet
test:
make -C scanGoSrc/
-vet: lint
- GO111MODULE=off go vet
-
-lint:
- # -buf lint refs.proto # todo: figure out where buf comes from again
+vet:
+ @GO111MODULE=off go vet
+ @echo this go library package builds okay
# autofixes your import headers in your golang files
goimports:
diff --git a/checkDirty.go b/checkDirty.go
new file mode 100644
index 0000000..0db0ff4
--- /dev/null
+++ b/checkDirty.go
@@ -0,0 +1,45 @@
+package gitpb
+
+// runs git, parses output
+// types faster than you can
+
+import (
+ "fmt"
+ "strings"
+
+ "go.wit.com/lib/gui/shell"
+ "go.wit.com/log"
+)
+
+func (repo *Repo) NoteChange(s string) {
+ log.Warn("NoteChange()", s)
+}
+
+// just return the current value
+func (repo *Repo) IsDirty() bool {
+ return repo.Dirty
+}
+
+// actually os.Exec('git')
+func (repo *Repo) CheckDirty() bool {
+ cmd := []string{"git", "status", "--porcelain"}
+ r := shell.PathRunLog(repo.FullPath, cmd, GITPB)
+ if r.Error != nil {
+ log.Warn("CheckDirty() status cmd =", cmd)
+ out := strings.Join(r.Stdout, "\n")
+ log.Warn("CheckDirty() status out =", out)
+ log.Warn("CheckDirty() status err =", r.Error)
+ log.Error(r.Error, "CheckDirty() git status error")
+ repo.NoteChange("git status is in error " + fmt.Sprint(r.Error))
+ repo.Dirty = true
+ return true
+ }
+
+ if len(r.Stdout) == 0 {
+ repo.Dirty = false
+ return false
+ }
+ repo.Dirty = true
+ return true
+
+}
diff --git a/gitTag.query.go b/currentVersions.go
index 2c902ad..c5c7395 100644
--- a/gitTag.query.go
+++ b/currentVersions.go
@@ -7,6 +7,7 @@ import (
"errors"
"path/filepath"
"strings"
+ "unicode"
"go.wit.com/log"
)
@@ -74,6 +75,74 @@ func (repo *Repo) GitUserVersion() string {
return ""
}
}
+func (repo *Repo) GetCurrentBranchName() string {
+ 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.GoPath)
+ log.Log(GITPBWARN, "GetCurrentBranchName() output might have worked anyway:", output)
+ }
+ return strings.TrimSpace(output)
+}
+
+func (repo *Repo) GetCurrentBranchVersion() string {
+ 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.GoPath)
+ log.Log(GITPBWARN, "GetCurrentBranchVersion() output might have worked anyway:", output)
+ }
+ return strings.TrimSpace(output)
+}
+
+func (repo *Repo) gitDescribeByHash(hash string) (string, error) {
+ if hash == "" {
+ return "", errors.New("hash was blank")
+ }
+ r := repo.RunQuiet([]string{"git", "describe", "--tags", "--always", hash})
+ out := strings.Join(r.Stdout, "\n")
+ if r.Error != nil {
+ log.Warn("not in a git repo or bad hash?", r.Error, repo.GoPath)
+ return out, r.Error
+ }
+ return out, r.Error
+}
+
+// this should get the most recent tag
+func (repo *Repo) GetLastTagVersion() string {
+ r := repo.RunQuiet([]string{"git", "rev-list", "--tags", "--max-count=1"})
+ hash := strings.Join(r.Stdout, "\n")
+ hash = strings.TrimSpace(hash)
+ log.Log(GITPB, "getLastTagVersion()", hash)
+
+ name, _ := repo.gitDescribeByHash(hash)
+ return name
+}
+
+func (repo *Repo) DebianReleaseVersion() string {
+ lasttag := repo.GetLastTagVersion()
+ newv := trimNonNumericFromStart(lasttag)
+ if newv == "" {
+ newv = "0.0"
+ if lasttag != "" {
+ newv += "-" + lasttag
+ }
+ }
+ return newv
+}
+
+func (repo *Repo) DebianCurrentVersion() string {
+ cbversion := repo.GetCurrentBranchVersion()
+
+ newv := trimNonNumericFromStart(cbversion)
+ if newv == "" {
+ newv = "0.0"
+ }
+ if repo.CheckDirty() {
+ newv += "-dirty"
+ }
+ return newv
+}
func (repo *Repo) gitVersionByName(name string) (string, error) {
name = strings.TrimSpace(name)
@@ -135,3 +204,12 @@ func (repo *Repo) IsBranch(findname string) bool {
log.Log(GITPB, "did not find tag:", findname, "in", repo.GoPath)
return false
}
+
+func trimNonNumericFromStart(s string) string {
+ for i, r := range s {
+ if unicode.IsDigit(r) {
+ return s[i:]
+ }
+ }
+ return ""
+}
diff --git a/goDep.helpers.go b/goDep.helpers.go
index 0af28be..ced3fea 100644
--- a/goDep.helpers.go
+++ b/goDep.helpers.go
@@ -7,8 +7,8 @@ import (
"time"
)
-func (repo *Repo) DeleteGoDepByHash(hash string) *GoDep {
- return repo.GoDeps.DeleteByHash(hash)
+func (repo *Repo) DeleteGoDepByHash(hash string) {
+ repo.GoDeps.DeleteByHash(hash)
}
// enforces no duplicate package names
diff --git a/repo.proto b/repo.proto
index 1d59e4f..fff5579 100644
--- a/repo.proto
+++ b/repo.proto
@@ -23,10 +23,12 @@ message Repo { // `autogenpb:marshal`
bool goPrimitive = 9; // if this is a golang primitive
GoDeps goDeps = 10;
google.protobuf.Timestamp lastGoDep = 11; // last time go.sum was processed
+
+ bool dirty = 12; // if git says things have been changed
}
message Repos { // `autogenpb:marshal`
- string uuid = 1; // I guess why not just have this on each file
+ string uuid = 1; // `autogenpb:uuid:8daaeba1-fb1f-4762-ae6e-95a55d352673`
string version = 2; // maybe can be used for protobuf schema change violations
repeated Repo repos = 3;
}