diff options
Diffstat (limited to 'clients/common')
-rw-r--r-- | clients/common/common.go | 23 | ||||
-rw-r--r-- | clients/common/common_test.go | 17 |
2 files changed, 27 insertions, 13 deletions
diff --git a/clients/common/common.go b/clients/common/common.go index 8756cfd..460eb10 100644 --- a/clients/common/common.go +++ b/clients/common/common.go @@ -92,6 +92,17 @@ func (c *Capabilities) Decode(raw string) { } } +// Get returns the values for a capability +func (c *Capabilities) Get(capability string) *Capability { + return c.m[capability] +} + +// Set sets a capability removing the values +func (c *Capabilities) Set(capability string, values ...string) { + delete(c.m, capability) + c.Add(capability, values...) +} + // Add adds a capability, values are optional func (c *Capabilities) Add(capability string, values ...string) { if !c.Supports(capability) { @@ -112,11 +123,6 @@ func (c *Capabilities) Supports(capability string) bool { return ok } -// Get returns the values for a capability -func (c *Capabilities) Get(capability string) *Capability { - return c.m[capability] -} - // SymbolicReference returns the reference for a given symbolic reference func (c *Capabilities) SymbolicReference(sym string) string { if !c.Supports("symref") { @@ -170,7 +176,7 @@ func (c *Capabilities) String() string { type GitUploadPackInfo struct { Capabilities *Capabilities - Head string + Head core.Hash Refs map[string]core.Hash } @@ -221,8 +227,7 @@ func (r *GitUploadPackInfo) read(d *pktline.Decoder) error { func (r *GitUploadPackInfo) decodeHeaderLine(line string) { parts := strings.SplitN(line, " HEAD", 2) - - r.Head = parts[0] + r.Head = core.NewHash(parts[0]) r.Capabilities.Decode(line) } @@ -251,7 +256,7 @@ func (r *GitUploadPackInfo) Bytes() []byte { e := pktline.NewEncoder() e.AddLine("# service=git-upload-pack") e.AddFlush() - e.AddLine(fmt.Sprintf("%s HEAD\x00%s", r.Refs[r.Head].String(), r.Capabilities.String())) + e.AddLine(fmt.Sprintf("%s HEAD\x00%s", r.Head, r.Capabilities.String())) for name, id := range r.Refs { e.AddLine(fmt.Sprintf("%s %s", id, name)) diff --git a/clients/common/common_test.go b/clients/common/common_test.go index 9529236..5ffb402 100644 --- a/clients/common/common_test.go +++ b/clients/common/common_test.go @@ -53,7 +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") + c.Assert(i.Head.String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") } func (s *SuiteCommon) TestGitUploadPackInfoEmpty(c *C) { @@ -73,7 +73,16 @@ func (s *SuiteCommon) TestCapabilitiesDecode(c *C) { c.Assert(cap.Get("thin-pack").Values, DeepEquals, []string{""}) } -func (s *SuiteCommon) TestCapabilitiesString(c *C) { +func (s *SuiteCommon) TestCapabilitiesSet(c *C) { + cap := NewCapabilities() + cap.Add("symref", "foo", "qux") + cap.Set("symref", "bar") + + c.Assert(cap.m, HasLen, 1) + c.Assert(cap.Get("symref").Values, DeepEquals, []string{"bar"}) +} + +func (s *SuiteCommon) TestCapabilitiesAdd(c *C) { cap := NewCapabilities() cap.Add("symref", "foo", "qux") cap.Add("thin-pack") @@ -85,9 +94,9 @@ func (s *SuiteCommon) TestGitUploadPackEncode(c *C) { info := NewGitUploadPackInfo() info.Capabilities.Add("symref", "HEAD:refs/heads/master") - info.Head = "refs/heads/master" + info.Head = core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5") info.Refs = map[string]core.Hash{ - "refs/heads/master": core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), + "refs/heads/master": info.Head, } c.Assert(info.String(), Equals, |