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