diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-01-11 12:09:15 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-01-11 12:09:15 +0100 |
commit | 37cc5cf842c3c0fb989bcf7525cc8f826d96b295 (patch) | |
tree | ad234af3bd3af78992944858abc2095b3199df44 | |
parent | cebec78608e7913b8c843390237fd609069022ae (diff) | |
parent | 6d19be9bdb355d2285138ead6cd487920b26fe99 (diff) | |
download | go-git-37cc5cf842c3c0fb989bcf7525cc8f826d96b295.tar.gz |
Merge pull request #12 from alcortesm/hotfix-close-packfilev2.1.2
missing call to Close on Fetch return value (ReadCloser)
-rw-r--r-- | common_test.go | 6 | ||||
-rw-r--r-- | repository.go | 5 | ||||
-rw-r--r-- | repository_test.go | 5 |
3 files changed, 13 insertions, 3 deletions
diff --git a/common_test.go b/common_test.go index 44b76ee..f6e0f0c 100644 --- a/common_test.go +++ b/common_test.go @@ -15,6 +15,7 @@ func Test(t *testing.T) { TestingT(t) } type MockGitUploadPackService struct { Auth common.AuthMethod + RC io.ReadCloser } func (s *MockGitUploadPackService) Connect(url common.Endpoint) error { @@ -40,8 +41,9 @@ func (s *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) { } func (s *MockGitUploadPackService) Fetch(*common.GitUploadPackRequest) (io.ReadCloser, error) { - r, _ := os.Open("formats/packfile/fixtures/git-fixture.ref-delta") - return r, nil + var err error + s.RC, err = os.Open("formats/packfile/fixtures/git-fixture.ref-delta") + return s.RC, err } var fixtureRepos = [...]struct { diff --git a/repository.go b/repository.go index e63869a..5deddfb 100644 --- a/repository.go +++ b/repository.go @@ -53,7 +53,7 @@ func NewPlainRepository() *Repository { } } -func (r *Repository) Pull(remoteName, branch string) error { +func (r *Repository) Pull(remoteName, branch string) (err error) { remote, ok := r.Remotes[remoteName] if !ok { return fmt.Errorf("unable to find remote %q", remoteName) @@ -75,6 +75,9 @@ func (r *Repository) Pull(remoteName, branch string) error { if err != nil { return err } + defer func() { + err = reader.Close() + }() pr := packfile.NewReader(reader) if _, err = pr.Read(r.Storage); err != nil { diff --git a/repository_test.go b/repository_test.go index 20aaf0c..df6ed6b 100644 --- a/repository_test.go +++ b/repository_test.go @@ -31,6 +31,11 @@ func (s *SuiteRepository) TestPull(c *C) { c.Assert(err, IsNil) c.Assert(r.Pull("origin", "refs/heads/master"), IsNil) + + mock, ok := (r.Remotes["origin"].upSrv).(*MockGitUploadPackService) + c.Assert(ok, Equals, true) + err = mock.RC.Close() + c.Assert(err, Not(IsNil), Commentf("pull leaks an open fd from the fetch")) } func (s *SuiteRepository) TestCommit(c *C) { |