diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-15 03:51:04 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-15 03:51:04 +0200 |
commit | bcb49927a3897eadc29960032c70da29e26d6b58 (patch) | |
tree | 60025a0a59d15e49c6027b1bfd5d6fee5d5d2438 /clients | |
parent | f6fe29c80d11662a169806dcf413ecdedcb28fa3 (diff) | |
download | go-git-bcb49927a3897eadc29960032c70da29e26d6b58.tar.gz |
Repository.Clone and Remote.Fetch remote, local branches and client: correct header read
Diffstat (limited to 'clients')
-rw-r--r-- | clients/common/common.go | 5 | ||||
-rw-r--r-- | clients/http/git_upload_pack.go | 20 | ||||
-rw-r--r-- | clients/http/git_upload_pack_test.go | 16 |
3 files changed, 38 insertions, 3 deletions
diff --git a/clients/common/common.go b/clients/common/common.go index b1a0fe1..c8dc7de 100644 --- a/clients/common/common.go +++ b/clients/common/common.go @@ -287,6 +287,7 @@ func (r *GitUploadPackInfo) Bytes() []byte { type GitUploadPackRequest struct { Wants []core.Hash Haves []core.Hash + Depth int } func (r *GitUploadPackRequest) Want(h ...core.Hash) { @@ -312,6 +313,10 @@ func (r *GitUploadPackRequest) Reader() *strings.Reader { e.AddLine(fmt.Sprintf("have %s", have)) } + if r.Depth != 0 { + e.AddLine(fmt.Sprintf("deepen %d", r.Depth)) + } + e.AddFlush() e.AddLine("done") 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) +} |