diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2015-11-05 01:48:07 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2015-11-05 01:48:07 +0100 |
commit | 1d6b13537129018bc7e866ea42ec835e565c6469 (patch) | |
tree | 5527498133a45fee26e471e4f8be4f35299beedb | |
parent | 6badbeb07eb5cc0b1be201f5d8cc8193e30bcf54 (diff) | |
download | go-git-1d6b13537129018bc7e866ea42ec835e565c6469.tar.gz |
clients: capabilities improvement and info head
-rw-r--r-- | clients/common/common.go | 26 | ||||
-rw-r--r-- | clients/common/common_test.go | 1 |
2 files changed, 23 insertions, 4 deletions
diff --git a/clients/common/common.go b/clients/common/common.go index 9abb8eb..44d8e6a 100644 --- a/clients/common/common.go +++ b/clients/common/common.go @@ -132,13 +132,24 @@ func (c *Capabilities) String() string { var o string for _, key := range c.o { cap := c.m[key] - if len(cap.Values) == 0 { - o += key + " " - } + added := false for _, value := range cap.Values { + if value == "" { + continue + } + + added = true o += fmt.Sprintf("%s=%s ", key, value) } + + if len(cap.Values) == 0 || !added { + o += key + " " + } + } + + if len(o) == 0 { + return o } return o[:len(o)-1] @@ -180,7 +191,7 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error { } if len(r.Capabilities.o) == 0 { - r.Capabilities.Decode(line) + r.decodeHeaderLine(line) continue } @@ -195,6 +206,13 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error { return nil } +func (r *GitUploadPackInfo) decodeHeaderLine(line string) { + parts := strings.SplitN(line, " HEAD", 2) + + r.Head = parts[0] + r.Capabilities.Decode(line) +} + func (r *GitUploadPackInfo) isValidLine(line string) bool { if line[0] == '#' { return false diff --git a/clients/common/common_test.go b/clients/common/common_test.go index 7215c17..9529236 100644 --- a/clients/common/common_test.go +++ b/clients/common/common_test.go @@ -53,6 +53,7 @@ func (s *SuiteCommon) TestGitUploadPackInfo(c *C) { ref := i.Capabilities.SymbolicReference("HEAD") c.Assert(ref, Equals, "refs/heads/master") c.Assert(i.Refs[ref].String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") + c.Assert(i.Head, Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") } func (s *SuiteCommon) TestGitUploadPackInfoEmpty(c *C) { |