diff options
-rw-r--r-- | clients/common/common.go | 5 | ||||
-rw-r--r-- | clients/common/common_test.go | 7 | ||||
-rw-r--r-- | commit.go | 13 | ||||
-rw-r--r-- | commit_test.go | 16 | ||||
-rw-r--r-- | repository_test.go | 11 |
5 files changed, 50 insertions, 2 deletions
diff --git a/clients/common/common.go b/clients/common/common.go index ef35440..a6f6166 100644 --- a/clients/common/common.go +++ b/clients/common/common.go @@ -99,7 +99,10 @@ func (c *Capabilities) Get(capability string) *Capability { // Set sets a capability removing the values func (c *Capabilities) Set(capability string, values ...string) { - delete(c.m, capability) + if _, ok := c.m[capability]; ok { + delete(c.m, capability) + } + c.Add(capability, values...) } diff --git a/clients/common/common_test.go b/clients/common/common_test.go index dac15b6..c8dafe9 100644 --- a/clients/common/common_test.go +++ b/clients/common/common_test.go @@ -82,6 +82,13 @@ func (s *SuiteCommon) TestCapabilitiesSet(c *C) { c.Assert(cap.Get("symref").Values, DeepEquals, []string{"bar"}) } +func (s *SuiteCommon) TestCapabilitiesSetEmpty(c *C) { + cap := NewCapabilities() + cap.Set("foo", "bar") + + c.Assert(cap.Get("foo").Values, HasLen, 1) +} + func (s *SuiteCommon) TestCapabilitiesAdd(c *C) { cap := NewCapabilities() cap.Add("symref", "foo", "qux") @@ -113,17 +113,28 @@ func (i *CommitIter) Next() (*Commit, error) { type iter struct { ch chan core.Object r *Repository + + IsClosed bool } func newIter(r *Repository) iter { ch := make(chan core.Object, 1) - return iter{ch, r} + return iter{ch: ch, r: r} } func (i *iter) Add(o core.Object) { + if i.IsClosed { + return + } + i.ch <- o } func (i *iter) Close() { + if i.IsClosed { + return + } + + defer func() { i.IsClosed = true }() close(i.ch) } diff --git a/commit_test.go b/commit_test.go new file mode 100644 index 0000000..14c2e74 --- /dev/null +++ b/commit_test.go @@ -0,0 +1,16 @@ +package git + +import ( + . "gopkg.in/check.v1" + "gopkg.in/src-d/go-git.v2/core" +) + +type CommitCommon struct{} + +var _ = Suite(&CommitCommon{}) + +func (s *CommitCommon) TestIterClose(c *C) { + i := &iter{ch: make(chan core.Object, 1)} + i.Close() + i.Close() +} diff --git a/repository_test.go b/repository_test.go index 421160d..a8fe50a 100644 --- a/repository_test.go +++ b/repository_test.go @@ -69,3 +69,14 @@ func (s *SuiteRepository) TestCommits(c *C) { c.Assert(count, Equals, 8) } + +func (s *SuiteRepository) TestCommitIterClosePanic(c *C) { + r, err := NewRepository(RepositoryFixture, nil) + r.Remotes["origin"].upSrv = &MockGitUploadPackService{} + + c.Assert(err, IsNil) + c.Assert(r.Pull("origin", "refs/heads/master"), IsNil) + + commits := r.Commits() + commits.Close() +} |