Swift bindings to libgit2
Swift bindings to 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 uses value objects wherever possible. That means using Swift’s
structs and
enums without holding references to libgit2 objects. This has a number of advantages:
This vastly simplifies the design of long-lived applications, which are the most common use case with Swift. Consequently, SwiftGit2 APIs don’t necessarily map 1-to-1 with libgit2 APIs.
All methods for reading from or writing to a repository are on SwiftGit’s only
class:
Repository. This highlights the failability and mutation of these methods, while freeing up all other instances to be immutable
structs and
enums.
To build SwiftGit2, you'll need the following tools installed locally:
brew install cmake libssh2 libtool autoconf automake pkg-config
The easiest way to add SwiftGit2 to your project is to use Carthage. Simply add
github "SwiftGit2/SwiftGit2"to your
Cartfileand run
carthage update.
If you’d like, you can do things the ~~hard~~ old-fashioned way:
git submodule update --init --recursiveto fetch all of SwiftGit2’s depedencies.
SwiftGit2.xcodeprojto your project’s Xcode project or workspace.
SwiftGit2.frameworkto the “Link Binary With Libraries” phase. SwiftGit2 must also be added to a “Copy Frameworks” build phase.
If you want to build a copy of SwiftGit2 without Carthage, possibly for development:
git submodule update --init --recursiveto clone the submodules
We :heart: to receive pull requests! GitHub makes it easy:
All contributions should match GitHub’s Swift Style Guide.
SwiftGit2 is available under the MIT license.