This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree 2 files changed +22
-1
lines changed
storage/filesystem/internal/dotgit
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ func (w *PackWriter) Write(p []byte) (int, error) {
92
92
// was written, the tempfiles are deleted without writing a packfile.
93
93
func (w * PackWriter ) Close () error {
94
94
defer func () {
95
- if w .Notify != nil {
95
+ if w .Notify != nil && w . index != nil && w . index . Size () > 0 {
96
96
w .Notify (w .checksum , w .index )
97
97
}
98
98
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
12
12
13
13
. "gopkg.in/check.v1"
14
14
"gopkg.in/src-d/go-billy.v3/osfs"
15
+ "gopkg.in/src-d/go-git.v4/plumbing"
15
16
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
16
17
)
17
18
@@ -132,3 +133,23 @@ func (s *SuiteDotGit) TestSyncedReader(c *C) {
132
133
c .Assert (n , Equals , 3 )
133
134
c .Assert (string (head ), Equals , "280" )
134
135
}
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
+ }
You can’t perform that action at this time.
0 commit comments