aboutsummaryrefslogtreecommitdiff
path: root/internal/unsorted/http_handle_branches.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-04-06 01:55:21 +0800
committerRunxi Yu <me@runxiyu.org>2025-04-06 02:08:58 +0800
commitfaa5ca8fab23176d390e9522f1485d467851545b (patch)
treed3b1d081e0ea5e7f71a94dc1d301e2540a8abcc8 /internal/unsorted/http_handle_branches.go
parentSlight refactor on NewServer (diff)
downloadforge-0.1.28.tar.gz
forge-0.1.28.tar.zst
forge-0.1.28.zip
Move stuff into internal/unsortedv0.1.28
Diffstat (limited to 'internal/unsorted/http_handle_branches.go')
-rw-r--r--internal/unsorted/http_handle_branches.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/unsorted/http_handle_branches.go b/internal/unsorted/http_handle_branches.go
new file mode 100644
index 0000000..04a9f31
--- /dev/null
+++ b/internal/unsorted/http_handle_branches.go
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
+
+package unsorted
+
+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"
+ "go.lindenii.runxiyu.org/forge/internal/misc"
+)
+
+// httpHandleRepoBranches provides the branches page in repos.
+func (s *Server) 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") || misc.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"] = s.genHTTPRemoteURL(groupPath, repoName)
+ params["ssh_clone_url"] = s.genSSHRemoteURL(groupPath, repoName)
+ params["notes"] = notes
+
+ s.renderTemplate(writer, "repo_branches", params)
+}