aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--storage/filesystem/internal/dotgit/writers.go2
-rw-r--r--storage/filesystem/internal/dotgit/writers_test.go21
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)
+}