mirror of
https://github.com/gosticks/SwiftGit2.git
synced 2025-10-16 11:55:34 +00:00
Implement localBranchWithName()
This commit is contained in:
parent
f46d869de7
commit
a8cc3144c4
@ -252,8 +252,20 @@ final public class Repository {
|
||||
return failure()
|
||||
}
|
||||
|
||||
public func branchWithName(name: String) -> Result<Branch> {
|
||||
return failure()
|
||||
public func localBranchWithName(name: String) -> Result<Branch> {
|
||||
let pointer = UnsafeMutablePointer<COpaquePointer>.alloc(1)
|
||||
let repository = self.pointer
|
||||
let result = git_branch_lookup(pointer, repository, name.cStringUsingEncoding(NSUTF8StringEncoding)!, GIT_BRANCH_LOCAL)
|
||||
|
||||
if result != GIT_OK.value {
|
||||
pointer.dealloc(1)
|
||||
return failure()
|
||||
}
|
||||
|
||||
let value = Branch(pointer.memory)!
|
||||
git_reference_free(pointer.memory)
|
||||
pointer.dealloc(1)
|
||||
return success(value)
|
||||
}
|
||||
|
||||
public func allTags() -> Result<[TagReference]> {
|
||||
|
||||
@ -309,5 +309,17 @@ class RepositorySpec: QuickSpec {
|
||||
expect(result.error()).notTo(beNil())
|
||||
}
|
||||
}
|
||||
|
||||
describe("-localBranchWithName()") {
|
||||
it("should return the branch if it exists") {
|
||||
let result = Fixtures.simpleRepository.localBranchWithName("master")
|
||||
expect(result.value()?.longName).to(equal("refs/heads/master"))
|
||||
}
|
||||
|
||||
it("should error if the branch doesn't exists") {
|
||||
let result = Fixtures.simpleRepository.localBranchWithName("nonexistent")
|
||||
expect(result.error()).notTo(beNil())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user