Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 7738417

Browse files
authored
Merge pull request #543 from erizocosmico/fix/packwriter-unused-notify
prevent PackWriter from using Notify if nothing was written
2 parents 91868d1 + 94f43de commit 7738417

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

storage/filesystem/internal/dotgit/writers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (w *PackWriter) Write(p []byte) (int, error) {
9292
// was written, the tempfiles are deleted without writing a packfile.
9393
func (w *PackWriter) Close() error {
9494
defer func() {
95-
if w.Notify != nil {
95+
if w.Notify != nil && w.index != nil && w.index.Size() > 0 {
9696
w.Notify(w.checksum, w.index)
9797
}
9898

storage/filesystem/internal/dotgit/writers_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
. "gopkg.in/check.v1"
1414
"gopkg.in/src-d/go-billy.v3/osfs"
15+
"gopkg.in/src-d/go-git.v4/plumbing"
1516
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
1617
)
1718

@@ -132,3 +133,23 @@ func (s *SuiteDotGit) TestSyncedReader(c *C) {
132133
c.Assert(n, Equals, 3)
133134
c.Assert(string(head), Equals, "280")
134135
}
136+
137+
func (s *SuiteDotGit) TestPackWriterUnusedNotify(c *C) {
138+
dir, err := ioutil.TempDir("", "example")
139+
if err != nil {
140+
c.Assert(err, IsNil)
141+
}
142+
143+
defer os.RemoveAll(dir)
144+
145+
fs := osfs.New(dir)
146+
147+
w, err := newPackWrite(fs)
148+
c.Assert(err, IsNil)
149+
150+
w.Notify = func(h plumbing.Hash, idx *packfile.Index) {
151+
c.Fatal("unexpected call to PackWriter.Notify")
152+
}
153+
154+
c.Assert(w.Close(), IsNil)
155+
}

0 commit comments

Comments
 (0)