diff --git a/gitTag.query.go b/gitTag.query.go index ef87561..750d501 100644 --- a/gitTag.query.go +++ b/gitTag.query.go @@ -89,7 +89,7 @@ func (repo *Repo) gitVersionByName(name string) (string, error) { } return strings.TrimSpace(output), nil } - if ! repo.IsBranch(name) { + if !repo.IsBranch(name) { // tag does not exist log.Log(GITPBWARN, "LocalTagExists()", name, "did not exist") return "", errors.New("gitDescribeByName() git fatal: Not a valid object name: " + name) diff --git a/gitTag.update.go b/gitTag.update.go index 18af8d9..ecf0d6b 100644 --- a/gitTag.update.go +++ b/gitTag.update.go @@ -58,7 +58,7 @@ func (repo *Repo) UpdateGitTags() error { newr := GitTag{ Refname: refname, - Hash: hash, + Hash: hash, Subject: subject, Creatordate: ctime, Authordate: atime, diff --git a/repo.protofiles.go b/repo.protofiles.go new file mode 100644 index 0000000..81a4b6f --- /dev/null +++ b/repo.protofiles.go @@ -0,0 +1,74 @@ +package gitpb + +import ( + "errors" + "os" + "path/filepath" + "strings" + + "go.wit.com/log" +) + +// This returns the list of autogenerated protobuf files +// it assumes any file *.pb.go is autogenerated +// +// this are made from protoc / proto-gen-go +// these packages also use go.wit.com/apps/autogenpb +// +// errors() if a .proto file does not have an autogenerated .pb.go file +func (repo *Repo) IsProtobuf() (bool, []string, error) { + fullp, fullc, err := scanForProtobuf(repo.FullPath) + protos := make(map[string]string) + protoc := make(map[string]string) + var anyfound bool = false + var allc []string + for _, s := range fullp { + filebase := filepath.Base(s) + name := strings.TrimSuffix(filebase, ".proto") + anyfound = true + protos[name] = s + } + for pname, _ := range protos { + var found bool = false + for _, s := range fullc { + cfilebase := filepath.Base(s) + cname := strings.TrimSuffix(cfilebase, ".pb.go") + protoc[cname] = s + if cname == pname { + found = true + allc = append(allc, cfilebase) + } + } + if found { + // log.Info("found ok") + } else { + log.Info("missing compiled proto file:", pname+"pb.go") + err = errors.New("compiled file " + pname + ".pb.go missing") + } + } + return anyfound, allc, err +} + +func scanForProtobuf(srcDir string) ([]string, []string, error) { + var protofiles []string + var compiled []string + err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error { + if err != nil { + log.Log(GITPBWARN, "Error accessing path:", path, err) + return err + } + + if strings.HasSuffix(path, ".proto") { + // + protofiles = append(protofiles, path) + } + + if strings.HasSuffix(path, ".pb.go") { + compiled = append(compiled, path) + } + + return nil + }) + + return protofiles, compiled, err +}