1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
diff --git a/internal/http/http.go b/internal/http/http.go
index 6885cc0df0cae5c7830ae814a2f1ca81e48af3e4..f8ad236202bc90a4c8b74cd03a045f756fa1d05a 100644
--- a/internal/http/http.go
+++ b/internal/http/http.go
@@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"net/url"
+ "strings"
"go.jolheiser.com/ugit/assets"
"go.jolheiser.com/ugit/internal/git"
@@ -61,22 +62,18 @@ mux.Use(middleware.Logger)
mux.Use(middleware.Recoverer)
rh := repoHandler{s: settings}
- mux.Route("/{repo}.git", func(r chi.Router) {
- r.Get("/", func(w http.ResponseWriter, r *http.Request) {
- http.Redirect(w, r, "/"+chi.URLParam(r, "repo"), http.StatusFound)
- })
- r.Get("/info/refs", httperr.Handler(rh.infoRefs))
- r.Post("/git-upload-pack", httperr.Handler(rh.uploadPack))
- })
-
mux.Route("/", func(r chi.Router) {
r.Get("/", httperr.Handler(rh.index))
r.Route("/{repo}", func(r chi.Router) {
r.Use(rh.repoMiddleware)
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
+ repo := r.Context().Value(repoCtxKey).(*git.Repo)
if r.URL.Query().Has("go-get") {
- repo := chi.URLParam(r, "repo")
- w.Write([]byte(settings.goGet(repo)))
+ w.Write([]byte(settings.goGet(repo.Name())))
+ return
+ }
+ if strings.HasSuffix(chi.URLParam(r, "repo"), ".git") {
+ http.Redirect(w, r, "/"+repo.Name(), http.StatusFound)
return
}
rh.repoTree("", "").ServeHTTP(w, r)
@@ -88,6 +85,10 @@ 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))
})
})
|