diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-16 01:36:02 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-16 01:36:02 +0800 |
commit | cab2f0547987fa3ecd32c37971dd0f4df9787465 (patch) | |
tree | dc5ed7909c151db7882e846c7c3f1080ed8f4dbf | |
parent | *: go-humanize is a direct dependency, not indirect (diff) | |
download | forge-cab2f0547987fa3ecd32c37971dd0f4df9787465.tar.gz forge-cab2f0547987fa3ecd32c37971dd0f4df9787465.tar.zst forge-cab2f0547987fa3ecd32c37971dd0f4df9787465.zip |
Show branches
Diffstat (limited to '')
-rw-r--r-- | http_handle_repo_index.go | 12 | ||||
-rw-r--r-- | templates/repo_index.tmpl | 18 |
2 files changed, 30 insertions, 0 deletions
diff --git a/http_handle_repo_index.go b/http_handle_repo_index.go index 6ac9b07..e4a9f5d 100644 --- a/http_handle_repo_index.go +++ b/http_handle_repo_index.go @@ -9,6 +9,7 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/plumbing/storer" "github.com/go-git/go-git/v5/plumbing/object" ) @@ -22,6 +23,8 @@ func handle_repo_index(w http.ResponseWriter, r *http.Request, params map[string var commit_object *object.Commit var tree *object.Tree var notes []string + var branches []string + var branches_ storer.ReferenceIter repo, repo_name, group_path = params["repo"].(*git.Repository), params["repo_name"].(string), params["group_path"].([]string) @@ -34,6 +37,15 @@ func handle_repo_index(w http.ResponseWriter, r *http.Request, params map[string goto no_ref } + branches_, err = repo.Branches() + if err != nil {} + err = branches_.ForEach(func (branch *plumbing.Reference) error { + branches = append(branches, branch.Name().Short()) + return nil + }) + if err != nil {} + params["branches"] = branches + if recent_commits, err = get_recent_commits(repo, ref_hash, 3); err != nil { goto no_ref } diff --git a/templates/repo_index.tmpl b/templates/repo_index.tmpl index d0c65c0..19814cc 100644 --- a/templates/repo_index.tmpl +++ b/templates/repo_index.tmpl @@ -43,6 +43,24 @@ </table> </div> <div class="padding-wrapper"> + <table id="branches" class="rounded"> + <thead> + <tr class="title-row"> + <th colspan="1">Branches</th> + </tr> + </thead> + <tbody> + {{ range .branches }} + <tr> + <td> + <a href="./?branch={{ . }}">{{ . }}</a> + </td> + </tr> + {{ end }} + </tbody> + </table> + </div> + <div class="padding-wrapper"> <p> <a href="contrib/" class="btn-normal">Merge requests</a> </p> |