From cab2f0547987fa3ecd32c37971dd0f4df9787465 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 16 Mar 2025 01:36:02 +0800 Subject: [PATCH] Show branches --- http_handle_repo_index.go | 12 ++++++++++++ templates/repo_index.tmpl | 18 ++++++++++++++++++ diff --git a/http_handle_repo_index.go b/http_handle_repo_index.go index 6ac9b07e3ee20c01d4fc2a49e0bc7e2acf1c05b9..e4a9f5d6f0d23b75e3522eeb0048d093d1b9ea6c 100644 --- a/http_handle_repo_index.go +++ b/http_handle_repo_index.go @@ -9,6 +9,7 @@ "strings" "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 @@ var recent_commits []*object.Commit 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) @@ -33,6 +36,15 @@ ref_hash, err = get_ref_hash_from_type_and_name(repo, params["ref_type"].(string), params["ref_name"].(string)) if err != nil { 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 d0c65c046b029e0f37547c186a7cba4624f3a382..19814ccc8a038d39be81dc1694bad82742e998a1 100644 --- a/templates/repo_index.tmpl +++ b/templates/repo_index.tmpl @@ -43,6 +43,24 @@
+ + + + + + + + {{ range .branches }} + + + + {{ end }} + +
Branches
+ {{ . }} +
+
+

Merge requests

-- 2.48.1