From d6383cd4fadb38bbac2b7e25cbd4aedc974618f9 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Thu, 27 Mar 2025 15:53:06 +0200 Subject: [PATCH] knotserver: git: fetch last commit time against current plumbing.Hash This fixes the bug where paths wouldn't show up in non-default branches. We were running 'git log' against the bare repository that was pointing to the default branch, which would then return no output for that specific path since -- understandably -- the path doesn't exist on the default branch. This change simply passes the current g.h (plumbing.Hash) to 'git log' which resolves the path in that ref. --- knotserver/git/git.go | 2 +- knotserver/git/tree.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/knotserver/git/git.go b/knotserver/git/git.go index a66d370b..45568d57 100644 --- a/knotserver/git/git.go +++ b/knotserver/git/git.go @@ -308,7 +308,7 @@ func (g *GitRepo) LastCommitForPath(path string) (*types.LastCommitInfo, error) } cacheMu.RUnlock() - cmd := exec.Command("git", "-C", g.path, "log", "-1", "--format=%H %ct", "--", path) + cmd := exec.Command("git", "-C", g.path, "log", g.h.String(), "-1", "--format=%H %ct", "--", path) var out bytes.Buffer cmd.Stdout = &out diff --git a/knotserver/git/tree.go b/knotserver/git/tree.go index 1c7f8c49..4ad99745 100644 --- a/knotserver/git/tree.go +++ b/knotserver/git/tree.go @@ -2,6 +2,7 @@ package git import ( "fmt" + "time" "github.com/go-git/go-git/v5/plumbing/object" "tangled.sh/tangled.sh/core/types" @@ -56,7 +57,13 @@ func (g *GitRepo) makeNiceTree(t *object.Tree, parent string) []types.NiceTree { lastCommit, err := g.LastCommitForPath(fpath) if err != nil { fmt.Println("error getting last commit time:", err) - continue + // We don't want to skip the file, so worst case lets just + // populate it with "defaults". + lastCommit = &types.LastCommitInfo{ + Hash: g.h, + Message: "", + When: time.Now(), + } } nts = append(nts, types.NiceTree{ -- 2.51.2