···
···
func (d *Handle) InfoRefs(w http.ResponseWriter, r *http.Request) {
did := chi.URLParam(r, "did")
name := chi.URLParam(r, "name")
17
-
repo, _ := securejoin.SecureJoin(d.c.Repo.ScanPath, filepath.Join(did, name))
18
+
repoName, err := securejoin.SecureJoin(did, name)
20
+
gitError(w, "repository not found", http.StatusNotFound)
21
+
d.l.Error("git: failed to secure join repo path", "handler", "InfoRefs", "error", err)
19
-
w.Header().Set("content-type", "application/x-git-upload-pack-advertisement")
20
-
w.WriteHeader(http.StatusOK)
25
+
repoPath, err := securejoin.SecureJoin(d.c.Repo.ScanPath, repoName)
27
+
gitError(w, "repository not found", http.StatusNotFound)
28
+
d.l.Error("git: failed to secure join repo path", "handler", "InfoRefs", "error", err)
cmd := service.ServiceCommand{
27
-
if err := cmd.InfoRefs(); err != nil {
28
-
writeError(w, err.Error(), 500)
29
-
d.l.Error("git: failed to execute git-upload-pack (info/refs)", "handler", "InfoRefs", "error", err)
37
+
serviceName := r.URL.Query().Get("service")
38
+
switch serviceName {
39
+
case "git-upload-pack":
40
+
w.Header().Set("content-type", "application/x-git-upload-pack-advertisement")
41
+
w.WriteHeader(http.StatusOK)
43
+
if err := cmd.InfoRefs(); err != nil {
44
+
gitError(w, err.Error(), http.StatusInternalServerError)
45
+
d.l.Error("git: process failed", "handler", "InfoRefs", "service", serviceName, "error", err)
48
+
case "git-receive-pack":
49
+
d.RejectPush(w, r, name)
51
+
gitError(w, fmt.Sprintf("service unsupported: '%s'", serviceName), http.StatusForbidden)
···
96
+
func (d *Handle) RejectPush(w http.ResponseWriter, r *http.Request, unqualifiedRepoName string) {
97
+
// A text/plain response will cause git to print each line of the body
98
+
// prefixed with "remote: ".
99
+
w.Header().Set("content-type", "text/plain; charset=UTF-8")
100
+
w.WriteHeader(http.StatusForbidden)
102
+
fmt.Fprintf(w, "Welcome to Tangled.sh!\n\nPushes are currently only supported over SSH.")
103
+
fmt.Fprintf(w, "\n\n")
106
+
func gitError(w http.ResponseWriter, msg string, status int) {
107
+
w.Header().Set("content-type", "text/plain; charset=UTF-8")
108
+
w.WriteHeader(status)
109
+
fmt.Fprintf(w, "%s\n", msg)