mirror of
https://github.com/gosticks/SwiftGit2.git
synced 2025-10-16 11:55:34 +00:00
Make Branch Hashable
This commit is contained in:
parent
d84cf377d0
commit
f46d869de7
@ -91,6 +91,17 @@ public struct Branch: ReferenceType {
|
||||
}
|
||||
}
|
||||
|
||||
extension Branch: Hashable {
|
||||
public var hashValue: Int {
|
||||
return longName.hashValue ^ oid.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
public func == (lhs: Branch, rhs: Branch) -> Bool {
|
||||
return lhs.longName == rhs.longName
|
||||
&& lhs.oid == rhs.oid
|
||||
}
|
||||
|
||||
/// A git tag reference, which can be either a lightweight tag or a Tag object.
|
||||
public enum TagReference: ReferenceType {
|
||||
/// A lightweight tag, which is just a name and an OID.
|
||||
|
||||
@ -75,5 +75,30 @@ class BranchSpec: QuickSpec {
|
||||
expect(branch.oid).to(equal(branch.commit.oid))
|
||||
}
|
||||
}
|
||||
|
||||
describe("==") {
|
||||
it("should be true with equal branches") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let branch1 = from_git_reference(repo, "refs/heads/master") { Branch($0)! }
|
||||
let branch2 = from_git_reference(repo, "refs/heads/master") { Branch($0)! }
|
||||
expect(branch1).to(equal(branch2))
|
||||
}
|
||||
|
||||
it("should be false with unequal branches") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let branch1 = from_git_reference(repo, "refs/heads/master") { Branch($0)! }
|
||||
let branch2 = from_git_reference(repo, "refs/heads/another-branch") { Branch($0)! }
|
||||
expect(branch1).notTo(equal(branch2))
|
||||
}
|
||||
}
|
||||
|
||||
describe("hashValue") {
|
||||
it("should be equal with equal references") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let branch1 = from_git_reference(repo, "refs/heads/master") { Branch($0)! }
|
||||
let branch2 = from_git_reference(repo, "refs/heads/master") { Branch($0)! }
|
||||
expect(branch1.hashValue).to(equal(branch2.hashValue))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user