Implement localBranchWithName()

This commit is contained in:
Matt Diephouse 2015-02-13 15:36:58 -05:00
parent f46d869de7
commit a8cc3144c4
2 changed files with 26 additions and 2 deletions

View File

@ -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]> {

View File

@ -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())
}
}
}
}