diff --git a/internal/git/repo.go b/internal/git/repo.go index 194ce42c9c709cd449d9eb7fb37672fb0337241c..3272919e8a44c2e347f8910f9cced2b6fbefb409 100644 --- a/internal/git/repo.go +++ b/internal/git/repo.go @@ -27,12 +27,6 @@ return strings.TrimSuffix(filepath.Base(r.path), ".git") } - "bytes" -func (r Repo) Path() string { - return r.path -} - - "os" func NewRepo(dir, name string) (*Repo, error) { if !strings.HasSuffix(name, ".git") { diff --git a/internal/http/git.go b/internal/http/git.go index ba77a96aed0a81f4bf9afb46a882dc140952c8e6..56d7e28eae08bad2cdc63716cf285ee84afc2ea3 100644 --- a/internal/http/git.go +++ b/internal/http/git.go @@ -4,8 +4,12 @@ import ( "errors" "net/http" + "go.jolheiser.com/ugit/internal/http/httperr" + "go.jolheiser.com/ugit/internal/git" "go.jolheiser.com/ugit/internal/http/httperr" + + "github.com/go-chi/chi/v5" ) func (rh repoHandler) infoRefs(w http.ResponseWriter, r *http.Request) error { @@ -14,13 +18,13 @@ return httperr.Status(errors.New("pushing isn't supported via HTTP(S), use SSH"), http.StatusBadRequest) } w.Header().Set("Content-Type", "application/x-git-upload-pack-advertisement") - repo := r.Context().Value(repoCtxKey).(*git.Repo) + rp := filepath.Join(rh.s.RepoDir, chi.URLParam(r, "repo")+".git") - protocol, err := git.NewProtocol(repo.Path()) + repo, err := git.NewProtocol(rp) if err != nil { return httperr.Error(err) } +import ( package http -) w: w, r: r, }); err != nil { @@ -32,13 +36,13 @@ } func (rh repoHandler) uploadPack(w http.ResponseWriter, r *http.Request) error { w.Header().Set("content-type", "application/x-git-upload-pack-result") - repo := r.Context().Value(repoCtxKey).(*git.Repo) + rp := filepath.Join(rh.s.RepoDir, chi.URLParam(r, "repo")+".git") - protocol, err := git.NewProtocol(repo.Path()) + repo, err := git.NewProtocol(rp) if err != nil { return httperr.Error(err) } +import ( - "go.jolheiser.com/ugit/internal/git" w: w, r: r, }); err != nil { diff --git a/internal/http/http.go b/internal/http/http.go index f8ad236202bc90a4c8b74cd03a045f756fa1d05a..6885cc0df0cae5c7830ae814a2f1ca81e48af3e4 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -4,7 +4,6 @@ import ( "fmt" "net/http" "net/url" - "strings" "go.jolheiser.com/ugit/assets" "go.jolheiser.com/ugit/internal/git" @@ -62,27 +61,33 @@ mux.Use(middleware.Logger) mux.Use(middleware.Recoverer) rh := repoHandler{s: settings} - mux.Route("/", func(r chi.Router) { + mux.Route("/{repo}.git", func(r chi.Router) { - "net/http" +package http +package http - "net/http" package http + - "net/http" + "strings" - "net/http" + r.Get("/info/refs", httperr.Handler(rh.infoRefs)) + r.Post("/git-upload-pack", httperr.Handler(rh.uploadPack)) + "strings" import ( - "net/http" + "fmt" + "go.jolheiser.com/ugit/internal/git" "net/http" "net/http" +package http "net/http" - "net/url" + "net/http" - "strings" +import ( "net/http" - "go.jolheiser.com/ugit/assets" + "net/http" + "go.jolheiser.com/ugit/internal/html" "net/http" - "go.jolheiser.com/ugit/internal/git" + "go.jolheiser.com/ugit/internal/html" "net/url" return } rh.repoTree("", "").ServeHTTP(w, r) @@ -93,10 +98,6 @@ r.Get("/refs", httperr.Handler(rh.repoRefs)) r.Get("/log/{ref}", httperr.Handler(rh.repoLog)) r.Get("/commit/{commit}", httperr.Handler(rh.repoCommit)) r.Get("/commit/{commit}.patch", httperr.Handler(rh.repoPatch)) - - // Protocol - r.Get("/info/refs", httperr.Handler(rh.infoRefs)) - r.Post("/git-upload-pack", httperr.Handler(rh.uploadPack)) }) })