fix tree/content routes not using reference param
4 files changed, 16 insertions(+), 7 deletions(-)
changed files
M git/git.go → git/git.go
@@ -213,8 +213,12 @@ return file != nil, nil } -func (g *Repo) FileContent(path string) (string, error) { - c, err := g.r.CommitObject(g.h) +func (g *Repo) FileContent(path string, ref string) (string, error) { + hash, err := g.r.ResolveRevision(plumbing.Revision(ref)) + if err != nil { + return "", fmt.Errorf("resolving rev %s for %s: %w", ref, path, err) + } + c, err := g.r.CommitObject(*hash) if err != nil { return "", fmt.Errorf("commit object: %w", err) }
M git/tree.go → git/tree.go
@@ -4,12 +4,17 @@ import ( "fmt" "strings" + "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" ) -func (g *Repo) FileTree(path string) ([]NiceTree, error) { +func (g *Repo) FileTree(path string, ref string) ([]NiceTree, error) { + hash, err := g.r.ResolveRevision(plumbing.Revision(ref)) + if err != nil { + return nil, fmt.Errorf("resolving rev %s for %s: %w", ref, path, err) + } path = strings.TrimSuffix(path, "/") - c, err := g.r.CommitObject(g.h) + c, err := g.r.CommitObject(*hash) if err != nil { return nil, fmt.Errorf("commit object: %w", err) }
M routes/routes.go → routes/routes.go
@@ -66,7 +66,7 @@ if !found { return d.NotFound(rc) } - files, err := gr.FileTree(treePath) + files, err := gr.FileTree(treePath, ref) if err != nil { return err }@@ -99,7 +99,7 @@ if !found { return d.NotFound(rc) } - contents, err := gr.FileContent(treePath) + contents, err := gr.FileContent(treePath, ref) if err != nil { return err }
M routes/util.go → routes/util.go
@@ -103,7 +103,7 @@ } for _, readme := range d.c.Repo.Readme { ext := filepath.Ext(readme) - content, _ := r.FileContent(readme) + content, _ := r.FileContent(readme, r.MainBranch) if len(content) > 0 { switch ext { case ".md", ".mkd", ".markdown":