// FetchPack performs a request to the server to fetch a packfile. A reader is // returned with the packfile content. The reader must be closed after reading. func (s *session) FetchPack(req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) { if req.IsEmpty() { return nil, transport.ErrEmptyUploadPackRequest } if err := req.Validate(); err != nil { return nil, err } if _, err := s.AdvertisedReferences(); err != nil { return nil, err } s.packRun = true if err := fetchPack(s.Stdin, s.Stdout, req); err != nil { return nil, err } r, err := ioutil.NonEmptyReader(s.Stdout) if err == ioutil.ErrEmptyReader { if c, ok := s.Stdout.(io.Closer); ok { _ = c.Close() } return nil, transport.ErrEmptyUploadPackRequest } if err != nil { return nil, err } wc := &waitCloser{s.Command} rc := ioutil.NewReadCloser(r, wc) return DecodeUploadPackResponse(rc, req) }
func (s *fetchPackSession) FetchPack(req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) { if req.IsEmpty() { return nil, transport.ErrEmptyUploadPackRequest } if err := req.Validate(); err != nil { return nil, err } url := fmt.Sprintf( "%s/%s", s.endpoint.String(), transport.UploadPackServiceName, ) content, err := uploadPackRequestToReader(req) if err != nil { return nil, err } res, err := s.doRequest(http.MethodPost, url, content) if err != nil { return nil, err } r, err := ioutil.NonEmptyReader(res.Body) if err != nil { if err == ioutil.ErrEmptyReader || err == io.ErrUnexpectedEOF { return nil, transport.ErrEmptyUploadPackRequest } return nil, err } rc := ioutil.NewReadCloser(r, res.Body) return common.DecodeUploadPackResponse(rc, req) }