aboutsummaryrefslogtreecommitdiff
path: root/http_handle_branches.go
diff options
context:
space:
mode:
Diffstat (limited to 'http_handle_branches.go')
-rw-r--r--http_handle_branches.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/http_handle_branches.go b/http_handle_branches.go
new file mode 100644
index 0000000..c7f9d39
--- /dev/null
+++ b/http_handle_branches.go
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// SPDX-FileContributor: Runxi Yu <https://runxiyu.org>
+
+package main
+
+import (
+ "net/http"
+ "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"
+)
+
+func httpHandleRepoBranches(writer http.ResponseWriter, _ *http.Request, params map[string]any) {
+ var repo *git.Repository
+ var repoName string
+ var groupPath []string
+ var err error
+ var notes []string
+ var branches []string
+ var branchesIter storer.ReferenceIter
+
+ repo, repoName, groupPath = params["repo"].(*git.Repository), params["repo_name"].(string), params["group_path"].([]string)
+
+ if strings.Contains(repoName, "\n") || sliceContainsNewlines(groupPath) {
+ notes = append(notes, "Path contains newlines; HTTP Git access impossible")
+ }
+
+ branchesIter, err = repo.Branches()
+ if err == nil {
+ _ = branchesIter.ForEach(func(branch *plumbing.Reference) error {
+ branches = append(branches, branch.Name().Short())
+ return nil
+ })
+ }
+ params["branches"] = branches
+
+ params["http_clone_url"] = genHTTPRemoteURL(groupPath, repoName)
+ params["ssh_clone_url"] = genSSHRemoteURL(groupPath, repoName)
+ params["notes"] = notes
+
+ renderTemplate(writer, "repo_branches", params)
+}