aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object
diff options
context:
space:
mode:
authorFilip Navara <filip.navara@gmail.com>2019-04-26 10:07:59 +0200
committerFilip Navara <filip.navara@gmail.com>2019-04-26 10:07:59 +0200
commit14c17dc6881fccf851c8bdffab15774faa3bce8b (patch)
treee4e567231fee000bf6a6424577c60ce907431a18 /plumbing/object
parent34cb7a3aededd002881504dd729527628e923fc6 (diff)
parentca5d7bb1a790303d2ca245cb6225850bcf5d12a6 (diff)
downloadgo-git-14c17dc6881fccf851c8bdffab15774faa3bce8b.tar.gz
Merge branch 'master' into commitgraph-obj
Diffstat (limited to 'plumbing/object')
-rw-r--r--plumbing/object/commit.go7
-rw-r--r--plumbing/object/commit_test.go23
-rw-r--r--plumbing/object/patch.go4
-rw-r--r--plumbing/object/tag.go7
-rw-r--r--plumbing/object/tag_test.go24
5 files changed, 61 insertions, 4 deletions
diff --git a/plumbing/object/commit.go b/plumbing/object/commit.go
index 511242d..6b50934 100644
--- a/plumbing/object/commit.go
+++ b/plumbing/object/commit.go
@@ -235,6 +235,11 @@ func (b *Commit) Encode(o plumbing.EncodedObject) error {
return b.encode(o, true)
}
+// EncodeWithoutSignature export a Commit into a plumbing.EncodedObject without the signature (correspond to the payload of the PGP signature).
+func (b *Commit) EncodeWithoutSignature(o plumbing.EncodedObject) error {
+ return b.encode(o, false)
+}
+
func (b *Commit) encode(o plumbing.EncodedObject, includeSig bool) (err error) {
o.SetType(plumbing.CommitObject)
w, err := o.Writer()
@@ -349,7 +354,7 @@ func (c *Commit) Verify(armoredKeyRing string) (*openpgp.Entity, error) {
encoded := &plumbing.MemoryObject{}
// Encode commit components, excluding signature and get a reader object.
- if err := c.encode(encoded, false); err != nil {
+ if err := c.EncodeWithoutSignature(encoded); err != nil {
return nil, err
}
er, err := encoded.Reader()
diff --git a/plumbing/object/commit_test.go b/plumbing/object/commit_test.go
index c9acf42..957e7d6 100644
--- a/plumbing/object/commit_test.go
+++ b/plumbing/object/commit_test.go
@@ -4,14 +4,15 @@ import (
"bytes"
"context"
"io"
+ "io/ioutil"
"strings"
"time"
+ fixtures "gopkg.in/src-d/go-git-fixtures.v3"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
. "gopkg.in/check.v1"
- "gopkg.in/src-d/go-git-fixtures.v3"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
)
@@ -495,3 +496,23 @@ func (s *SuiteCommit) TestMalformedHeader(c *C) {
err = decoded.Decode(encoded)
c.Assert(err, IsNil)
}
+
+func (s *SuiteCommit) TestEncodeWithoutSignature(c *C) {
+ //Similar to TestString since no signature
+ encoded := &plumbing.MemoryObject{}
+ err := s.Commit.EncodeWithoutSignature(encoded)
+ c.Assert(err, IsNil)
+ er, err := encoded.Reader()
+ c.Assert(err, IsNil)
+ payload, err := ioutil.ReadAll(er)
+ c.Assert(err, IsNil)
+
+ c.Assert(string(payload), Equals, ""+
+ "tree eba74343e2f15d62adedfd8c883ee0262b5c8021\n"+
+ "parent 35e85108805c84807bc66a02d91535e1e24b38b9\n"+
+ "parent a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69\n"+
+ "author Máximo Cuadros Ortiz <mcuadros@gmail.com> 1427802494 +0200\n"+
+ "committer Máximo Cuadros Ortiz <mcuadros@gmail.com> 1427802494 +0200\n"+
+ "\n"+
+ "Merge branch 'master' of github.com:tyba/git-fixture\n")
+}
diff --git a/plumbing/object/patch.go b/plumbing/object/patch.go
index 068589e..1efd0b1 100644
--- a/plumbing/object/patch.go
+++ b/plumbing/object/patch.go
@@ -321,6 +321,10 @@ func getFileStatsFromFilePatches(filePatches []fdiff.FilePatch) FileStats {
for _, chunk := range fp.Chunks() {
s := chunk.Content()
+ if len(s) == 0 {
+ continue
+ }
+
switch chunk.Type() {
case fdiff.Add:
cs.Addition += strings.Count(s, "\n")
diff --git a/plumbing/object/tag.go b/plumbing/object/tag.go
index bc03477..9ee5509 100644
--- a/plumbing/object/tag.go
+++ b/plumbing/object/tag.go
@@ -171,6 +171,11 @@ func (t *Tag) Encode(o plumbing.EncodedObject) error {
return t.encode(o, true)
}
+// EncodeWithoutSignature export a Tag into a plumbing.EncodedObject without the signature (correspond to the payload of the PGP signature).
+func (t *Tag) EncodeWithoutSignature(o plumbing.EncodedObject) error {
+ return t.encode(o, false)
+}
+
func (t *Tag) encode(o plumbing.EncodedObject, includeSig bool) (err error) {
o.SetType(plumbing.TagObject)
w, err := o.Writer()
@@ -291,7 +296,7 @@ func (t *Tag) Verify(armoredKeyRing string) (*openpgp.Entity, error) {
encoded := &plumbing.MemoryObject{}
// Encode tag components, excluding signature and get a reader object.
- if err := t.encode(encoded, false); err != nil {
+ if err := t.EncodeWithoutSignature(encoded); err != nil {
return nil, err
}
er, err := encoded.Reader()
diff --git a/plumbing/object/tag_test.go b/plumbing/object/tag_test.go
index 0ef7136..addec8d 100644
--- a/plumbing/object/tag_test.go
+++ b/plumbing/object/tag_test.go
@@ -3,16 +3,17 @@ package object
import (
"fmt"
"io"
+ "io/ioutil"
"strings"
"time"
+ fixtures "gopkg.in/src-d/go-git-fixtures.v3"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
"gopkg.in/src-d/go-git.v4/storage/memory"
. "gopkg.in/check.v1"
- "gopkg.in/src-d/go-git-fixtures.v3"
)
type TagSuite struct {
@@ -447,3 +448,24 @@ HdzbB2ak/HxIeCqmHVlmUqa+WfTMUJcsgOm3/ZFPCSoL6l0bz9Z1XVbiyD03
_, err = tag.Verify(armoredKeyRing)
c.Assert(err, IsNil)
}
+
+func (s *TagSuite) TestEncodeWithoutSignature(c *C) {
+ //Similar to TestString since no signature
+ encoded := &plumbing.MemoryObject{}
+ tag := s.tag(c, plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69"))
+ err := tag.EncodeWithoutSignature(encoded)
+ c.Assert(err, IsNil)
+ er, err := encoded.Reader()
+ c.Assert(err, IsNil)
+ payload, err := ioutil.ReadAll(er)
+ c.Assert(err, IsNil)
+
+ c.Assert(string(payload), Equals, ""+
+ "object f7b877701fbf855b44c0a9e86f3fdce2c298b07f\n"+
+ "type commit\n"+
+ "tag annotated-tag\n"+
+ "tagger Máximo Cuadros <mcuadros@gmail.com> 1474485215 +0200\n"+
+ "\n"+
+ "example annotated tag\n",
+ )
+}