Go to file
Matt Rubin c6a8c01c87 Set low project deployment targets
This allows other projects which use SwiftGit2 more flexibility in their own deployment targets.
2016-12-10 16:43:31 -08:00
Carthage/Checkouts Update Guanaco 2016-12-10 16:43:02 -08:00
External Update libgit2 to 0.24.3 2016-12-06 09:55:23 -05:00
script Remove xcpretty installation from script/bootstrap 2016-12-09 16:24:26 -08:00
SwiftGit2 Update project, source, and tests to build with Swift 2.3 2016-12-06 12:43:03 -05:00
SwiftGit2.xcodeproj Set low project deployment targets 2016-12-10 16:43:31 -08:00
SwiftGit2.xcworkspace Use ZipArchive to extract fixtures for tests 2016-02-16 16:51:49 +00:00
SwiftGit2Tests Update project, source, and tests to build with Swift 2.3 2016-12-06 12:43:03 -05:00
.gitignore Structure xcode project for iOS 2016-02-22 11:17:41 +00:00
.gitmodules Use a fork of Guanaco which supports Swift 2.3 2016-12-06 12:36:36 -05:00
.travis.yml Configure Travis CI to build with Xcode 8.1 2016-12-10 16:39:39 -08:00
Cartfile Update Result to 2.1.3 2016-12-06 09:54:47 -05:00
Cartfile.private Use a fork of Guanaco which supports Swift 2.3 2016-12-06 12:36:36 -05:00
Cartfile.resolved Update Guanaco 2016-12-10 16:43:02 -08:00
README.md Update println > print 2016-03-08 21:14:51 +01:00

SwiftGit2 Build Status

Swift bindings to libgit2.

let URL: NSURL = ...
let repo = Repository.atURL(URL)
if let repo = repo.value {
    let latestCommit: Result<Commit, NSError> = repo
        .HEAD()
        .flatMap { repo.commitWithOID($0.oid) }
    if let commit = latestCommit.value {
        print("Latest Commit: \(commit.message) by \(commit.author.name)")
    } else {
        print("Could not get commit: \(latestCommit.error)")
    }
} else {
    println("Could not open repository: \(repo.error)")
}

SwiftGit2 requires Xcode 6.3 or later.

Design

SwiftGit2 uses value objects wherever possible. That means using Swifts structs and enums without holding references to libgit2 objects. This has a number of advantages:

  1. Values can be used concurrently.
  2. Consuming values wont result in disk access.
  3. Disk access can be contained to a smaller number of APIs.

This vastly simplifies the design of long-lived applications, which are the most common use case with Swift. Consequently, SwiftGit2 APIs dont necessarily map 1-to-1 with libgit2 APIs.

All methods for reading from or writing to a repository are on SwiftGits only class: Repository. This highlights the failability and mutation of these methods, while freeing up all other instances to be immutable structs and enums.

Importing SwiftGit2

The easiest way to add SwiftGit2 to your project is to use Carthage. Simply add github "SwiftGit2/SwiftGit2" to your Cartfile and run carthage update.

If youd like, you can do things the hard old-fashioned way:

  1. Add SwiftGit2 as a submodule of your projects repository.
  2. Run git submodule update --init --recursive to fetch all of SwiftGit2s depedencies.
  3. Add SwiftGit2.xcodeproj to your projects Xcode project or workspace.
  4. On the “Build Phases” tab of your application target, add SwiftGit2.framework to the “Link Binary With Libraries” phase. SwiftGit2 must also be added to a “Copy Frameworks” build phase.
  5. If you added SwiftGit2 to a project (not a workspace), you will also need to add the appropriate SwiftGit2 target to the “Target Dependencies” of your application.

Contributions

We ❤️ to receive pull requests! GitHub makes it easy:

  1. Fork the repository
  2. Create a branch with your changes
  3. Send a Pull Request

All contributions should match GitHubs Swift Style Guide.

License

SwiftGit2 is available under the MIT license.