From 359ebce26ee2223fdd05e8a04f75f15415ec0457 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 22 Feb 2024 17:19:29 -0600 Subject: mtime --- branchesBox.go | 2 +- git.go | 17 +++++++++++++++++ modifyBox.go | 5 +---- unix.go | 10 ++++++++++ update.go | 6 +++++- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/branchesBox.go b/branchesBox.go index 669b0d7..96ef42e 100644 --- a/branchesBox.go +++ b/branchesBox.go @@ -44,7 +44,7 @@ func (rs *RepoStatus) makeBranchesBox(parent *gui.Node) { newgrid.NextRow() // runs "git branch --all" - rs.gitBranchAll() + // rs.gitBranchAll() rs.showBranchesButton = newgrid.NewButton("find jcarr and devel", func() { if rs.TagExists("jcarr") { diff --git a/git.go b/git.go index c54ab8c..3dffb97 100644 --- a/git.go +++ b/git.go @@ -20,6 +20,10 @@ func (rs *RepoStatus) GetCurrentBranchVersion() string { return rs.currentVersion.String() } +func (rs *RepoStatus) LastGitPull() (time.Time, error) { + return rs.mtime(".git/FETCH_HEAD") +} + func (rs *RepoStatus) Age() time.Duration { var t *Tag t = rs.NewestTag() @@ -35,6 +39,19 @@ func (rs *RepoStatus) Age() time.Duration { return time.Since(tagTime) } +func (rs *RepoStatus) GitPull() error { + var cmd []string + cmd = append(cmd, "git", "pull") + err, _, output := RunCmd(rs.realPath.String(), cmd) + if err == nil { + log.Log(REPOWARN,"git pull ran", rs.Path()) + log.Log(REPOWARN,"git pull output", output) + } else { + log.Log(REPOWARN,"git pull error", rs.Path(), err) + } + return err +} + /* // this isn't right func (rs *RepoStatus) LastTagAge() (time.Time, string) { diff --git a/modifyBox.go b/modifyBox.go index a7c76b9..ae577a2 100644 --- a/modifyBox.go +++ b/modifyBox.go @@ -40,10 +40,7 @@ func (rs *RepoStatus) drawGitCommands(box *gui.Node) { newgrid.NextRow() newgrid.NewButton("git pull", func() { - var cmd []string - cmd = append(cmd, "git", "pull") - err, b, output := RunCmd(rs.realPath.String(), cmd) - log.Warn("Did git pull here", err, b, output) + rs.GitPull() }) newgrid.NextRow() diff --git a/unix.go b/unix.go index 7d43d54..12ed300 100644 --- a/unix.go +++ b/unix.go @@ -233,6 +233,16 @@ func (rs *RepoStatus) Exists(filename string) bool { return false } +func (rs *RepoStatus) mtime(filename string) (time.Time, error) { + pathf := filepath.Join(rs.Path(), filename) + statf, err := os.Stat(pathf) + if err == nil { + return statf.ModTime(), nil + } + log.Log(REPOWARN, "mtime() error", pathf, err) + return time.Now(), err +} + // returns true if the file exists func Exists(file string) bool { _, err := os.Stat(file) diff --git a/update.go b/update.go index 6e10e93..ed849cf 100644 --- a/update.go +++ b/update.go @@ -11,8 +11,12 @@ import ( func (rs *RepoStatus) gitBranchAll() { err, out := rs.RunCmd([]string{"git", "branch", "--all"}) + log.Log(WARN, "git branch failed string =", rs.String()) + log.Log(WARN, "git branch failed realpath =", rs.realPath.String()) if err != nil { - log.Log(WARN, "git branch failed", rs.String()) + log.Log(WARN, "git branch failed string =", rs.String()) + log.Log(WARN, "git branch failed realpath =", rs.realPath.String()) + return } all := strings.Split(out, "\n") for _, s := range all { -- cgit v1.2.3