What's the equivalent of git diff?
#685
-
|
How can I compare the working tree to a Commit or Tree object? This would be the equivalent of running |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
|
Here's an extract from a test in 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)
}https://github.com/go-git/go-git/blob/master/plumbing/object/tree_test.go#L244-L269 With the resulting |
Beta Was this translation helpful? Give feedback.
-
|
Do you have the repo rather than the worktree? If so you could try (untested code written here): |
Beta Was this translation helpful? Give feedback.
-
|
I am looking for to ignore whitespace changes. With git CLI, this seems to work git diff --ignore-blank-lines --ignore-all-space --ignore-cr-at-eol --statIs there a way to do it with this go module? |
Beta Was this translation helpful? Give feedback.
Do you have the repo rather than the worktree? If so you could try (untested code written here):