test commit
This commit is contained in:
@@ -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})
|
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) {
|
func (h *RepoHandler) Commits(w http.ResponseWriter, r *http.Request) {
|
||||||
repo, ok := h.lookupRepo(w, r)
|
repo, ok := h.lookupRepo(w, r)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ func New(cfg *config.Config, engine *xorm.Engine, store sessions.Store, staticFi
|
|||||||
r.Get("/tree", repoH.Tree)
|
r.Get("/tree", repoH.Tree)
|
||||||
r.Get("/blob", repoH.Blob)
|
r.Get("/blob", repoH.Blob)
|
||||||
r.Get("/commits", repoH.Commits)
|
r.Get("/commits", repoH.Commits)
|
||||||
|
r.Get("/branches", repoH.Branches)
|
||||||
r.Get("/diff", repoH.Diff)
|
r.Get("/diff", repoH.Diff)
|
||||||
r.Route("/pulls", func(r chi.Router) {
|
r.Route("/pulls", func(r chi.Router) {
|
||||||
r.Get("/", prH.List)
|
r.Get("/", prH.List)
|
||||||
|
|||||||
@@ -162,6 +162,27 @@ func TreeLS(repoPath, ref, subPath string) ([]TreeEntry, error) {
|
|||||||
return entries, nil
|
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) {
|
func BlobCat(repoPath, ref, filePath string) ([]byte, error) {
|
||||||
return run(repoPath, "show", ref+":"+filePath)
|
return run(repoPath, "show", ref+":"+filePath)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user