Go to file
Matt Rubin 30c6452d99 Update scripts from Objective-Git, including commits:
commit fbc6bb0c42c3f35725fbe98db4e537e22c9a3aed
Author: Ben Chatelain <ben@octop.ad>
Date:   Mon Apr 11 09:40:00 2016 -0600

    Add clean_externals script

commit f250c3dd8330732d27b49af93a7defae6df0629e
Author: Ben Chatelain <ben@octop.ad>
Date:   Mon Apr 4 22:32:04 2016 -0600

    Enable pipefail

commit 7813f12c75381d87d5ab345c591d00f7184ab150
Author: Ben Chatelain <ben@octop.ad>
Date:   Mon Apr 4 22:19:42 2016 -0600

    Configure cibuild to echo commands and fail on first error

commit 6f802a4b82c634f115b7f941d697ccee3f557a8b
Author: Ben Chatelain <ben@octop.ad>
Date:   Sun Apr 3 13:01:45 2016 -0600

    Overhaul cibuild

    - Replaced xctool with xcodebuild + xcpretty
    - Removed unused cruft and awk scripts

commit 5978a65d53def353ab34d63f02553d7ff7622d1f
Merge: 41d4e28 de7f644
Author: Ben Chatelain <ben@octop.ad>
Date:   Sun Feb 28 21:06:56 2016 -0700

    Merge pull request #554 from libgit2/piet/travis-matrix

    Add matrix build for iOS and Mac

commit 1e3f6c5bdf38c1da26c7cc2b5bd4f6b3098bca2e
Author: Piet Brauer <piet@nerdishbynature.com>
Date:   Wed Feb 24 17:40:52 2016 +0800

    Add matrix build for iOS and Mac

commit 9c13681d06decdb8de327633dc80d9b742a54423
Author: Piet Brauer <piet@nerdishbynature.com>
Date:   Wed Feb 24 16:23:11 2016 +0800

    Enable Bitcode
2016-12-09 13:26:57 -08:00
Carthage/Checkouts Use ZipArchive to extract fixtures for tests 2016-02-16 16:51:49 +00:00
External Add OpenSSL and libssh2 for compilation on iOS 2016-02-16 16:51:49 +00:00
script Update scripts from Objective-Git, including commits: 2016-12-09 13:26:57 -08:00
SwiftGit2 Semanitcally import Foundation rather than Cocoa 2016-02-16 16:51:49 +00:00
SwiftGit2.xcodeproj Structure xcode project for iOS 2016-02-22 11:17:41 +00:00
SwiftGit2.xcworkspace Use ZipArchive to extract fixtures for tests 2016-02-16 16:51:49 +00:00
SwiftGit2Tests Vary the bundle identifier based on platform 2016-02-16 16:51:49 +00:00
.gitignore Structure xcode project for iOS 2016-02-22 11:17:41 +00:00
.gitmodules Add OpenSSL and libssh2 for compilation on iOS 2016-02-16 16:51:49 +00:00
.travis.yml Use script/cibuild for CI 2016-02-16 16:51:43 +00:00
Cartfile updated to Swift 2.0 2016-01-16 14:57:32 +00:00
Cartfile.private Use ZipArchive to extract fixtures for tests 2016-02-16 16:51:49 +00:00
Cartfile.resolved Use ZipArchive to extract fixtures for tests 2016-02-16 16:51:49 +00:00
README.md Add Travis CI build status badge to README.md 2016-01-30 17:58:52 -06: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 {
        println("Latest Commit: \(commit.message) by \(commit.author.name)")
    } else {
        println("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.