aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plumbing/format/diff/unified_encoder.go5
-rw-r--r--plumbing/format/diff/unified_encoder_test.go2
-rw-r--r--plumbing/object/patch.go5
-rw-r--r--plumbing/object/patch_test.go44
4 files changed, 51 insertions, 5 deletions
diff --git a/plumbing/format/diff/unified_encoder.go b/plumbing/format/diff/unified_encoder.go
index a4ff7ab..cf2a34b 100644
--- a/plumbing/format/diff/unified_encoder.go
+++ b/plumbing/format/diff/unified_encoder.go
@@ -2,7 +2,6 @@ package diff
import (
"bytes"
- "errors"
"fmt"
"io"
"strings"
@@ -45,8 +44,6 @@ const (
DefaultContextLines = 3
)
-var ErrBothFilesEmpty = errors.New("both files are empty")
-
// UnifiedEncoder encodes an unified diff into the provided Writer.
// There are some unsupported features:
// - Similarity index for renames
@@ -106,7 +103,7 @@ func (e *UnifiedEncoder) printMessage(message string) {
func (e *UnifiedEncoder) header(from, to File, isBinary bool) error {
switch {
case from == nil && to == nil:
- return ErrBothFilesEmpty
+ return nil
case from != nil && to != nil:
hashEquals := from.Hash() == to.Hash()
diff --git a/plumbing/format/diff/unified_encoder_test.go b/plumbing/format/diff/unified_encoder_test.go
index b832920..6e12070 100644
--- a/plumbing/format/diff/unified_encoder_test.go
+++ b/plumbing/format/diff/unified_encoder_test.go
@@ -20,7 +20,7 @@ func (s *UnifiedEncoderTestSuite) TestBothFilesEmpty(c *C) {
buffer := bytes.NewBuffer(nil)
e := NewUnifiedEncoder(buffer, 1)
err := e.Encode(testPatch{filePatches: []testFilePatch{{}}})
- c.Assert(err, Equals, ErrBothFilesEmpty)
+ c.Assert(err, IsNil)
}
func (s *UnifiedEncoderTestSuite) TestBinaryFile(c *C) {
diff --git a/plumbing/object/patch.go b/plumbing/object/patch.go
index a920631..aa96a96 100644
--- a/plumbing/object/patch.go
+++ b/plumbing/object/patch.go
@@ -271,6 +271,11 @@ func getFileStatsFromFilePatches(filePatches []fdiff.FilePatch) FileStats {
var fileStats FileStats
for _, fp := range filePatches {
+ // ignore empty patches (binary files, submodule refs updates)
+ if len(fp.Chunks()) == 0 {
+ continue
+ }
+
cs := FileStat{}
from, to := fp.Files()
if from == nil {
diff --git a/plumbing/object/patch_test.go b/plumbing/object/patch_test.go
new file mode 100644
index 0000000..8eb65ec
--- /dev/null
+++ b/plumbing/object/patch_test.go
@@ -0,0 +1,44 @@
+package object
+
+import (
+ . "gopkg.in/check.v1"
+ fixtures "gopkg.in/src-d/go-git-fixtures.v3"
+ "gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/storage/filesystem"
+)
+
+type PatchSuite struct {
+ BaseObjectsSuite
+}
+
+var _ = Suite(&PatchSuite{})
+
+func (s *PatchSuite) TestStatsWithSubmodules(c *C) {
+ storer, err := filesystem.NewStorage(
+ fixtures.ByURL("https://github.com/git-fixtures/submodule.git").One().DotGit())
+
+ commit, err := GetCommit(storer, plumbing.NewHash("b685400c1f9316f350965a5993d350bc746b0bf4"))
+
+ tree, err := commit.Tree()
+ c.Assert(err, IsNil)
+
+ e, err := tree.entry("basic")
+ c.Assert(err, IsNil)
+
+ ch := &Change{
+ From: ChangeEntry{
+ Name: "basic",
+ Tree: tree,
+ TreeEntry: *e,
+ },
+ To: ChangeEntry{
+ Name: "basic",
+ Tree: tree,
+ TreeEntry: *e,
+ },
+ }
+
+ p, err := getPatch("", ch)
+ c.Assert(err, IsNil)
+ c.Assert(p, NotNil)
+}