diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-10 15:33:04 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-10 15:33:04 +0800 |
commit | 75a6ab8875b5e94731dc7d306d964a0f5ff0b679 (patch) | |
tree | 349d550d44e0733a999ca82be605525ce442afb0 /handle_repo_tree.go | |
parent | repo_tree: Remove unnecessary commit_iter code (diff) | |
download | forge-75a6ab8875b5e94731dc7d306d964a0f5ff0b679.tar.gz forge-75a6ab8875b5e94731dc7d306d964a0f5ff0b679.tar.zst forge-75a6ab8875b5e94731dc7d306d964a0f5ff0b679.zip |
repo_tree: Read ref name from PathValue
Diffstat (limited to 'handle_repo_tree.go')
-rw-r--r-- | handle_repo_tree.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/handle_repo_tree.go b/handle_repo_tree.go index 5a66df6..47d02b4 100644 --- a/handle_repo_tree.go +++ b/handle_repo_tree.go @@ -11,6 +11,7 @@ import ( chroma_lexers "github.com/alecthomas/chroma/v2/lexers" chroma_styles "github.com/alecthomas/chroma/v2/styles" "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" "github.com/microcosm-cc/bluemonday" "github.com/yuin/goldmark" ) @@ -18,20 +19,20 @@ import ( func handle_repo_tree(w http.ResponseWriter, r *http.Request) { data := make(map[string]any) // TODO: Sanitize path values - category_name, repo_name, path_spec := r.PathValue("category_name"), r.PathValue("repo_name"), strings.TrimSuffix(r.PathValue("rest"), "/") + ref_name, category_name, repo_name, path_spec := r.PathValue("ref"), r.PathValue("category_name"), r.PathValue("repo_name"), strings.TrimSuffix(r.PathValue("rest"), "/") data["category_name"], data["repo_name"], data["path_spec"] = category_name, repo_name, path_spec repo, err := git.PlainOpen(filepath.Join(config.Git.Root, category_name, repo_name+".git")) if err != nil { _, _ = w.Write([]byte("Error opening repo: " + err.Error())) return } - head, err := repo.Head() + ref, err := repo.Reference(plumbing.NewBranchReferenceName(ref_name), true) if err != nil { - _, _ = w.Write([]byte("Error getting repo HEAD: " + err.Error())) + _, _ = w.Write([]byte("Error getting repo reference: " + err.Error())) return } - head_hash := head.Hash() - commit_object, err := repo.CommitObject(head_hash) + ref_hash := ref.Hash() + commit_object, err := repo.CommitObject(ref_hash) if err != nil { _, _ = w.Write([]byte("Error getting commit object: " + err.Error())) return |