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/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/checkDirty.go b/reloadCheckDirty.go similarity index 89% rename from checkDirty.go rename to reloadCheckDirty.go index 83b049d..c865c21 100644 --- a/checkDirty.go +++ b/reloadCheckDirty.go @@ -6,9 +6,11 @@ package gitpb 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) { @@ -51,6 +53,8 @@ func (repo *Repo) CheckDirty() bool { } } + pbnow := timestamppb.New(time.Now()) + repo.Times.LastDirty = pbnow return bad } diff --git a/isTracked.go b/reloadIsTracked.go similarity index 96% rename from isTracked.go rename to reloadIsTracked.go index b15db02..9e44b2a 100644 --- a/isTracked.go +++ b/reloadIsTracked.go @@ -37,6 +37,7 @@ func (repo *Repo) isIgnored(file string) (bool, error) { // 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) @@ -59,6 +60,7 @@ func (repo *Repo) RepoIgnoresGoMod() error { } else { if ignored { fmt.Printf("%s %s is ignored by Git.\n", repo.GoPath, file) + repo.GoInfo.GitIgnoresGoSum = true return nil } } diff --git a/repoType.go b/reloadRepoType.go similarity index 100% rename from repoType.go rename to reloadRepoType.go diff --git a/gitTag.update.go b/reloadTags.go similarity index 97% rename from gitTag.update.go rename to reloadTags.go index c8a35c3..e8409dc 100644 --- a/gitTag.update.go +++ b/reloadTags.go @@ -11,8 +11,8 @@ import ( timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) -// Update repo.Refs from .git/ -func (repo *Repo) UpdateGitTags() error { +// reload the tags +func (repo *Repo) reloadGitTags() error { // todo: look for changes in the tags? repo.Tags = new(GitTags) 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/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 }