From 4bc95ad2684cb42159229b8198aa8a2377f80aa1 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 17 Dec 2024 01:15:31 -0600 Subject: keep isolating use of os.Exec("git") --- checkDirty.go | 56 --------------------- currentVersions.go | 49 ++---------------- gitTag.update.go | 139 ---------------------------------------------------- isTracked.go | 72 --------------------------- reload.go | 68 ++++++++++++++++++++++++- reloadCheckDirty.go | 60 +++++++++++++++++++++++ reloadIsTracked.go | 74 ++++++++++++++++++++++++++++ reloadRepoType.go | 48 ++++++++++++++++++ reloadTags.go | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++ repo.new.go | 2 + repo.proto | 4 ++ repoType.go | 48 ------------------ shell.go | 2 +- 13 files changed, 399 insertions(+), 362 deletions(-) delete mode 100644 checkDirty.go delete mode 100644 gitTag.update.go delete mode 100644 isTracked.go create mode 100644 reloadCheckDirty.go create mode 100644 reloadIsTracked.go create mode 100644 reloadRepoType.go create mode 100644 reloadTags.go delete mode 100644 repoType.go diff --git a/checkDirty.go b/checkDirty.go deleted file mode 100644 index 83b049d..0000000 --- a/checkDirty.go +++ /dev/null @@ -1,56 +0,0 @@ -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 - } - - // dirty if anything but go.mod and go.sum - var bad bool = false - for _, line := range r.Stdout { - parts := strings.Fields(line) - if len(parts) == 2 { - switch parts[1] { - case "go.mod": - case "go.sum": - default: - bad = true - } - } else { - bad = true - } - } - - return bad - -} diff --git a/currentVersions.go b/currentVersions.go index e844831..8b9d16f 100644 --- a/currentVersions.go +++ b/currentVersions.go @@ -14,29 +14,6 @@ import ( "go.wit.com/log" ) -func (repo *Repo) GetLastTag() string { - 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) - 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) - return "" - } - - return result.Stdout[0] -} - func (repo *Repo) GetMasterVersion() string { bname := repo.GetMasterBranchName() v, err := repo.gitVersionByName(bname) @@ -78,6 +55,8 @@ func (repo *Repo) GetUserVersion() string { } } +/* +now tracked in repo.Reload() func (repo *Repo) GetCurrentBranchName() string { r := repo.RunQuiet([]string{"git", "branch", "--show-current"}) output := strings.Join(r.Stdout, "\n") @@ -87,6 +66,7 @@ func (repo *Repo) GetCurrentBranchName() string { } return strings.TrimSpace(output) } +*/ // this is used often. probably move everything to this // returns things like @@ -105,21 +85,6 @@ func (repo *Repo) GetCurrentVersion() string { return bver } -// always spawns 'git' and always should spawn 'git' -func (repo *Repo) GetCurrentBranchVersion() string { - 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.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") @@ -135,13 +100,7 @@ func (repo *Repo) gitDescribeByHash(hash string) (string, 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 + return repo.LastTag } func (repo *Repo) DebianReleaseVersion() string { diff --git a/gitTag.update.go b/gitTag.update.go deleted file mode 100644 index c8a35c3..0000000 --- a/gitTag.update.go +++ /dev/null @@ -1,139 +0,0 @@ -package gitpb - -import ( - "path/filepath" - "slices" - "strings" - "time" - - "go.wit.com/lib/gui/shell" - "go.wit.com/log" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" -) - -// Update repo.Refs from .git/ -func (repo *Repo) UpdateGitTags() error { - // todo: look for changes in the tags? - repo.Tags = new(GitTags) - - tags := []string{"%(objectname)", "%(creatordate)", "%(*authordate)", "%(refname)", "%(subject)"} - format := strings.Join(tags, "_,,,_") - cmd := []string{"git", "for-each-ref", "--sort=taggerdate", "--format", format} - // log.Info("RUNNING:", strings.Join(cmd, " ")) - result := shell.PathRunQuiet(repo.FullPath, cmd) - if result.Error != nil { - log.Warn("git for-each-ref error:", result.Error) - return result.Error - } - - lines := result.Stdout - // reverse the git order - slices.Reverse(lines) - - var refname string - var hash string - var subject string - var ctime *timestamppb.Timestamp - var atime *timestamppb.Timestamp - - for i, line := range lines { - var parts []string - parts = make([]string, 0) - parts = strings.Split(line, "_,,,_") - if len(parts) != 5 { - log.Info("tag error:", i, parts) - continue - } - hash = parts[0] - if parts[1] != "" { - tmp := getGitDateStamp(parts[1]) - ctime = timestamppb.New(tmp) - } - if parts[2] != "" { - tmp := getGitDateStamp(parts[2]) - atime = timestamppb.New(tmp) - } - refname = parts[3] - subject = parts[4] - - newr := GitTag{ - Refname: refname, - Hash: hash, - Subject: subject, - Creatordate: ctime, - Authordate: atime, - } - - repo.Tags.Append(&newr) - } - return nil -} - -// converts a git for-each-ref date. "Wed Feb 7 10:13:38 2024 -0600" -func getGitDateStamp(gitdefault string) time.Time { - // now := time.Now().Format("Wed Feb 7 10:13:38 2024 -0600") - const gitLayout = "Mon Jan 2 15:04:05 2006 -0700" - tagTime, err := time.Parse(gitLayout, gitdefault) - if err != nil { - log.Warn("GOT THIS IN PARSE AAA." + gitdefault + ".AAA") - log.Warn(err) - return time.Now() - } - return tagTime -} - -func (tag *GitTag) GetAge() time.Duration { - return time.Since(tag.GetAuthordate().AsTime()) -} - -func (repo *Repo) NewestTag() *GitTag { - loop := repo.Tags.SortByAge() - for loop.Scan() { - r := loop.Next() - return r - } - return nil -} - -func (repo *Repo) LocalTagExists(findname string) bool { - loop := repo.Tags.SortByRefname() - for loop.Scan() { - ref := loop.Next() - // log.Info(repo.GoPath, ref.Refname) - if strings.HasPrefix(ref.Refname, "refs/remotes") { - continue - } - _, tagname := filepath.Split(ref.Refname) - // log.Info("tag:", path, tagname, "from", repo.GoPath) - if tagname == findname { - // log.Info("found tag:", path, tagname, "from", repo.GoPath) - return true - } - } - return false -} - -// returns true if 'taggy' is _ONLY_ a local tag -// this means you can not do a git pull or git push on it -func (repo *Repo) IsOnlyLocalTag(taggy string) bool { - // first make sure the tag is actually even local - if !repo.LocalTagExists(taggy) { - // this means it's not even local now. - return false - } - // okay, taggy exists, does it exist in a remote repo? - loop := repo.Tags.SortByRefname() - for loop.Scan() { - ref := loop.Next() - tagname := ref.Refname - if strings.HasPrefix(tagname, "refs/remotes") { - path, filename := filepath.Split(tagname) - if filename == taggy { - log.Log(GITPB, "found tag:", path, filename, "from", repo.GetGoPath()) - return false - } - } - } - // we couldn't find the local tag anywhere remote, so it's probably only local - return true -} diff --git a/isTracked.go b/isTracked.go deleted file mode 100644 index b15db02..0000000 --- a/isTracked.go +++ /dev/null @@ -1,72 +0,0 @@ -package gitpb - -import ( - "errors" - "fmt" - - "go.wit.com/log" -) - -func (repo *Repo) isTracked(file string) (bool, error) { - cmd := []string{"git", "ls-files", "--error-unmatch", file} - result := repo.Run(cmd) - if result.Error != nil { - return false, result.Error - } - if result.Exit != 0 { - return false, nil - } - return true, nil -} - -func (repo *Repo) isIgnored(file string) (bool, error) { - cmd := []string{"git", "check-ignore", "-q", file} - result := repo.Run(cmd) - if result.Error != nil { - return false, result.Error - } - if result.Exit == 0 { - // exit with 0 means the file is ignored - return true, nil - } - // non-zero exit means the file is not ignored - return false, nil -} - -// is it a good idea to run go-mod-clean in this repo? -// for now, check if this repo should be ignored -// TODO: go.mod and go.sum should be moved to git tag metadata -func (repo *Repo) RepoIgnoresGoMod() error { - file := "go.mod" - if tracked, err := repo.isTracked(file); err != nil { - msg := fmt.Sprintf("%s Error checking if %s tracked: %v\n", repo.GoPath, file, err) - log.Info("gitpb:", msg) - return err - } else { - if tracked { - msg := fmt.Sprintf("%s %s is tracked by Git.\n", repo.GoPath, file) - log.Info("gitpb:", msg) - return errors.New(msg) - } - } - - if ignored, err := repo.isIgnored(file); err != nil { - if err != nil { - msg := fmt.Sprintf("%s Error checking if ignored: %v\n", repo.GoPath, err) - log.Info("gitpb:", msg) - return err - } - } else { - if ignored { - fmt.Printf("%s %s is ignored by Git.\n", repo.GoPath, file) - return nil - } - } - msg := fmt.Sprintf("%s %s is neither tracked nor ignored by Git.\n", repo.GoPath, file) - // this means, if you make a go.mod file, it'll add it to the repo to be tracked - // so you need to either add it to .gitignore (this is what should happen) - // or accept you want an auto-generated file to put endless garbage in your git repo - // this obviously exposes my opinion on this subject matter - log.Info("gitpb:", msg) - return errors.New(msg) -} diff --git a/reload.go b/reload.go index 7a8c212..7c910d3 100644 --- a/reload.go +++ b/reload.go @@ -1,14 +1,27 @@ package gitpb +import ( + "strings" + + "go.wit.com/log" +) + func (repo *Repo) Reload() error { repo.Tags = new(GitTags) - repo.UpdateGitTags() + repo.reloadGitTags() + repo.GoDeps = new(GoDeps) repo.ParseGoSum() if repo.GoInfo != nil { repo.ReloadGo() } + + repo.setLastTag() + repo.setCurrentBranchName() + + // everything has been checked, now save the mtime's + repo.RepoChanged() return nil } @@ -37,3 +50,56 @@ func (repo *Repo) SetDevelBranchName(bname string) { 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.GoPath) + 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.GoPath) + log.Log(GITPBWARN, "GetCurrentBranchVersion() output might have worked anyway:", output) + } + repo.CurrentBranchVersion = strings.TrimSpace(output) +} diff --git a/reloadCheckDirty.go b/reloadCheckDirty.go new file mode 100644 index 0000000..c865c21 --- /dev/null +++ b/reloadCheckDirty.go @@ -0,0 +1,60 @@ +package gitpb + +// runs git, parses output +// types faster than you can + +import ( + "fmt" + "strings" + "time" + + "go.wit.com/lib/gui/shell" + "go.wit.com/log" + "google.golang.org/protobuf/types/known/timestamppb" +) + +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 + } + + // dirty if anything but go.mod and go.sum + var bad bool = false + for _, line := range r.Stdout { + parts := strings.Fields(line) + if len(parts) == 2 { + switch parts[1] { + case "go.mod": + case "go.sum": + default: + bad = true + } + } else { + bad = true + } + } + + pbnow := timestamppb.New(time.Now()) + repo.Times.LastDirty = pbnow + return bad + +} diff --git a/reloadIsTracked.go b/reloadIsTracked.go new file mode 100644 index 0000000..9e44b2a --- /dev/null +++ b/reloadIsTracked.go @@ -0,0 +1,74 @@ +package gitpb + +import ( + "errors" + "fmt" + + "go.wit.com/log" +) + +func (repo *Repo) isTracked(file string) (bool, error) { + cmd := []string{"git", "ls-files", "--error-unmatch", file} + result := repo.Run(cmd) + if result.Error != nil { + return false, result.Error + } + if result.Exit != 0 { + return false, nil + } + return true, nil +} + +func (repo *Repo) isIgnored(file string) (bool, error) { + cmd := []string{"git", "check-ignore", "-q", file} + result := repo.Run(cmd) + if result.Error != nil { + return false, result.Error + } + if result.Exit == 0 { + // exit with 0 means the file is ignored + return true, nil + } + // non-zero exit means the file is not ignored + return false, nil +} + +// is it a good idea to run go-mod-clean in this repo? +// for now, check if this repo should be ignored +// TODO: go.mod and go.sum should be moved to git tag metadata +func (repo *Repo) RepoIgnoresGoMod() error { + repo.GoInfo.GitIgnoresGoSum = false + file := "go.mod" + if tracked, err := repo.isTracked(file); err != nil { + msg := fmt.Sprintf("%s Error checking if %s tracked: %v\n", repo.GoPath, file, err) + log.Info("gitpb:", msg) + return err + } else { + if tracked { + msg := fmt.Sprintf("%s %s is tracked by Git.\n", repo.GoPath, file) + log.Info("gitpb:", msg) + return errors.New(msg) + } + } + + if ignored, err := repo.isIgnored(file); err != nil { + if err != nil { + msg := fmt.Sprintf("%s Error checking if ignored: %v\n", repo.GoPath, err) + log.Info("gitpb:", msg) + return err + } + } else { + if ignored { + fmt.Printf("%s %s is ignored by Git.\n", repo.GoPath, file) + repo.GoInfo.GitIgnoresGoSum = true + return nil + } + } + msg := fmt.Sprintf("%s %s is neither tracked nor ignored by Git.\n", repo.GoPath, file) + // this means, if you make a go.mod file, it'll add it to the repo to be tracked + // so you need to either add it to .gitignore (this is what should happen) + // or accept you want an auto-generated file to put endless garbage in your git repo + // this obviously exposes my opinion on this subject matter + log.Info("gitpb:", msg) + return errors.New(msg) +} diff --git a/reloadRepoType.go b/reloadRepoType.go new file mode 100644 index 0000000..52846d2 --- /dev/null +++ b/reloadRepoType.go @@ -0,0 +1,48 @@ +package gitpb + +// does processing on the go.mod and go.sum files + +import ( + "os" + "strings" + + "go.wit.com/log" +) + +func (repo *Repo) RepoType() string { + if repo == nil { + return "nil" + } + if repo.GetGoPlugin() { + return "plugin" + } + if repo.GetGoBinary() { + if repo.Exists(".plugin") { + return "plugin" + } + return "binary" + } + if ok, _, _ := repo.IsProtobuf(); ok { + return "protobuf" + } + if repo.GetGoLibrary() { + return "library" + } + return "" +} + +func (repo *Repo) goListRepoType() string { + os.Setenv("GO111MODULE", "off") + cmd := []string{"go", "list", "-f", "'{{if eq .Name \"main\"}}binary{{else}}library{{end}}'"} + // cmd := []string{"go", "list", "-f", "'{{.Name}}'"} // probably use this. this just prints out the package name + // cmd := []string{"go", "list", "-f", "'{{.ImportPath}}'"} // returns go.wit.com/lib/protobuf/gitpb + + result := repo.RunQuiet(cmd) + if result.Error != nil { + log.Warn("go list binary detect failed", result.Error) + return "" + } + output := strings.TrimSpace(strings.Join(result.Stdout, "\n")) + output = strings.Trim(output, "'") + return output +} diff --git a/reloadTags.go b/reloadTags.go new file mode 100644 index 0000000..e8409dc --- /dev/null +++ b/reloadTags.go @@ -0,0 +1,139 @@ +package gitpb + +import ( + "path/filepath" + "slices" + "strings" + "time" + + "go.wit.com/lib/gui/shell" + "go.wit.com/log" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" +) + +// reload the tags +func (repo *Repo) reloadGitTags() error { + // todo: look for changes in the tags? + repo.Tags = new(GitTags) + + tags := []string{"%(objectname)", "%(creatordate)", "%(*authordate)", "%(refname)", "%(subject)"} + format := strings.Join(tags, "_,,,_") + cmd := []string{"git", "for-each-ref", "--sort=taggerdate", "--format", format} + // log.Info("RUNNING:", strings.Join(cmd, " ")) + result := shell.PathRunQuiet(repo.FullPath, cmd) + if result.Error != nil { + log.Warn("git for-each-ref error:", result.Error) + return result.Error + } + + lines := result.Stdout + // reverse the git order + slices.Reverse(lines) + + var refname string + var hash string + var subject string + var ctime *timestamppb.Timestamp + var atime *timestamppb.Timestamp + + for i, line := range lines { + var parts []string + parts = make([]string, 0) + parts = strings.Split(line, "_,,,_") + if len(parts) != 5 { + log.Info("tag error:", i, parts) + continue + } + hash = parts[0] + if parts[1] != "" { + tmp := getGitDateStamp(parts[1]) + ctime = timestamppb.New(tmp) + } + if parts[2] != "" { + tmp := getGitDateStamp(parts[2]) + atime = timestamppb.New(tmp) + } + refname = parts[3] + subject = parts[4] + + newr := GitTag{ + Refname: refname, + Hash: hash, + Subject: subject, + Creatordate: ctime, + Authordate: atime, + } + + repo.Tags.Append(&newr) + } + return nil +} + +// converts a git for-each-ref date. "Wed Feb 7 10:13:38 2024 -0600" +func getGitDateStamp(gitdefault string) time.Time { + // now := time.Now().Format("Wed Feb 7 10:13:38 2024 -0600") + const gitLayout = "Mon Jan 2 15:04:05 2006 -0700" + tagTime, err := time.Parse(gitLayout, gitdefault) + if err != nil { + log.Warn("GOT THIS IN PARSE AAA." + gitdefault + ".AAA") + log.Warn(err) + return time.Now() + } + return tagTime +} + +func (tag *GitTag) GetAge() time.Duration { + return time.Since(tag.GetAuthordate().AsTime()) +} + +func (repo *Repo) NewestTag() *GitTag { + loop := repo.Tags.SortByAge() + for loop.Scan() { + r := loop.Next() + return r + } + return nil +} + +func (repo *Repo) LocalTagExists(findname string) bool { + loop := repo.Tags.SortByRefname() + for loop.Scan() { + ref := loop.Next() + // log.Info(repo.GoPath, ref.Refname) + if strings.HasPrefix(ref.Refname, "refs/remotes") { + continue + } + _, tagname := filepath.Split(ref.Refname) + // log.Info("tag:", path, tagname, "from", repo.GoPath) + if tagname == findname { + // log.Info("found tag:", path, tagname, "from", repo.GoPath) + return true + } + } + return false +} + +// returns true if 'taggy' is _ONLY_ a local tag +// this means you can not do a git pull or git push on it +func (repo *Repo) IsOnlyLocalTag(taggy string) bool { + // first make sure the tag is actually even local + if !repo.LocalTagExists(taggy) { + // this means it's not even local now. + return false + } + // okay, taggy exists, does it exist in a remote repo? + loop := repo.Tags.SortByRefname() + for loop.Scan() { + ref := loop.Next() + tagname := ref.Refname + if strings.HasPrefix(tagname, "refs/remotes") { + path, filename := filepath.Split(tagname) + if filename == taggy { + log.Log(GITPB, "found tag:", path, filename, "from", repo.GetGoPath()) + return false + } + } + } + // we couldn't find the local tag anywhere remote, so it's probably only local + return true +} diff --git a/repo.new.go b/repo.new.go index 10b5fcb..ca224e2 100644 --- a/repo.new.go +++ b/repo.new.go @@ -27,6 +27,8 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) { newr := Repo{ FullPath: fullpath, } + newr.Times = new(GitTimes) + newr.GoInfo = new(GoInfo) newr.GoInfo.GoPath = gopath diff --git a/repo.proto b/repo.proto index 71f3010..6730af9 100644 --- a/repo.proto +++ b/repo.proto @@ -39,6 +39,9 @@ message Repo { // `autogenpb:marshal` GitTimes times = 25; // store all the mtime values here. these are temporary GoInfo goInfo = 26; // put all the go specifcs here string stateChange = 27; // reason for state change + string lastTag = 28; // the oldest tag + string currentBranchName = 29; // the branch currently checked out + string currentBranchVersion = 30; // the branch currently checked out } message Repos { // `autogenpb:marshal` @@ -71,4 +74,5 @@ message GoInfo { GoDeps published = 9; // the last published go.mod/go.sum bytes goMod = 10; // the last go.mod file bytes goSum = 11; // the last go.sum file + bool gitIgnoresGoSum = 12; // does .gitignore ignore go.mod & go.sum? } diff --git a/repoType.go b/repoType.go deleted file mode 100644 index 52846d2..0000000 --- a/repoType.go +++ /dev/null @@ -1,48 +0,0 @@ -package gitpb - -// does processing on the go.mod and go.sum files - -import ( - "os" - "strings" - - "go.wit.com/log" -) - -func (repo *Repo) RepoType() string { - if repo == nil { - return "nil" - } - if repo.GetGoPlugin() { - return "plugin" - } - if repo.GetGoBinary() { - if repo.Exists(".plugin") { - return "plugin" - } - return "binary" - } - if ok, _, _ := repo.IsProtobuf(); ok { - return "protobuf" - } - if repo.GetGoLibrary() { - return "library" - } - return "" -} - -func (repo *Repo) goListRepoType() string { - os.Setenv("GO111MODULE", "off") - cmd := []string{"go", "list", "-f", "'{{if eq .Name \"main\"}}binary{{else}}library{{end}}'"} - // cmd := []string{"go", "list", "-f", "'{{.Name}}'"} // probably use this. this just prints out the package name - // cmd := []string{"go", "list", "-f", "'{{.ImportPath}}'"} // returns go.wit.com/lib/protobuf/gitpb - - result := repo.RunQuiet(cmd) - if result.Error != nil { - log.Warn("go list binary detect failed", result.Error) - return "" - } - output := strings.TrimSpace(strings.Join(result.Stdout, "\n")) - output = strings.Trim(output, "'") - return output -} diff --git a/shell.go b/shell.go index 3d15eee..ce000e5 100644 --- a/shell.go +++ b/shell.go @@ -77,7 +77,7 @@ func (repo *Repo) Exists(filename string) bool { return true } -func (repo *Repo) IsValid() bool { +func (repo *Repo) IsValidDir() bool { if repo == nil { return false } -- cgit v1.2.3