Go to file
Bilal Karim Reffas 1e57a9ff00
Update README.md
2020-04-28 21:08:23 +02:00
Carthage/Checkouts Replace antitypical/Result with the standard library Result type 2019-04-14 17:42:37 -04:00
External Update libgit2 to 0.27.7 2018-10-27 03:34:54 +02:00
libgit2 Change libgit2 to Clibgit2 2019-07-14 11:06:36 +07:00
script Change to a device which should be valid 2020-04-28 09:42:02 +02:00
SwiftGit2 Updated to Swift 5.2 2020-04-27 22:05:20 +02:00
SwiftGit2.xcodeproj Updated to Swift 5.2 2020-04-27 22:05:20 +02:00
SwiftGit2.xcworkspace Replace antitypical/Result with the standard library Result type 2019-04-14 17:42:37 -04:00
SwiftGit2Tests Change libgit2 to Clibgit2 2019-07-14 11:06:36 +07:00
.gitignore Change libgit2 to Clibgit2 2019-07-14 11:06:36 +07:00
.gitmodules Replace antitypical/Result with the standard library Result type 2019-04-14 17:42:37 -04:00
.hound.yml Configure Hound to use the project's SwiftLint config file 2019-04-12 13:58:30 -04:00
.swiftlint.yml Synthesize Equatable conformance for Signature 2019-04-12 16:08:18 -04:00
.travis.yml Updated to Swift 5.2 2020-04-27 22:05:20 +02:00
Cartfile.private Upgrade xcconfigs 2019-04-12 00:31:09 -04:00
Cartfile.resolved Replace antitypical/Result with the standard library Result type 2019-04-14 17:42:37 -04:00
LICENSE.md Add a LICENSE file 2016-12-10 16:21:30 -08:00
README.md Update README.md 2020-04-28 21:08:23 +02:00

SwiftGit2

Build Status Carthage compatible GitHub release Swift 5.2.x

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)")
}

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.

Required Tools

To build SwiftGit2, you'll need the following tools installed locally:

  • cmake
  • libssh2
  • libtool
  • autoconf
  • automake
  • pkg-config
brew install cmake libssh2 libtool autoconf automake pkg-config

Adding SwiftGit2 to your Project

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.

Building SwiftGit2 Manually

If you want to build a copy of SwiftGit2 without Carthage, possibly for development:

  1. Clone SwiftGit2
  2. Run git submodule update --init --recursive to clone the submodules
  3. Build in Xcode

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.