From d860d78543c350d3ffbb9baba988d2f6469ae1df Mon Sep 17 00:00:00 2001 From: erangel1 Date: Thu, 7 May 2026 10:34:19 +0200 Subject: [PATCH] test commit --- internal/api/handlers/repos.go | 17 +++++++++++++++++ internal/api/router.go | 1 + internal/domain/git/binary.go | 21 +++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/internal/api/handlers/repos.go b/internal/api/handlers/repos.go index 5bf4fc0..bc17be2 100644 --- a/internal/api/handlers/repos.go +++ b/internal/api/handlers/repos.go @@ -160,6 +160,23 @@ func (h *RepoHandler) Blob(w http.ResponseWriter, r *http.Request) { jsonOK(w, map[string]string{"content": string(content), "path": path, "ref": ref}) } +func (h *RepoHandler) Branches(w http.ResponseWriter, r *http.Request) { + repo, ok := h.lookupRepo(w, r) + if !ok { + return + } + gitdomain.SetRepoRoot(h.cfg.RepoRoot) + branches, err := gitdomain.Branches(repo.DiskPath) + if err != nil { + jsonError(w, "could not list branches", http.StatusInternalServerError) + return + } + if branches == nil { + branches = []gitdomain.Branch{} + } + jsonOK(w, branches) +} + func (h *RepoHandler) Commits(w http.ResponseWriter, r *http.Request) { repo, ok := h.lookupRepo(w, r) if !ok { diff --git a/internal/api/router.go b/internal/api/router.go index f1f38e5..b95ffe9 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -110,6 +110,7 @@ func New(cfg *config.Config, engine *xorm.Engine, store sessions.Store, staticFi r.Get("/tree", repoH.Tree) r.Get("/blob", repoH.Blob) r.Get("/commits", repoH.Commits) + r.Get("/branches", repoH.Branches) r.Get("/diff", repoH.Diff) r.Route("/pulls", func(r chi.Router) { r.Get("/", prH.List) diff --git a/internal/domain/git/binary.go b/internal/domain/git/binary.go index 43a300a..74b20a6 100644 --- a/internal/domain/git/binary.go +++ b/internal/domain/git/binary.go @@ -162,6 +162,27 @@ func TreeLS(repoPath, ref, subPath string) ([]TreeEntry, error) { return entries, nil } +type Branch struct { + Name string `json:"name"` +} + +func Branches(repoPath string) ([]Branch, error) { + if IsEmpty(repoPath) { + return nil, nil + } + out, err := run(repoPath, "branch", "--format=%(refname:short)") + if err != nil { + return nil, err + } + var branches []Branch + for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") { + if line != "" { + branches = append(branches, Branch{Name: line}) + } + } + return branches, nil +} + func BlobCat(repoPath, ref, filePath string) ([]byte, error) { return run(repoPath, "show", ref+":"+filePath) }