aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clients/common/common.go23
-rw-r--r--clients/common/common_test.go17
-rw-r--r--clients/http/common.go1
-rw-r--r--clients/http/git_upload_pack.go1
-rw-r--r--common_test.go2
5 files changed, 29 insertions, 15 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,
diff --git a/clients/http/common.go b/clients/http/common.go
index fc3a236..f0f2e6b 100644
--- a/clients/http/common.go
+++ b/clients/http/common.go
@@ -6,6 +6,7 @@ import (
"net/http"
"gopkg.in/src-d/go-git.v2/clients/common"
+
"gopkg.in/src-d/go-git.v2/core"
)
diff --git a/clients/http/git_upload_pack.go b/clients/http/git_upload_pack.go
index 217e4aa..2d38d42 100644
--- a/clients/http/git_upload_pack.go
+++ b/clients/http/git_upload_pack.go
@@ -85,7 +85,6 @@ func (s *GitUploadPackService) doRequest(method, url string, content *strings.Re
s.applyAuthToRequest(req)
res, err := s.Client.Do(req)
-
if err != nil {
return nil, core.NewUnexpectedError(err)
}
diff --git a/common_test.go b/common_test.go
index 03f027c..cf4fc29 100644
--- a/common_test.go
+++ b/common_test.go
@@ -33,7 +33,7 @@ func (s *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
return &common.GitUploadPackInfo{
Capabilities: cap,
- Head: "refs/heads/master",
+ Head: hash,
Refs: map[string]core.Hash{"refs/heads/master": hash},
}, nil
}