Rename mapGit* methods back to withGit*

This commit is contained in:
Matt Rubin 2016-12-21 23:37:21 -05:00
parent 9c13bee3ad
commit 597a2fd000
4 changed files with 76 additions and 76 deletions

View File

@ -185,7 +185,7 @@ final public class Repository {
///
/// Returns the result of calling `transform` or an error if the object
/// cannot be loaded.
private func mapGitObject<T>(withIdentity oid: OID, type: git_otype, transform: (OpaquePointer) -> Result<T, NSError>) -> Result<T, NSError> {
private func withGitObject<T>(withIdentity oid: OID, type: git_otype, transform: (OpaquePointer) -> Result<T, NSError>) -> Result<T, NSError> {
var pointer: OpaquePointer? = nil
var oid = oid.oid
let result = git_object_lookup(&pointer, self.pointer, &oid, type)
@ -199,8 +199,8 @@ final public class Repository {
return value
}
private func mapGitObject<T>(withIdentity oid: OID, type: git_otype, transform: (OpaquePointer) -> T) -> Result<T, NSError> {
return mapGitObject(withIdentity: oid, type: type) { Result.success(transform($0)) }
private func withGitObject<T>(withIdentity oid: OID, type: git_otype, transform: (OpaquePointer) -> T) -> Result<T, NSError> {
return withGitObject(withIdentity: oid, type: type) { Result.success(transform($0)) }
}
/// Loads the object with the given OID.
@ -209,7 +209,7 @@ final public class Repository {
///
/// Returns a `Blob`, `Commit`, `Tag`, or `Tree` if one exists, or an error.
public func object(withIdentity oid: OID) -> Result<ObjectType, NSError> {
return mapGitObject(withIdentity: oid, type: GIT_OBJ_ANY) { object in
return withGitObject(withIdentity: oid, type: GIT_OBJ_ANY) { object in
let type = git_object_type(object)
if type == Blob.type {
return Result.success(Blob(object))
@ -238,7 +238,7 @@ final public class Repository {
///
/// Returns the blob if it exists, or an error.
public func blob(withIdentity oid: OID) -> Result<Blob, NSError> {
return mapGitObject(withIdentity: oid, type: GIT_OBJ_BLOB) { Blob($0) }
return withGitObject(withIdentity: oid, type: GIT_OBJ_BLOB) { Blob($0) }
}
/// Loads the commit with the given OID.
@ -247,7 +247,7 @@ final public class Repository {
///
/// Returns the commit if it exists, or an error.
public func commit(withIdentity oid: OID) -> Result<Commit, NSError> {
return mapGitObject(withIdentity: oid, type: GIT_OBJ_COMMIT) { Commit($0) }
return withGitObject(withIdentity: oid, type: GIT_OBJ_COMMIT) { Commit($0) }
}
/// Loads the tag with the given OID.
@ -256,7 +256,7 @@ final public class Repository {
///
/// Returns the tag if it exists, or an error.
public func tag(withIdentity oid: OID) -> Result<Tag, NSError> {
return mapGitObject(withIdentity: oid, type: GIT_OBJ_TAG) { Tag($0) }
return withGitObject(withIdentity: oid, type: GIT_OBJ_TAG) { Tag($0) }
}
/// Loads the tree with the given OID.
@ -265,7 +265,7 @@ final public class Repository {
///
/// Returns the tree if it exists, or an error.
public func tree(withIdentity oid: OID) -> Result<Tree, NSError> {
return mapGitObject(withIdentity: oid, type: GIT_OBJ_TREE) { Tree($0) }
return withGitObject(withIdentity: oid, type: GIT_OBJ_TREE) { Tree($0) }
}
/// Loads the referenced object from the pointer.
@ -274,7 +274,7 @@ final public class Repository {
///
/// Returns the object if it exists, or an error.
public func object<T>(from pointer: PointerTo<T>) -> Result<T, NSError> {
return mapGitObject(withIdentity: pointer.oid, type: pointer.type) { T($0) }
return withGitObject(withIdentity: pointer.oid, type: pointer.type) { T($0) }
}
/// Loads the referenced object from the pointer.

View File

@ -13,7 +13,7 @@ import Quick
import libgit2
private extension Repository {
func mapGitObject<T>(withIdentity oid: OID, transform: (OpaquePointer) -> T) -> T {
func withGitObject<T>(withIdentity oid: OID, transform: (OpaquePointer) -> T) -> T {
let repository = self.pointer
var oid = oid.oid
@ -33,7 +33,7 @@ class SignatureSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
let raw_signature = repo.mapGitObject(withIdentity: oid) { git_commit_author($0).pointee }
let raw_signature = repo.withGitObject(withIdentity: oid) { git_commit_author($0).pointee }
let signature = Signature(raw_signature)
expect(signature.name).to(equal("Matt Diephouse"))
@ -48,7 +48,7 @@ class SignatureSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
let author1 = repo.mapGitObject(withIdentity: oid) { commit in
let author1 = repo.withGitObject(withIdentity: oid) { commit in
Signature(git_commit_author(commit).pointee)
}
let author2 = author1
@ -61,10 +61,10 @@ class SignatureSpec: QuickSpec {
let oid1 = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
let oid2 = OID(string: "24e1e40ee77525d9e279f079f9906ad6d98c8940")!
let author1 = repo.mapGitObject(withIdentity: oid1) { commit in
let author1 = repo.withGitObject(withIdentity: oid1) { commit in
Signature(git_commit_author(commit).pointee)
}
let author2 = repo.mapGitObject(withIdentity: oid2) { commit in
let author2 = repo.withGitObject(withIdentity: oid2) { commit in
Signature(git_commit_author(commit).pointee)
}
@ -77,7 +77,7 @@ class SignatureSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
let author1 = repo.mapGitObject(withIdentity: oid) { commit in
let author1 = repo.withGitObject(withIdentity: oid) { commit in
Signature(git_commit_author(commit).pointee)
}
let author2 = author1
@ -95,11 +95,11 @@ class CommitSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "24e1e40ee77525d9e279f079f9906ad6d98c8940")!
let commit = repo.mapGitObject(withIdentity: oid) { Commit($0) }
let author = repo.mapGitObject(withIdentity: oid) { commit in
let commit = repo.withGitObject(withIdentity: oid) { Commit($0) }
let author = repo.withGitObject(withIdentity: oid) { commit in
Signature(git_commit_author(commit).pointee)
}
let committer = repo.mapGitObject(withIdentity: oid) { commit in
let committer = repo.withGitObject(withIdentity: oid) { commit in
Signature(git_commit_committer(commit).pointee)
}
let tree = PointerTo<Tree>(OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!)
@ -118,7 +118,7 @@ class CommitSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
let commit = repo.mapGitObject(withIdentity: oid) { Commit($0) }
let commit = repo.withGitObject(withIdentity: oid) { Commit($0) }
expect(commit.parents).to(equal([]))
}
@ -126,7 +126,7 @@ class CommitSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "c4ed03a6b7d7ce837d31d83757febbe84dd465fd")!
let commit = repo.mapGitObject(withIdentity: oid) { Commit($0) }
let commit = repo.withGitObject(withIdentity: oid) { Commit($0) }
let parents: [PointerTo<Commit>] = [
PointerTo(OID(string: "315b3f344221db91ddc54b269f3c9af422da0f2e")!),
PointerTo(OID(string: "57f6197561d1f99b03c160f4026a07f06b43cf20")!),
@ -140,7 +140,7 @@ class CommitSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
let commit1 = repo.mapGitObject(withIdentity: oid) { Commit($0) }
let commit1 = repo.withGitObject(withIdentity: oid) { Commit($0) }
let commit2 = commit1
expect(commit1).to(equal(commit2))
}
@ -150,8 +150,8 @@ class CommitSpec: QuickSpec {
let oid1 = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
let oid2 = OID(string: "c4ed03a6b7d7ce837d31d83757febbe84dd465fd")!
let commit1 = repo.mapGitObject(withIdentity: oid1) { Commit($0) }
let commit2 = repo.mapGitObject(withIdentity: oid2) { Commit($0) }
let commit1 = repo.withGitObject(withIdentity: oid1) { Commit($0) }
let commit2 = repo.withGitObject(withIdentity: oid2) { Commit($0) }
expect(commit1).notTo(equal(commit2))
}
}
@ -161,7 +161,7 @@ class CommitSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
let commit1 = repo.mapGitObject(withIdentity: oid) { Commit($0) }
let commit1 = repo.withGitObject(withIdentity: oid) { Commit($0) }
let commit2 = commit1
expect(commit1.hashValue).to(equal(commit2.hashValue))
}
@ -189,7 +189,7 @@ class TreeEntrySpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
let entry = repo.mapGitObject(withIdentity: oid) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
let entry = repo.withGitObject(withIdentity: oid) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
expect(entry.attributes).to(equal(Int32(GIT_FILEMODE_BLOB.rawValue)))
expect(entry.object).to(equal(Pointer.Blob(OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!)))
expect(entry.name).to(equal("README.md"))
@ -201,7 +201,7 @@ class TreeEntrySpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
let entry1 = repo.mapGitObject(withIdentity: oid) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
let entry1 = repo.withGitObject(withIdentity: oid) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
let entry2 = entry1
expect(entry1).to(equal(entry2))
}
@ -211,8 +211,8 @@ class TreeEntrySpec: QuickSpec {
let oid1 = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
let oid2 = OID(string: "f93e3a1a1525fb5b91020da86e44810c87a2d7bc")!
let entry1 = repo.mapGitObject(withIdentity: oid1) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
let entry2 = repo.mapGitObject(withIdentity: oid2) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
let entry1 = repo.withGitObject(withIdentity: oid1) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
let entry2 = repo.withGitObject(withIdentity: oid2) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
expect(entry1).notTo(equal(entry2))
}
}
@ -222,7 +222,7 @@ class TreeEntrySpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
let entry1 = repo.mapGitObject(withIdentity: oid) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
let entry1 = repo.withGitObject(withIdentity: oid) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
let entry2 = entry1
expect(entry1.hashValue).to(equal(entry2.hashValue))
}
@ -237,7 +237,7 @@ class TreeSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
let tree = repo.mapGitObject(withIdentity: oid) { Tree($0) }
let tree = repo.withGitObject(withIdentity: oid) { Tree($0) }
let entries = [
"README.md": Tree.Entry(attributes: Int32(GIT_FILEMODE_BLOB.rawValue), object: .Blob(OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!), name: "README.md"),
]
@ -250,7 +250,7 @@ class TreeSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
let tree1 = repo.mapGitObject(withIdentity: oid) { Tree($0) }
let tree1 = repo.withGitObject(withIdentity: oid) { Tree($0) }
let tree2 = tree1
expect(tree1).to(equal(tree2))
}
@ -260,8 +260,8 @@ class TreeSpec: QuickSpec {
let oid1 = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
let oid2 = OID(string: "f93e3a1a1525fb5b91020da86e44810c87a2d7bc")!
let tree1 = repo.mapGitObject(withIdentity: oid1) { Tree($0) }
let tree2 = repo.mapGitObject(withIdentity: oid2) { Tree($0) }
let tree1 = repo.withGitObject(withIdentity: oid1) { Tree($0) }
let tree2 = repo.withGitObject(withIdentity: oid2) { Tree($0) }
expect(tree1).notTo(equal(tree2))
}
}
@ -271,7 +271,7 @@ class TreeSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
let tree1 = repo.mapGitObject(withIdentity: oid) { Tree($0) }
let tree1 = repo.withGitObject(withIdentity: oid) { Tree($0) }
let tree2 = tree1
expect(tree1.hashValue).to(equal(tree2.hashValue))
}
@ -286,7 +286,7 @@ class BlobSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!
let blob = repo.mapGitObject(withIdentity: oid) { Blob($0) }
let blob = repo.withGitObject(withIdentity: oid) { Blob($0) }
let contents = "# Simple Repository\nA simple repository used for testing SwiftGit2.\n\n## Branches\n\n- master\n\n"
let data = contents.data(using: String.Encoding.utf8)!
expect(blob.oid).to(equal(oid))
@ -299,7 +299,7 @@ class BlobSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!
let blob1 = repo.mapGitObject(withIdentity: oid) { Blob($0) }
let blob1 = repo.withGitObject(withIdentity: oid) { Blob($0) }
let blob2 = blob1
expect(blob1).to(equal(blob2))
}
@ -309,8 +309,8 @@ class BlobSpec: QuickSpec {
let oid1 = OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!
let oid2 = OID(string: "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")!
let blob1 = repo.mapGitObject(withIdentity: oid1) { Blob($0) }
let blob2 = repo.mapGitObject(withIdentity: oid2) { Blob($0) }
let blob1 = repo.withGitObject(withIdentity: oid1) { Blob($0) }
let blob2 = repo.withGitObject(withIdentity: oid2) { Blob($0) }
expect(blob1).notTo(equal(blob2))
}
}
@ -320,7 +320,7 @@ class BlobSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!
let blob1 = repo.mapGitObject(withIdentity: oid) { Blob($0) }
let blob1 = repo.withGitObject(withIdentity: oid) { Blob($0) }
let blob2 = blob1
expect(blob1.hashValue).to(equal(blob2.hashValue))
}
@ -335,8 +335,8 @@ class TagSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "57943b8ee00348180ceeedc960451562750f6d33")!
let tag = repo.mapGitObject(withIdentity: oid) { Tag($0) }
let tagger = repo.mapGitObject(withIdentity: oid) { Signature(git_tag_tagger($0).pointee) }
let tag = repo.withGitObject(withIdentity: oid) { Tag($0) }
let tagger = repo.withGitObject(withIdentity: oid) { Signature(git_tag_tagger($0).pointee) }
expect(tag.oid).to(equal(oid))
expect(tag.target).to(equal(Pointer.Commit(OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!)))
@ -351,7 +351,7 @@ class TagSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "57943b8ee00348180ceeedc960451562750f6d33")!
let tag1 = repo.mapGitObject(withIdentity: oid) { Tag($0) }
let tag1 = repo.withGitObject(withIdentity: oid) { Tag($0) }
let tag2 = tag1
expect(tag1).to(equal(tag2))
}
@ -361,8 +361,8 @@ class TagSpec: QuickSpec {
let oid1 = OID(string: "57943b8ee00348180ceeedc960451562750f6d33")!
let oid2 = OID(string: "13bda91157f255ab224ff88d0a11a82041c9d0c1")!
let tag1 = repo.mapGitObject(withIdentity: oid1) { Tag($0) }
let tag2 = repo.mapGitObject(withIdentity: oid2) { Tag($0) }
let tag1 = repo.withGitObject(withIdentity: oid1) { Tag($0) }
let tag2 = repo.withGitObject(withIdentity: oid2) { Tag($0) }
expect(tag1).notTo(equal(tag2))
}
}
@ -372,7 +372,7 @@ class TagSpec: QuickSpec {
let repo = Fixtures.simpleRepository
let oid = OID(string: "57943b8ee00348180ceeedc960451562750f6d33")!
let tag1 = repo.mapGitObject(withIdentity: oid) { Tag($0) }
let tag1 = repo.withGitObject(withIdentity: oid) { Tag($0) }
let tag2 = tag1
expect(tag1.hashValue).to(equal(tag2.hashValue))
}

View File

@ -13,7 +13,7 @@ import Quick
import libgit2
private extension Repository {
func mapGitReference<T>(withName name: String, transform: (OpaquePointer) -> T) -> T {
func withGitReference<T>(withName name: String, transform: (OpaquePointer) -> T) -> T {
let repository = self.pointer
var pointer: OpaquePointer? = nil
@ -30,7 +30,7 @@ class ReferenceSpec: QuickSpec {
describe("Reference(pointer)") {
it("should initialize its properties") {
let repo = Fixtures.simpleRepository
let ref = repo.mapGitReference(withName: "refs/heads/master") { Reference($0) }
let ref = repo.withGitReference(withName: "refs/heads/master") { Reference($0) }
expect(ref.longName).to(equal("refs/heads/master"))
expect(ref.shortName).to(equal("master"))
expect(ref.oid).to(equal(OID(string: "c4ed03a6b7d7ce837d31d83757febbe84dd465fd")!))
@ -40,15 +40,15 @@ class ReferenceSpec: QuickSpec {
describe("==(Reference, Reference)") {
it("should be true with equal references") {
let repo = Fixtures.simpleRepository
let ref1 = repo.mapGitReference(withName: "refs/heads/master") { Reference($0) }
let ref2 = repo.mapGitReference(withName: "refs/heads/master") { Reference($0) }
let ref1 = repo.withGitReference(withName: "refs/heads/master") { Reference($0) }
let ref2 = repo.withGitReference(withName: "refs/heads/master") { Reference($0) }
expect(ref1).to(equal(ref2))
}
it("should be false with unequal references") {
let repo = Fixtures.simpleRepository
let ref1 = repo.mapGitReference(withName: "refs/heads/master") { Reference($0) }
let ref2 = repo.mapGitReference(withName: "refs/heads/another-branch") { Reference($0) }
let ref1 = repo.withGitReference(withName: "refs/heads/master") { Reference($0) }
let ref2 = repo.withGitReference(withName: "refs/heads/another-branch") { Reference($0) }
expect(ref1).notTo(equal(ref2))
}
}
@ -56,8 +56,8 @@ class ReferenceSpec: QuickSpec {
describe("Reference.hashValue") {
it("should be equal with equal references") {
let repo = Fixtures.simpleRepository
let ref1 = repo.mapGitReference(withName: "refs/heads/master") { Reference($0) }
let ref2 = repo.mapGitReference(withName: "refs/heads/master") { Reference($0) }
let ref1 = repo.withGitReference(withName: "refs/heads/master") { Reference($0) }
let ref2 = repo.withGitReference(withName: "refs/heads/master") { Reference($0) }
expect(ref1.hashValue).to(equal(ref2.hashValue))
}
}
@ -69,7 +69,7 @@ class BranchSpec: QuickSpec {
describe("Branch(pointer)") {
it("should initialize its properties") {
let repo = Fixtures.mantleRepository
let branch = repo.mapGitReference(withName: "refs/heads/master") { Branch($0)! }
let branch = repo.withGitReference(withName: "refs/heads/master") { Branch($0)! }
expect(branch.longName).to(equal("refs/heads/master"))
expect(branch.name).to(equal("master"))
expect(branch.shortName).to(equal(branch.name))
@ -81,7 +81,7 @@ class BranchSpec: QuickSpec {
it("should work with symoblic refs") {
let repo = Fixtures.mantleRepository
let branch = repo.mapGitReference(withName: "refs/remotes/origin/HEAD") { Branch($0)! }
let branch = repo.withGitReference(withName: "refs/remotes/origin/HEAD") { Branch($0)! }
expect(branch.longName).to(equal("refs/remotes/origin/HEAD"))
expect(branch.name).to(equal("origin/HEAD"))
expect(branch.shortName).to(equal(branch.name))
@ -95,15 +95,15 @@ class BranchSpec: QuickSpec {
describe("==(Branch, Branch)") {
it("should be true with equal branches") {
let repo = Fixtures.simpleRepository
let branch1 = repo.mapGitReference(withName: "refs/heads/master") { Branch($0)! }
let branch2 = repo.mapGitReference(withName: "refs/heads/master") { Branch($0)! }
let branch1 = repo.withGitReference(withName: "refs/heads/master") { Branch($0)! }
let branch2 = repo.withGitReference(withName: "refs/heads/master") { Branch($0)! }
expect(branch1).to(equal(branch2))
}
it("should be false with unequal branches") {
let repo = Fixtures.simpleRepository
let branch1 = repo.mapGitReference(withName: "refs/heads/master") { Branch($0)! }
let branch2 = repo.mapGitReference(withName: "refs/heads/another-branch") { Branch($0)! }
let branch1 = repo.withGitReference(withName: "refs/heads/master") { Branch($0)! }
let branch2 = repo.withGitReference(withName: "refs/heads/another-branch") { Branch($0)! }
expect(branch1).notTo(equal(branch2))
}
}
@ -111,8 +111,8 @@ class BranchSpec: QuickSpec {
describe("Branch.hashValue") {
it("should be equal with equal references") {
let repo = Fixtures.simpleRepository
let branch1 = repo.mapGitReference(withName: "refs/heads/master") { Branch($0)! }
let branch2 = repo.mapGitReference(withName: "refs/heads/master") { Branch($0)! }
let branch1 = repo.withGitReference(withName: "refs/heads/master") { Branch($0)! }
let branch2 = repo.withGitReference(withName: "refs/heads/master") { Branch($0)! }
expect(branch1.hashValue).to(equal(branch2.hashValue))
}
}
@ -124,7 +124,7 @@ class TagReferenceSpec: QuickSpec {
describe("TagReference(pointer)") {
it("should work with an annotated tag") {
let repo = Fixtures.simpleRepository
let tag = repo.mapGitReference(withName: "refs/tags/tag-2") { TagReference($0)! }
let tag = repo.withGitReference(withName: "refs/tags/tag-2") { TagReference($0)! }
expect(tag.longName).to(equal("refs/tags/tag-2"))
expect(tag.name).to(equal("tag-2"))
expect(tag.shortName).to(equal(tag.name))
@ -133,7 +133,7 @@ class TagReferenceSpec: QuickSpec {
it("should work with a lightweight tag") {
let repo = Fixtures.mantleRepository
let tag = repo.mapGitReference(withName: "refs/tags/1.5.4") { TagReference($0)! }
let tag = repo.withGitReference(withName: "refs/tags/1.5.4") { TagReference($0)! }
expect(tag.longName).to(equal("refs/tags/1.5.4"))
expect(tag.name).to(equal("1.5.4"))
expect(tag.shortName).to(equal(tag.name))
@ -142,7 +142,7 @@ class TagReferenceSpec: QuickSpec {
it("should return nil if not a tag") {
let repo = Fixtures.simpleRepository
let tag = repo.mapGitReference(withName: "refs/heads/master") { TagReference($0) }
let tag = repo.withGitReference(withName: "refs/heads/master") { TagReference($0) }
expect(tag).to(beNil())
}
}
@ -150,15 +150,15 @@ class TagReferenceSpec: QuickSpec {
describe("==(TagReference, TagReference)") {
it("should be true with equal tag references") {
let repo = Fixtures.simpleRepository
let tag1 = repo.mapGitReference(withName: "refs/tags/tag-2") { TagReference($0)! }
let tag2 = repo.mapGitReference(withName: "refs/tags/tag-2") { TagReference($0)! }
let tag1 = repo.withGitReference(withName: "refs/tags/tag-2") { TagReference($0)! }
let tag2 = repo.withGitReference(withName: "refs/tags/tag-2") { TagReference($0)! }
expect(tag1).to(equal(tag2))
}
it("should be false with unequal tag references") {
let repo = Fixtures.simpleRepository
let tag1 = repo.mapGitReference(withName: "refs/tags/tag-1") { TagReference($0)! }
let tag2 = repo.mapGitReference(withName: "refs/tags/tag-2") { TagReference($0)! }
let tag1 = repo.withGitReference(withName: "refs/tags/tag-1") { TagReference($0)! }
let tag2 = repo.withGitReference(withName: "refs/tags/tag-2") { TagReference($0)! }
expect(tag1).notTo(equal(tag2))
}
}
@ -166,8 +166,8 @@ class TagReferenceSpec: QuickSpec {
describe("TagReference.hashValue") {
it("should be equal with equal references") {
let repo = Fixtures.simpleRepository
let tag1 = repo.mapGitReference(withName: "refs/tags/tag-2") { TagReference($0)! }
let tag2 = repo.mapGitReference(withName: "refs/tags/tag-2") { TagReference($0)! }
let tag1 = repo.withGitReference(withName: "refs/tags/tag-2") { TagReference($0)! }
let tag2 = repo.withGitReference(withName: "refs/tags/tag-2") { TagReference($0)! }
expect(tag1.hashValue).to(equal(tag2.hashValue))
}
}

View File

@ -13,7 +13,7 @@ import Quick
import libgit2
private extension Repository {
func mapGitRemote<T>(withName name: String, transform: (OpaquePointer) -> T) -> T {
func withGitRemote<T>(withName name: String, transform: (OpaquePointer) -> T) -> T {
let repository = self.pointer
var pointer: OpaquePointer? = nil
@ -30,7 +30,7 @@ class RemoteSpec: QuickSpec {
describe("Remote(pointer)") {
it("should initialize its properties") {
let repo = Fixtures.mantleRepository
let remote = repo.mapGitRemote(withName: "upstream") { Remote($0) }
let remote = repo.withGitRemote(withName: "upstream") { Remote($0) }
expect(remote.name).to(equal("upstream"))
expect(remote.URL).to(equal("git@github.com:Mantle/Mantle.git"))
@ -40,15 +40,15 @@ class RemoteSpec: QuickSpec {
describe("==(Remote, Remote)") {
it("should be true with equal objects") {
let repo = Fixtures.mantleRepository
let remote1 = repo.mapGitRemote(withName: "upstream") { Remote($0) }
let remote1 = repo.withGitRemote(withName: "upstream") { Remote($0) }
let remote2 = remote1
expect(remote1).to(equal(remote2))
}
it("should be false with unequal objcets") {
let repo = Fixtures.mantleRepository
let origin = repo.mapGitRemote(withName: "origin") { Remote($0) }
let upstream = repo.mapGitRemote(withName: "upstream") { Remote($0) }
let origin = repo.withGitRemote(withName: "origin") { Remote($0) }
let upstream = repo.withGitRemote(withName: "upstream") { Remote($0) }
expect(origin).notTo(equal(upstream))
}
}
@ -56,7 +56,7 @@ class RemoteSpec: QuickSpec {
describe("Remote.hashValue") {
it("should be equal with equal objcets") {
let repo = Fixtures.mantleRepository
let remote1 = repo.mapGitRemote(withName: "upstream") { Remote($0) }
let remote1 = repo.withGitRemote(withName: "upstream") { Remote($0) }
let remote2 = remote1
expect(remote1.hashValue).to(equal(remote2.hashValue))
}