Add git http-backend CGI wrapper
DDavid committed on 2026-06-28 01:05 commit c8bfb00
internal/infra/git/http_backend.go +34 −0
+package git
+
+import (
+ "net/http"
+ "net/http/cgi"
+ "os/exec"
+ "path/filepath"
+ "strings"
+)
+
+type Backend struct {
+ reposDir string
+ httpBackend string
+}
+
+func NewBackend(reposDir string) (*Backend, error) {
+ out, err := exec.Command("git", "--exec-path").Output()
+ if err != nil {
+ return nil, err
+ }
+ bin := filepath.Join(strings.TrimSpace(string(out)), "git-http-backend")
+ return &Backend{reposDir: reposDir, httpBackend: bin}, nil
+}
+
+func (b *Backend) Handler(remoteUser string) http.Handler {
+ return &cgi.Handler{
+ Path: b.httpBackend,
+ Env: []string{
+ "GIT_PROJECT_ROOT=" + b.reposDir,
+ "GIT_HTTP_EXPORT_ALL=1",
+ "REMOTE_USER=" + remoteUser,
+ },
+ }
+}