diff options
author | Miguel Molina <miguel@erizocosmi.co> | 2017-08-10 13:15:41 +0200 |
---|---|---|
committer | Miguel Molina <miguel@erizocosmi.co> | 2017-08-10 13:15:41 +0200 |
commit | 94f43de99c66883bd930fce9581971b3893da610 (patch) | |
tree | 6b437c0b94fa92cb88207eed2bcd04ac397e07bd | |
parent | 91868d15053f29fa93c1984c7cf9bd961b6ab13d (diff) | |
download | go-git-94f43de99c66883bd930fce9581971b3893da610.tar.gz |
prevent PackWriter from using Notify if nothing was written
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
-rw-r--r-- | storage/filesystem/internal/dotgit/writers.go | 2 | ||||
-rw-r--r-- | storage/filesystem/internal/dotgit/writers_test.go | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/storage/filesystem/internal/dotgit/writers.go b/storage/filesystem/internal/dotgit/writers.go index a7525d4..46d3619 100644 --- a/storage/filesystem/internal/dotgit/writers.go +++ b/storage/filesystem/internal/dotgit/writers.go @@ -92,7 +92,7 @@ func (w *PackWriter) Write(p []byte) (int, error) { // was written, the tempfiles are deleted without writing a packfile. func (w *PackWriter) Close() error { defer func() { - if w.Notify != nil { + if w.Notify != nil && w.index != nil && w.index.Size() > 0 { w.Notify(w.checksum, w.index) } diff --git a/storage/filesystem/internal/dotgit/writers_test.go b/storage/filesystem/internal/dotgit/writers_test.go index 1342396..1544de8 100644 --- a/storage/filesystem/internal/dotgit/writers_test.go +++ b/storage/filesystem/internal/dotgit/writers_test.go @@ -12,6 +12,7 @@ import ( . "gopkg.in/check.v1" "gopkg.in/src-d/go-billy.v3/osfs" + "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/format/packfile" ) @@ -132,3 +133,23 @@ func (s *SuiteDotGit) TestSyncedReader(c *C) { c.Assert(n, Equals, 3) c.Assert(string(head), Equals, "280") } + +func (s *SuiteDotGit) TestPackWriterUnusedNotify(c *C) { + dir, err := ioutil.TempDir("", "example") + if err != nil { + c.Assert(err, IsNil) + } + + defer os.RemoveAll(dir) + + fs := osfs.New(dir) + + w, err := newPackWrite(fs) + c.Assert(err, IsNil) + + w.Notify = func(h plumbing.Hash, idx *packfile.Index) { + c.Fatal("unexpected call to PackWriter.Notify") + } + + c.Assert(w.Close(), IsNil) +} |