aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/change_test.go
diff options
context:
space:
mode:
authorAntonio Jesus Navarro Perez <antonio@sourced.tech>2017-04-05 17:13:48 +0200
committerAntonio Jesus Navarro Perez <antonio@sourced.tech>2017-04-06 12:18:49 +0200
commit83e914defef47910ef112b1848c706e176439616 (patch)
tree62e6be8366935fe46e497145f3a4f528e3666056 /plumbing/object/change_test.go
parent31a249d0d5b71bc0f374d3297247d89808263a8b (diff)
downloadgo-git-83e914defef47910ef112b1848c706e176439616.tar.gz
object: fix Change.Files() method behavior (fix #317)
- If 'from' or 'to' are tree entries that aren't files, Files() method will return nil instead of object not found error. - Added a test checking this using modules fixture.
Diffstat (limited to 'plumbing/object/change_test.go')
-rw-r--r--plumbing/object/change_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/plumbing/object/change_test.go b/plumbing/object/change_test.go
index 3bab5d2..005ceb0 100644
--- a/plumbing/object/change_test.go
+++ b/plumbing/object/change_test.go
@@ -198,6 +198,54 @@ func (s *ChangeSuite) TestEmptyChangeFails(c *C) {
c.Assert(str, Equals, "malformed change")
}
+// test reproducing bug #317
+func (s *ChangeSuite) TestNoFileFilemodes(c *C) {
+ s.Suite.SetUpSuite(c)
+ f := fixtures.ByURL("https://github.com/git-fixtures/submodule.git").One()
+
+ sto, err := filesystem.NewStorage(f.DotGit())
+ c.Assert(err, IsNil)
+
+ iter, err := sto.IterEncodedObjects(plumbing.AnyObject)
+ c.Assert(err, IsNil)
+ var commits []*Commit
+ iter.ForEach(func(o plumbing.EncodedObject) error {
+ if o.Type() == plumbing.CommitObject {
+ commit, err := GetCommit(sto, o.Hash())
+ c.Assert(err, IsNil)
+ commits = append(commits, commit)
+
+ }
+
+ return nil
+ })
+
+ c.Assert(len(commits), Not(Equals), 0)
+
+ var prev *Commit
+ for _, commit := range commits {
+ if prev == nil {
+ prev = commit
+ continue
+ }
+ tree, err := commit.Tree()
+ c.Assert(err, IsNil)
+ prevTree, err := prev.Tree()
+ c.Assert(err, IsNil)
+ changes, err := DiffTree(tree, prevTree)
+ c.Assert(err, IsNil)
+ for _, change := range changes {
+ _, _, err := change.Files()
+ if err != nil {
+ panic(err)
+ c.Assert(err, IsNil)
+ }
+ }
+
+ prev = commit
+ }
+}
+
func (s *ChangeSuite) TestErrorsFindingChildsAreDetected(c *C) {
// Commit 7beaad711378a4daafccc2c04bc46d36df2a0fd1 of the go-git
// fixture modified "examples/latest/latest.go".