From fcbb68e3658a7929fe4f7e306fa8e9b602ff48f3 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Fri, 30 Oct 2015 11:07:26 +0100 Subject: client: handly empty repositories --- clients/common/common.go | 13 ++++++++++++- clients/common/common_test.go | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'clients/common') diff --git a/clients/common/common.go b/clients/common/common.go index d29706d..0140847 100644 --- a/clients/common/common.go +++ b/clients/common/common.go @@ -14,7 +14,8 @@ import ( ) var ( - NotFoundErr = errors.New("repository not found") + NotFoundErr = errors.New("repository not found") + EmptyGitUploadPackErr = errors.New("empty git-upload-pack given") ) const GitUploadPackServiceName = "git-upload-pack" @@ -93,6 +94,10 @@ type GitUploadPackInfo struct { func NewGitUploadPackInfo(d *pktline.Decoder) (*GitUploadPackInfo, error) { info := &GitUploadPackInfo{} if err := info.read(d); err != nil { + if err == EmptyGitUploadPackErr { + return nil, NewPermanentError(err) + } + return nil, NewUnexpectedError(err) } @@ -105,6 +110,7 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error { return err } + isEmpty := true r.Refs = map[string]*RemoteHead{} for _, line := range lines { if !r.isValidLine(line) { @@ -117,6 +123,11 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error { } r.readLine(line) + isEmpty = false + } + + if isEmpty { + return EmptyGitUploadPackErr } return nil diff --git a/clients/common/common_test.go b/clients/common/common_test.go index 43faf5b..b397ac9 100644 --- a/clients/common/common_test.go +++ b/clients/common/common_test.go @@ -53,6 +53,12 @@ func (s *SuiteCommon) TestGitUploadPackInfo(c *C) { c.Assert(info.Refs[ref].Name, Equals, "refs/heads/master") } +func (s *SuiteCommon) TestGitUploadPackInfoEmpty(c *C) { + b := bytes.NewBuffer(nil) + _, err := NewGitUploadPackInfo(pktline.NewDecoder(b)) + c.Assert(err, ErrorMatches, "permanent.*empty.*") +} + func (s *SuiteCommon) TestGitUploadPackRequest(c *C) { r := &GitUploadPackRequest{ Want: []internal.Hash{ -- cgit