summaryrefslogtreecommitdiff
path: root/reloadMtime.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-04 04:16:50 -0500
committerJeff Carr <[email protected]>2025-10-04 04:16:50 -0500
commit1ddedc1fa552ab543533e8dfa4dcd16ab3b38da6 (patch)
tree4166a983a09ccc471d20e0af4c26323bc619159e /reloadMtime.go
parentf4caf3ce34e41c7bdb98e945e6bbbd2d8e559d1d (diff)
maybe this will work?v0.0.145
Diffstat (limited to 'reloadMtime.go')
-rw-r--r--reloadMtime.go46
1 files changed, 45 insertions, 1 deletions
diff --git a/reloadMtime.go b/reloadMtime.go
index e3ed1f3..37ad2b6 100644
--- a/reloadMtime.go
+++ b/reloadMtime.go
@@ -4,6 +4,8 @@ package gitpb
import (
"fmt"
+ "os"
+ "path/filepath"
"time"
"go.wit.com/lib/gui/shell"
@@ -13,7 +15,7 @@ import (
func (repo *Repo) Mtime(fname string) *time.Time {
var fileTime *time.Time
- tmp, err := repo.oldMtime(fname)
+ tmp, err := repo.statMtime(fname)
fileTime = &tmp
if err != nil {
log.Info("MTime got err", err)
@@ -22,6 +24,16 @@ func (repo *Repo) Mtime(fname string) *time.Time {
return fileTime
}
+func (repo *Repo) statMtime(filename string) (time.Time, error) {
+ pathf := filepath.Join(repo.FullPath, filename)
+ statf, err := os.Stat(pathf)
+ if err == nil {
+ return statf.ModTime(), nil
+ }
+ log.Log(WARN, "Mtime() os.Stat() error", pathf, err)
+ return time.Now(), err
+}
+
func (repo *Repo) changedDir() bool {
fname := ".git"
fileTime := repo.Mtime(fname)
@@ -189,6 +201,38 @@ func (repo *Repo) reloadMtimes() bool {
return changed
}
+// also checks .git which seems to change *a lot*
+// this might work immediately after git checkout
+func (repo *Repo) DidRepoChangeDir() error {
+ if repo.Times == nil {
+ repo.Times = new(GitTimes)
+ }
+ if repo.didFileChange(".git/HEAD", repo.Times.MtimeHead) {
+ return log.Errorf(".git/HEAD changed")
+ }
+ if repo.didFileChange(".git/index", repo.Times.MtimeIndex) {
+ return log.Errorf(".git/index changed")
+ }
+ if repo.didFileChange(".git/config", repo.Times.MtimeConfig) {
+ return log.Errorf(".git/config changed")
+ }
+ if repo.didFileChange(".git", repo.Times.MtimeDir) {
+ // todo: do something with CheckDirty()
+ return log.Errorf(".git changed")
+ }
+ if repo.Times.LastUpdate == nil {
+ log.Info("repo.Reload() was never run")
+ return log.Errorf("Reload() ran for the first time")
+ } else {
+ if repo.Times.LastUpdate.Seconds < repo.Times.MtimeHead.Seconds {
+ log.Info("SHOULD RUN Reload() here", repo.Times.MtimeHead.Seconds-repo.Times.LastUpdate.Seconds, "secs diff")
+ return log.Errorf("Reload() time skew on .git/HEAD")
+ }
+ }
+ // log.Info("DidRepoChange() is false", repo.FullPath)
+ return nil
+}
+
func (repo *Repo) DidRepoChange() error {
if repo.Times == nil {
repo.Times = new(GitTimes)