Swift 对 libgit2 的绑定。
let URL: URL = ...
let result = Repository.at(URL)
switch result {
case let .success(repo):
let latestCommit = repo
.HEAD()
.flatMap {
repo.commit($0.oid)
}
switch latestCommit {
case let .success(commit):
print("Latest Commit: \(commit.message) by \(commit.author.name)")
case let .failure(error):
print("Could not get commit: \(error)")
}
case let .failure(error):
print("Could not open repository: \(error)")
}
SwiftGit2 尽可能地使用值对象。这意味着使用 Swift 的 struct
和 enum
,而不持有对 libgit2 对象的引用。这有很多优点
这大大简化了长生命周期应用程序的设计,这是 Swift 最常见的用例。因此,SwiftGit2 API 不一定与 libgit2 API 一一对应。
所有用于从仓库读取或写入的方法都在 SwiftGit 的唯一 class
:Repository
中。这突出了这些方法的可失败性和可变性,同时使所有其他实例成为不可变的 struct
和 enum
。
要构建 SwiftGit2,您需要在本地安装以下工具
brew install cmake libssh2 libtool autoconf automake pkg-config
将 SwiftGit2 添加到您的项目最简单的方法是使用 Carthage。只需将 github "SwiftGit2/SwiftGit2"
添加到您的 Cartfile
并运行 carthage update
。
如果您愿意,您可以采用困难的老式方法
git submodule update --init --recursive
来获取 SwiftGit2 的所有依赖项。SwiftGit2.xcodeproj
添加到您的项目的 Xcode 项目或工作区。SwiftGit2.framework
添加到“Link Binary With Libraries”阶段。SwiftGit2 也必须添加到“Copy Frameworks”构建阶段。如果您想在不使用 Carthage 的情况下构建 SwiftGit2 的副本,可能是为了开发
git submodule update --init --recursive
来克隆子模块我们 ❤️ 欢迎接收 pull request!GitHub 使之变得容易
所有贡献都应符合 GitHub 的 Swift Style Guide。
SwiftGit2 在 MIT 许可证下可用。