aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plumbing/difftree/difftree.go8
-rw-r--r--plumbing/difftree/difftree_test.go24
2 files changed, 28 insertions, 4 deletions
diff --git a/plumbing/difftree/difftree.go b/plumbing/difftree/difftree.go
index 76c5f27..d38ad2c 100644
--- a/plumbing/difftree/difftree.go
+++ b/plumbing/difftree/difftree.go
@@ -12,10 +12,6 @@ func DiffTree(a, b *object.Tree) ([]*Change, error) {
from := newTreeNoder(a)
to := newTreeNoder(b)
- hashEqual := func(a, b noder.Hasher) bool {
- return bytes.Equal(a.Hash(), b.Hash())
- }
-
merkletrieChanges, err := merkletrie.DiffTree(from, to, hashEqual)
if err != nil {
return nil, err
@@ -23,3 +19,7 @@ func DiffTree(a, b *object.Tree) ([]*Change, error) {
return newChanges(merkletrieChanges)
}
+
+func hashEqual(a, b noder.Hasher) bool {
+ return bytes.Equal(a.Hash(), b.Hash())
+}
diff --git a/plumbing/difftree/difftree_test.go b/plumbing/difftree/difftree_test.go
index e2519b3..24817f1 100644
--- a/plumbing/difftree/difftree_test.go
+++ b/plumbing/difftree/difftree_test.go
@@ -1,6 +1,7 @@
package difftree
import (
+ "os"
"sort"
"testing"
@@ -353,3 +354,26 @@ func (s *DiffTreeSuite) TestDiffTree(c *C) {
assertChanges(obtained, c)
}
}
+
+func (s *DiffTreeSuite) TestIssue279(c *C) {
+ // HashEqual should ignore files if the only change is from a 100664
+ // mode to a 100644 or vice versa.
+ from := &treeNoder{
+ hash: plumbing.NewHash("d08e895238bac36d8220586fdc28c27e1a7a76d3"),
+ mode: os.FileMode(0100664),
+ }
+ to := &treeNoder{
+ hash: plumbing.NewHash("d08e895238bac36d8220586fdc28c27e1a7a76d3"),
+ mode: os.FileMode(0100644),
+ }
+ c.Assert(hashEqual(from, to), Equals, true)
+ c.Assert(hashEqual(to, from), Equals, true)
+
+ // but should detect if the contents of the file also changed.
+ to = &treeNoder{
+ hash: plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
+ mode: os.FileMode(0100644),
+ }
+ c.Assert(hashEqual(from, to), Equals, false)
+ c.Assert(hashEqual(to, from), Equals, false)
+}