diff --git a/SwiftGit2/References.swift b/SwiftGit2/References.swift index 81229aa..72e13ca 100644 --- a/SwiftGit2/References.swift +++ b/SwiftGit2/References.swift @@ -169,4 +169,14 @@ public enum TagReference: ReferenceType { } } +extension TagReference: Hashable { + public var hashValue: Int { + return longName.hashValue ^ oid.hashValue + } +} + +public func == (lhs: TagReference, rhs: TagReference) -> Bool { + return lhs.longName == rhs.longName + && lhs.oid == rhs.oid +} diff --git a/SwiftGit2Tests/ReferencesSpec.swift b/SwiftGit2Tests/ReferencesSpec.swift index 1564065..2962945 100644 --- a/SwiftGit2Tests/ReferencesSpec.swift +++ b/SwiftGit2Tests/ReferencesSpec.swift @@ -130,5 +130,30 @@ class TagReferenceSpec: QuickSpec { expect(tag).to(beNil()) } } + + describe("==") { + it("should be true with equal tag references") { + let repo = Fixtures.simpleRepository + let tag1 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! } + let tag2 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! } + expect(tag1).to(equal(tag2)) + } + + it("should be false with unequal tag references") { + let repo = Fixtures.simpleRepository + let tag1 = from_git_reference(repo, "refs/tags/tag-1") { TagReference($0)! } + let tag2 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! } + expect(tag1).notTo(equal(tag2)) + } + } + + describe("hashValue") { + it("should be equal with equal references") { + let repo = Fixtures.simpleRepository + let tag1 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! } + let tag2 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! } + expect(tag1.hashValue).to(equal(tag2.hashValue)) + } + } } }