Mirror of https://git.jolheiser.com/ugit
1package http
2
3import (
4 "errors"
5 "net/http"
6
7 "go.jolheiser.com/ugit/internal/git"
8 "go.jolheiser.com/ugit/internal/http/httperr"
9)
10
11func (rh repoHandler) infoRefs(w http.ResponseWriter, r *http.Request) error {
12 if r.URL.Query().Get("service") != "git-upload-pack" {
13 return httperr.Status(errors.New("pushing isn't supported via HTTP(S), use SSH"), http.StatusBadRequest)
14 }
15
16 w.Header().Set("Content-Type", "application/x-git-upload-pack-advertisement")
17 repo := r.Context().Value(repoCtxKey).(*git.Repo)
18 protocol, err := git.NewProtocol(repo.Path())
19 if err != nil {
20 return httperr.Error(err)
21 }
22 if err := protocol.HTTPInfoRefs(Session{
23 w: w,
24 r: r,
25 }); err != nil {
26 return httperr.Error(err)
27 }
28
29 return nil
30}
31
32func (rh repoHandler) uploadPack(w http.ResponseWriter, r *http.Request) error {
33 w.Header().Set("content-type", "application/x-git-upload-pack-result")
34 repo := r.Context().Value(repoCtxKey).(*git.Repo)
35 protocol, err := git.NewProtocol(repo.Path())
36 if err != nil {
37 return httperr.Error(err)
38 }
39 if err := protocol.HTTPUploadPack(Session{
40 w: w,
41 r: r,
42 }); err != nil {
43 return httperr.Error(err)
44 }
45
46 return nil
47}