aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packp
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-11-25 09:25:49 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-11-25 09:25:49 +0100
commit9e34f68d980de57631c588aaa910c9ea95ed7c2e (patch)
treeb1bd9f867b757ca46ada2f349d122723dde3529c /plumbing/format/packp
parent8966c042795509ed17730e50d352ad69901c3da8 (diff)
downloadgo-git-9e34f68d980de57631c588aaa910c9ea95ed7c2e.tar.gz
plumbing/transport: add common tests and fixes. (#136)
* plumbing/transport: add common tests and fixes. * add common test suite for different transport implementations. * fix different behaviour on error handling for ssh and http. fixes issue #123. * support detecting unexisting repositories with SSH + GitHub/Bitbucket (apparently, there is no standard for all SSH servers). * remove ssh.NewClient (only DefaultClient makes sense at the moment). * make ssh.Client and http.Client private. * utils/ioutil: utilities to work with io interfaces. * * transport: test actual objects fetched, not just packfile size. * * fix doc typo. * * improve UploadPackRequest.IsEmpty
Diffstat (limited to 'plumbing/format/packp')
-rw-r--r--plumbing/format/packp/advrefs/decoder.go12
-rw-r--r--plumbing/format/packp/advrefs/decoder_test.go26
2 files changed, 38 insertions, 0 deletions
diff --git a/plumbing/format/packp/advrefs/decoder.go b/plumbing/format/packp/advrefs/decoder.go
index b654882..c50eeef 100644
--- a/plumbing/format/packp/advrefs/decoder.go
+++ b/plumbing/format/packp/advrefs/decoder.go
@@ -86,6 +86,12 @@ func decodePrefix(d *Decoder) decoderStateFn {
return nil
}
+ // If the repository is empty, we receive a flush here (SSH).
+ if isFlush(d.line) {
+ d.err = ErrEmpty
+ return nil
+ }
+
if isPrefix(d.line) {
tmp := make([]byte, len(d.line))
copy(tmp, d.line)
@@ -117,6 +123,12 @@ func isFlush(payload []byte) bool {
// list-of-refs is comming, and the hash will be followed by the first
// advertised ref.
func decodeFirstHash(p *Decoder) decoderStateFn {
+ // If the repository is empty, we receive a flush here (HTTP).
+ if isFlush(p.line) {
+ p.err = ErrEmpty
+ return nil
+ }
+
if len(p.line) < hashSize {
p.error("cannot read hash, pkt-line too short")
return nil
diff --git a/plumbing/format/packp/advrefs/decoder_test.go b/plumbing/format/packp/advrefs/decoder_test.go
index 03867d3..bacf79a 100644
--- a/plumbing/format/packp/advrefs/decoder_test.go
+++ b/plumbing/format/packp/advrefs/decoder_test.go
@@ -26,6 +26,32 @@ func (s *SuiteDecoder) TestEmpty(c *C) {
c.Assert(err, Equals, advrefs.ErrEmpty)
}
+func (s *SuiteDecoder) TestEmptyFlush(c *C) {
+ ar := advrefs.New()
+ var buf bytes.Buffer
+ e := pktline.NewEncoder(&buf)
+ e.Flush()
+
+ d := advrefs.NewDecoder(&buf)
+
+ err := d.Decode(ar)
+ c.Assert(err, Equals, advrefs.ErrEmpty)
+}
+
+func (s *SuiteDecoder) TestEmptyPrefixFlush(c *C) {
+ ar := advrefs.New()
+ var buf bytes.Buffer
+ e := pktline.NewEncoder(&buf)
+ e.EncodeString("# service=git-upload-pack")
+ e.Flush()
+ e.Flush()
+
+ d := advrefs.NewDecoder(&buf)
+
+ err := d.Decode(ar)
+ c.Assert(err, Equals, advrefs.ErrEmpty)
+}
+
func (s *SuiteDecoder) TestShortForHash(c *C) {
payloads := []string{
"6ecf0ef2c2dffb796",