diff --git a/SwiftGit2/References.swift b/SwiftGit2/References.swift index bd4cb43..47b9404 100644 --- a/SwiftGit2/References.swift +++ b/SwiftGit2/References.swift @@ -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. diff --git a/SwiftGit2Tests/ReferencesSpec.swift b/SwiftGit2Tests/ReferencesSpec.swift index 3858576..88ccfd2 100644 --- a/SwiftGit2Tests/ReferencesSpec.swift +++ b/SwiftGit2Tests/ReferencesSpec.swift @@ -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()) } }