aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-12-09 12:59:37 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-12-09 12:59:37 +0100
commit4f16cc925238aae81586e917d26b8ff6b6a340bd (patch)
treee33dd70fa5a27ebe34b2c00f1204abefa1f1f3d6 /plumbing
parent0f74faf7acb716941e462d4234f0d5b196e41f69 (diff)
downloadgo-git-4f16cc925238aae81586e917d26b8ff6b6a340bd.tar.gz
packp/capability: trim spaces on capabilities decode. (#170)
git 1.8 used to write a leading space in the capabilities announcement for git-receive-pack. We now trim spaces before decoding a capabilities list to be more tolerant about this kind of difference.
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/protocol/packp/capability/list.go5
-rw-r--r--plumbing/protocol/packp/capability/list_test.go9
2 files changed, 14 insertions, 0 deletions
diff --git a/plumbing/protocol/packp/capability/list.go b/plumbing/protocol/packp/capability/list.go
index 7197d36..2847580 100644
--- a/plumbing/protocol/packp/capability/list.go
+++ b/plumbing/protocol/packp/capability/list.go
@@ -48,6 +48,11 @@ func (l *List) IsEmpty() bool {
// Decode decodes list of capabilities from raw into the list
func (l *List) Decode(raw []byte) error {
+ // git 1.x receive pack used to send a leading space on its
+ // git-receive-pack capabilities announcement. We just trim space to be
+ // tolerant to space changes in different versions.
+ raw = bytes.TrimSpace(raw)
+
if len(raw) == 0 {
return nil
}
diff --git a/plumbing/protocol/packp/capability/list_test.go b/plumbing/protocol/packp/capability/list_test.go
index d6aac16..42f0179 100644
--- a/plumbing/protocol/packp/capability/list_test.go
+++ b/plumbing/protocol/packp/capability/list_test.go
@@ -27,6 +27,15 @@ func (s *SuiteCapabilities) TestDecode(c *check.C) {
c.Assert(cap.Get(ThinPack), check.IsNil)
}
+func (s *SuiteCapabilities) TestDecodeWithLeadingSpace(c *check.C) {
+ cap := NewList()
+ err := cap.Decode([]byte(" report-status"))
+ c.Assert(err, check.IsNil)
+
+ c.Assert(cap.m, check.HasLen, 1)
+ c.Assert(cap.Supports(ReportStatus), check.Equals, true)
+}
+
func (s *SuiteCapabilities) TestDecodeEmpty(c *check.C) {
cap := NewList()
err := cap.Decode(nil)