Files
swift-bump-version/Sources/GitVersion/Client.swift
2023-03-10 11:07:27 -05:00

39 lines
954 B
Swift

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
import ShellClient
import XCTestDynamicOverlay
public struct GitVersionClient {
private var currentVersion: (String?) throws -> String
public init(currentVersion: @escaping (String?) throws -> String) {
self.currentVersion = currentVersion
}
public func currentVersion(in gitDirectory: String? = nil) throws -> String {
try self.currentVersion(gitDirectory)
}
public mutating func override(with version: String) {
self.currentVersion = { _ in version }
}
}
extension GitVersionClient: TestDependencyKey {
public static let testValue = GitVersionClient(
currentVersion: unimplemented("\(Self.self).currentVersion", placeholder: "")
)
}
extension DependencyValues {
public var gitVersionClient: GitVersionClient {
get { self[GitVersionClient.self] }
set { self[GitVersionClient.self] = newValue }
}
}