aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2020-04-25 12:36:40 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2020-04-25 12:36:40 +0200
commit042e56e56e644bc9f02780dbf6eeadc40eb57f6a (patch)
treeb384712a73068ae5f4945385fac7b45752f6dd7c /plumbing
parentc9533a6f9f3a6edd0fb7c8c161d4016a6af26bc3 (diff)
downloadgo-git-042e56e56e644bc9f02780dbf6eeadc40eb57f6a.tar.gz
plumbing: object, make renames diff default
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/object/commit.go6
-rw-r--r--plumbing/object/tree.go35
-rw-r--r--plumbing/object/tree_test.go30
3 files changed, 55 insertions, 16 deletions
diff --git a/plumbing/object/commit.go b/plumbing/object/commit.go
index b37ff61..b27f20b 100644
--- a/plumbing/object/commit.go
+++ b/plumbing/object/commit.go
@@ -78,6 +78,9 @@ func (c *Commit) Tree() (*Tree, error) {
// PatchContext returns the Patch between the actual commit and the provided one.
// Error will be return if context expires. Provided context must be non-nil.
+//
+// NOTE: Since version 5.1.0 the renames are correctly handled, the settings
+// used are the recommended options DefaultDiffTreeOptions.
func (c *Commit) PatchContext(ctx context.Context, to *Commit) (*Patch, error) {
fromTree, err := c.Tree()
if err != nil {
@@ -93,6 +96,9 @@ func (c *Commit) PatchContext(ctx context.Context, to *Commit) (*Patch, error) {
}
// Patch returns the Patch between the actual commit and the provided one.
+//
+// NOTE: Since version 5.1.0 the renames are correctly handled, the settings
+// used are the recommended options DefaultDiffTreeOptions.
func (c *Commit) Patch(to *Commit) (*Patch, error) {
return c.PatchContext(context.Background(), to)
}
diff --git a/plumbing/object/tree.go b/plumbing/object/tree.go
index d3c8c77..5e6378c 100644
--- a/plumbing/object/tree.go
+++ b/plumbing/object/tree.go
@@ -304,29 +304,34 @@ func (t *Tree) buildMap() {
}
// Diff returns a list of changes between this tree and the provided one
-func (from *Tree) Diff(to *Tree) (Changes, error) {
- return DiffTree(from, to)
+func (t *Tree) Diff(to *Tree) (Changes, error) {
+ return t.DiffContext(context.Background(), to)
}
-// Diff returns a list of changes between this tree and the provided one
-// Error will be returned if context expires
-// Provided context must be non nil
-func (from *Tree) DiffContext(ctx context.Context, to *Tree) (Changes, error) {
- return DiffTreeContext(ctx, from, to)
+// DiffContext returns a list of changes between this tree and the provided one
+// Error will be returned if context expires. Provided context must be non nil.
+//
+// NOTE: Since version 5.1.0 the renames are correctly handled, the settings
+// used are the recommended options DefaultDiffTreeOptions.
+func (t *Tree) DiffContext(ctx context.Context, to *Tree) (Changes, error) {
+ return DiffTreeWithOptions(ctx, t, to, DefaultDiffTreeOptions)
}
// Patch returns a slice of Patch objects with all the changes between trees
// in chunks. This representation can be used to create several diff outputs.
-func (from *Tree) Patch(to *Tree) (*Patch, error) {
- return from.PatchContext(context.Background(), to)
+func (t *Tree) Patch(to *Tree) (*Patch, error) {
+ return t.PatchContext(context.Background(), to)
}
-// Patch returns a slice of Patch objects with all the changes between trees
-// in chunks. This representation can be used to create several diff outputs.
-// If context expires, an error will be returned
-// Provided context must be non-nil
-func (from *Tree) PatchContext(ctx context.Context, to *Tree) (*Patch, error) {
- changes, err := DiffTreeContext(ctx, from, to)
+// PatchContext returns a slice of Patch objects with all the changes between
+// trees in chunks. This representation can be used to create several diff
+// outputs. If context expires, an error will be returned. Provided context must
+// be non-nil.
+//
+// NOTE: Since version 5.1.0 the renames are correctly handled, the settings
+// used are the recommended options DefaultDiffTreeOptions.
+func (t *Tree) PatchContext(ctx context.Context, to *Tree) (*Patch, error) {
+ changes, err := t.DiffContext(ctx, to)
if err != nil {
return nil, err
}
diff --git a/plumbing/object/tree_test.go b/plumbing/object/tree_test.go
index 319caae..474bb6a 100644
--- a/plumbing/object/tree_test.go
+++ b/plumbing/object/tree_test.go
@@ -1,9 +1,11 @@
package object
import (
+ "context"
"errors"
"io"
+ fixtures "github.com/go-git/go-git-fixtures/v4"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/cache"
"github.com/go-git/go-git/v5/plumbing/filemode"
@@ -11,7 +13,6 @@ import (
"github.com/go-git/go-git/v5/storage/filesystem"
. "gopkg.in/check.v1"
- "github.com/go-git/go-git-fixtures/v4"
)
type TreeSuite struct {
@@ -240,6 +241,33 @@ func (s *TreeSuite) TestTreeDecodeEncodeIdempotent(c *C) {
}
}
+func (s *TreeSuite) TestTreeDiff(c *C) {
+ f := fixtures.ByURL("https://github.com/src-d/go-git.git").One()
+ storer := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
+ commit, err := GetCommit(storer, plumbing.NewHash("89f8bda31d29767a6d6ba8f9d0dfb941d598e843"))
+ c.Assert(err, IsNil)
+
+ tree, err := commit.Tree()
+ c.Assert(err, IsNil)
+
+ parentCommit, err := commit.Parent(0)
+ c.Assert(err, IsNil)
+
+ parentTree, err := parentCommit.Tree()
+ c.Assert(err, IsNil)
+
+ ch, err := parentTree.Diff(tree)
+ c.Assert(err, IsNil)
+
+ c.Assert(ch, HasLen, 3)
+ c.Assert(ch[0].From.Name, Equals, "examples/object_storage/main.go")
+ c.Assert(ch[0].To.Name, Equals, "examples/storage/main.go")
+
+ ch, err = parentTree.DiffContext(context.Background(), tree)
+ c.Assert(err, IsNil)
+ c.Assert(ch, HasLen, 3)
+}
+
func (s *TreeSuite) TestTreeIter(c *C) {
encIter, err := s.Storer.IterEncodedObjects(plumbing.TreeObject)
c.Assert(err, IsNil)