diff options
Diffstat (limited to 'clients/http')
-rw-r--r-- | clients/http/git_upload_pack.go | 20 | ||||
-rw-r--r-- | clients/http/git_upload_pack_test.go | 16 |
2 files changed, 33 insertions, 3 deletions
diff --git a/clients/http/git_upload_pack.go b/clients/http/git_upload_pack.go index 96535de..68ec238 100644 --- a/clients/http/git_upload_pack.go +++ b/clients/http/git_upload_pack.go @@ -66,14 +66,28 @@ func (s *GitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.ReadClo return nil, err } - h := make([]byte, 8) - if _, err := res.Body.Read(h); err != nil { - return nil, core.NewUnexpectedError(err) + if err := s.discardResponseInfo(res.Body); err != nil { + return nil, err } return res.Body, nil } +func (s *GitUploadPackService) discardResponseInfo(r io.Reader) error { + decoder := pktline.NewDecoder(r) + for { + line, err := decoder.ReadLine() + if err != nil { + break + } + + if line == "NAK\n" { + break + } + } + + return nil +} func (s *GitUploadPackService) doRequest(method, url string, content *strings.Reader) (*http.Response, error) { var body io.Reader if content != nil { diff --git a/clients/http/git_upload_pack_test.go b/clients/http/git_upload_pack_test.go index 7e8cc36..702f1b2 100644 --- a/clients/http/git_upload_pack_test.go +++ b/clients/http/git_upload_pack_test.go @@ -73,3 +73,19 @@ func (s *RemoteSuite) TestFetch(c *C) { c.Assert(err, IsNil) c.Assert(b, HasLen, 85374) } + +func (s *RemoteSuite) TestFetchMulti(c *C) { + r := NewGitUploadPackService(s.Endpoint) + c.Assert(r.Connect(), IsNil) + + req := &common.GitUploadPackRequest{} + req.Want(core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")) + req.Want(core.NewHash("e8d3ffab552895c19b9fcf7aa264d277cde33881")) + + reader, err := r.Fetch(req) + c.Assert(err, IsNil) + + b, err := ioutil.ReadAll(reader) + c.Assert(err, IsNil) + c.Assert(len(b), HasLen, 85585) +} |