prevent PackWriter from using Notify if nothing was written

Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
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 @@
 // 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 @@
 
 	. "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 @@
 	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)
+}