This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +51
-5
lines changed Expand file tree Collapse file tree 4 files changed +51
-5
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package diff
22
33import (
44 "bytes"
5- "errors"
65 "fmt"
76 "io"
87 "strings"
@@ -45,8 +44,6 @@ const (
4544 DefaultContextLines = 3
4645)
4746
48- var ErrBothFilesEmpty = errors .New ("both files are empty" )
49-
5047// UnifiedEncoder encodes an unified diff into the provided Writer.
5148// There are some unsupported features:
5249// - Similarity index for renames
@@ -106,7 +103,7 @@ func (e *UnifiedEncoder) printMessage(message string) {
106103func (e * UnifiedEncoder ) header (from , to File , isBinary bool ) error {
107104 switch {
108105 case from == nil && to == nil :
109- return ErrBothFilesEmpty
106+ return nil
110107 case from != nil && to != nil :
111108 hashEquals := from .Hash () == to .Hash ()
112109
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ func (s *UnifiedEncoderTestSuite) TestBothFilesEmpty(c *C) {
2020 buffer := bytes .NewBuffer (nil )
2121 e := NewUnifiedEncoder (buffer , 1 )
2222 err := e .Encode (testPatch {filePatches : []testFilePatch {{}}})
23- c .Assert (err , Equals , ErrBothFilesEmpty )
23+ c .Assert (err , IsNil )
2424}
2525
2626func (s * UnifiedEncoderTestSuite ) TestBinaryFile (c * C ) {
Original file line number Diff line number Diff line change @@ -271,6 +271,11 @@ func getFileStatsFromFilePatches(filePatches []fdiff.FilePatch) FileStats {
271271 var fileStats FileStats
272272
273273 for _ , fp := range filePatches {
274+ // ignore empty patches (binary files, submodule refs updates)
275+ if len (fp .Chunks ()) == 0 {
276+ continue
277+ }
278+
274279 cs := FileStat {}
275280 from , to := fp .Files ()
276281 if from == nil {
Original file line number Diff line number Diff line change 1+ package object
2+
3+ import (
4+ . "gopkg.in/check.v1"
5+ fixtures "gopkg.in/src-d/go-git-fixtures.v3"
6+ "gopkg.in/src-d/go-git.v4/plumbing"
7+ "gopkg.in/src-d/go-git.v4/storage/filesystem"
8+ )
9+
10+ type PatchSuite struct {
11+ BaseObjectsSuite
12+ }
13+
14+ var _ = Suite (& PatchSuite {})
15+
16+ func (s * PatchSuite ) TestStatsWithSubmodules (c * C ) {
17+ storer , err := filesystem .NewStorage (
18+ fixtures .ByURL ("https://github.com/git-fixtures/submodule.git" ).One ().DotGit ())
19+
20+ commit , err := GetCommit (storer , plumbing .NewHash ("b685400c1f9316f350965a5993d350bc746b0bf4" ))
21+
22+ tree , err := commit .Tree ()
23+ c .Assert (err , IsNil )
24+
25+ e , err := tree .entry ("basic" )
26+ c .Assert (err , IsNil )
27+
28+ ch := & Change {
29+ From : ChangeEntry {
30+ Name : "basic" ,
31+ Tree : tree ,
32+ TreeEntry : * e ,
33+ },
34+ To : ChangeEntry {
35+ Name : "basic" ,
36+ Tree : tree ,
37+ TreeEntry : * e ,
38+ },
39+ }
40+
41+ p , err := getPatch ("" , ch )
42+ c .Assert (err , IsNil )
43+ c .Assert (p , NotNil )
44+ }
You can’t perform that action at this time.
0 commit comments