diff options
-rw-r--r-- | lib/git/commit.py | 6 | ||||
-rw-r--r-- | test/git/test_commit.py | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/git/commit.py b/lib/git/commit.py index a488c4a1..ba7a7102 100644 --- a/lib/git/commit.py +++ b/lib/git/commit.py @@ -67,6 +67,12 @@ class Commit(LazyMixin): if tree is not None: self.tree = Tree(repo, id=tree) + def __eq__(self, other): + return self.id == other.id + + def __ne__(self, other): + return self.id != other.id + def __bake__(self): temp = Commit.find_all(self.repo, self.id, max_count=1)[0] self.parents = temp.parents diff --git a/test/git/test_commit.py b/test/git/test_commit.py index 3e37a7a4..e63edbcf 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -236,3 +236,10 @@ class TestCommit(object): def test_repr(self): commit = Commit(self.repo, id='abc') assert_equal('<git.Commit "abc">', repr(commit)) + + def test_equality(self): + commit1 = Commit(self.repo, id='abc') + commit2 = Commit(self.repo, id='abc') + commit3 = Commit(self.repo, id='zyx') + assert_equal(commit1, commit2) + assert_not_equal(commit2, commit3) |