Add isLocal and isRemote to Branch

This commit is contained in:
Matt Diephouse 2015-02-14 12:52:56 -05:00
parent 910b9b35d2
commit 67d44d96d1
2 changed files with 10 additions and 0 deletions

View File

@ -73,6 +73,12 @@ public struct Branch: ReferenceType {
/// This is the same as `commit.oid`, but is declared here to adhere to `ReferenceType`.
public var oid: OID { return commit.oid }
/// Whether the branch is a local branch.
public var isLocal: Bool { return longName.hasPrefix("refs/heads/") }
/// Whether the branch is a remote branch.
public var isRemote: Bool { return longName.hasPrefix("refs/remotes/") }
/// Create an instance with a libgit2 `git_reference` object.
///
/// Returns `nil` if the pointer isn't a branch.

View File

@ -73,6 +73,8 @@ class BranchSpec: QuickSpec {
expect(branch.shortName).to(equal(branch.name))
expect(branch.commit.oid).to(equal(OID(string: "f797bd4837b61d37847a4833024aab268599a681")!))
expect(branch.oid).to(equal(branch.commit.oid))
expect(branch.isLocal).to(beTrue())
expect(branch.isRemote).to(beFalse())
}
it("should work with symoblic refs") {
@ -83,6 +85,8 @@ class BranchSpec: QuickSpec {
expect(branch.shortName).to(equal(branch.name))
expect(branch.commit.oid).to(equal(OID(string: "f797bd4837b61d37847a4833024aab268599a681")!))
expect(branch.oid).to(equal(branch.commit.oid))
expect(branch.isLocal).to(beFalse())
expect(branch.isRemote).to(beTrue())
}
}