aboutsummaryrefslogtreecommitdiffstats
path: root/clients
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2015-10-30 11:07:26 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2015-10-30 11:07:26 +0100
commitfcbb68e3658a7929fe4f7e306fa8e9b602ff48f3 (patch)
tree01bbdabbe3cf0a00d86b1d0c44b92dffcb389ad3 /clients
parent419ea1639230c5a7613962cbcbe0eb8b9e1ad078 (diff)
downloadgo-git-fcbb68e3658a7929fe4f7e306fa8e9b602ff48f3.tar.gz
client: handly empty repositories
Diffstat (limited to 'clients')
-rw-r--r--clients/common/common.go13
-rw-r--r--clients/common/common_test.go6
2 files changed, 18 insertions, 1 deletions
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{