summaryrefslogtreecommitdiffstats
path: root/routes/git.go
diff options
context:
space:
mode:
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)