Home

ugit @6e497c3b7a113e7d0f90d47b25c44cf3183b1f13 - refs - log -
-
https://git.jolheiser.com/ugit.git
The code powering this h*ckin' site
ugit / internal / http / git.go
- raw
 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
package http

import (
	"errors"
	"net/http"

	"go.jolheiser.com/ugit/internal/git"
	"go.jolheiser.com/ugit/internal/http/httperr"
)

func (rh repoHandler) infoRefs(w http.ResponseWriter, r *http.Request) error {
	if r.URL.Query().Get("service") != "git-upload-pack" {
		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)
	protocol, err := git.NewProtocol(repo.Path())
	if err != nil {
		return httperr.Error(err)
	}
	if err := protocol.HTTPInfoRefs(Session{
		w: w,
		r: r,
	}); err != nil {
		return httperr.Error(err)
	}

	return nil
}

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)
	protocol, err := git.NewProtocol(repo.Path())
	if err != nil {
		return httperr.Error(err)
	}
	if err := protocol.HTTPUploadPack(Session{
		w: w,
		r: r,
	}); err != nil {
		return httperr.Error(err)
	}

	return nil
}