summaryrefslogtreecommitdiffstats
path: root/routes/git.go
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2024-02-19 23:49:34 +0000
committerLibravatar cel 🌸 <cel@blos.sm>2024-02-19 23:49:34 +0000
commitac0983a89692534daa3d36dba528461b5bb32dbc (patch)
treecc1ced6b3098192f9009cc4f1337da7014b49bd0 /routes/git.go
parent3c1b8007b6d5992e6bffc701ad06e0adec717145 (diff)
downloadlegit-ac0983a89692534daa3d36dba528461b5bb32dbc.tar.gz
legit-ac0983a89692534daa3d36dba528461b5bb32dbc.tar.bz2
legit-ac0983a89692534daa3d36dba528461b5bb32dbc.zip
support categories
Diffstat (limited to 'routes/git.go')
-rw-r--r--routes/git.go38
1 files changed, 30 insertions, 8 deletions
diff --git a/routes/git.go b/routes/git.go
index 1a5e035..5cde6f1 100644
--- a/routes/git.go
+++ b/routes/git.go
@@ -18,7 +18,12 @@ func (d *deps) InfoRefs(w http.ResponseWriter, r *http.Request) {
name := flow.Param(r.Context(), "name")
name = filepath.Clean(name)
- repo := filepath.Join(d.c.Repo.ScanPath, name)
+ repo := d.c.Repo.ScanPath
+ category := flow.Param(r.Context(), "category")
+ if category != "" {
+ repo = filepath.Join(repo, category)
+ }
+ repo = filepath.Join(repo, name)
w.Header().Set("content-type", "application/x-git-upload-pack-advertisement")
@@ -34,9 +39,15 @@ func (d *deps) InfoRefs(w http.ResponseWriter, r *http.Request) {
srv := server.NewServer(loader)
session, err := srv.NewUploadPackSession(ep, nil)
if err != nil {
- http.Error(w, err.Error(), 500)
- log.Printf("git: %s", err)
- return
+ billyfs := osfs.New(repo + ".git")
+ loader := server.NewFilesystemLoader(billyfs)
+ srv := server.NewServer(loader)
+ session, err = srv.NewUploadPackSession(ep, nil)
+ if err != nil {
+ http.Error(w, err.Error(), 500)
+ log.Printf("git: %s", err)
+ return
+ }
}
ar, err := session.AdvertisedReferencesContext(r.Context())
@@ -64,7 +75,12 @@ func (d *deps) UploadPack(w http.ResponseWriter, r *http.Request) {
name := flow.Param(r.Context(), "name")
name = filepath.Clean(name)
- repo := filepath.Join(d.c.Repo.ScanPath, name)
+ repo := d.c.Repo.ScanPath
+ category := flow.Param(r.Context(), "category")
+ if category != "" {
+ repo = filepath.Join(repo, category)
+ }
+ repo = filepath.Join(repo, name)
w.Header().Set("content-type", "application/x-git-upload-pack-result")
@@ -88,9 +104,15 @@ func (d *deps) UploadPack(w http.ResponseWriter, r *http.Request) {
svr := server.NewServer(loader)
session, err := svr.NewUploadPackSession(ep, nil)
if err != nil {
- http.Error(w, err.Error(), 500)
- log.Printf("git: %s", err)
- return
+ billyfs := osfs.New(repo + ".git")
+ loader := server.NewFilesystemLoader(billyfs)
+ svr := server.NewServer(loader)
+ session, err = svr.NewUploadPackSession(ep, nil)
+ if err != nil {
+ http.Error(w, err.Error(), 500)
+ log.Printf("git: %s", err)
+ return
+ }
}
res, err := session.UploadPack(r.Context(), upr)