diff --git a/SwiftGit2/Repository.swift b/SwiftGit2/Repository.swift index 9349403..526a1ef 100644 --- a/SwiftGit2/Repository.swift +++ b/SwiftGit2/Repository.swift @@ -283,6 +283,13 @@ final public class Repository { } public func tagWithName(name: String) -> Result { - return failure() + return referenceWithName("refs/tags/" + name) + .flatMap { + if let tag = $0 as? TagReference { + return success(tag) + } else { + return failure() + } + } } } diff --git a/SwiftGit2Tests/RepositorySpec.swift b/SwiftGit2Tests/RepositorySpec.swift index 46c103e..086b3bb 100644 --- a/SwiftGit2Tests/RepositorySpec.swift +++ b/SwiftGit2Tests/RepositorySpec.swift @@ -335,5 +335,17 @@ class RepositorySpec: QuickSpec { expect(result.error()).notTo(beNil()) } } + + describe("-tagWithName()") { + it("should return the tag if it exists") { + let result = Fixtures.simpleRepository.tagWithName("tag-2") + expect(result.value()?.longName).to(equal("refs/tags/tag-2")) + } + + it("should error if the branch doesn't exists") { + let result = Fixtures.simpleRepository.tagWithName("nonexistent") + expect(result.error()).notTo(beNil()) + } + } } }