├── .github
└── release.yml
├── .gitignore
├── .gitmodules
├── .swiftpm
└── xcode
│ └── package.xcworkspace
│ └── contents.xcworkspacedata
├── LICENSE.md
├── Package.resolved
├── Package.swift
├── README.md
├── Sources
├── CGit
│ ├── CGit.h
│ ├── CGit.m
│ └── module.modulemap
└── Git
│ ├── Git.swift
│ ├── GitError.swift
│ └── Repository.swift
└── build.sh
/.github/release.yml:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Michael F. Collins, III
2 | #
3 | # Permission is hereby granted, free of charge, to any person obtaining a
4 | # copy of this software and associated documentation files (the "Software"),
5 | # to deal in the Software without restrictions, including without limitation
6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 | # and/or sell copies of the Software, and to permit persons to whom the
8 | # Software is furnished to do so, subject to the following conditions:
9 | #
10 | # The above copyright notice and this permission notice shall be included in
11 | # all copies or substantial portions of the Software.
12 | #
13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 | # DEALINGS IN THE SOFTWARE.
20 |
21 | changelog:
22 | exclude:
23 | labels:
24 | - build
25 | - chore
26 | - ci
27 | - documentation
28 | - perf
29 | - refactor
30 | - revert
31 | - style
32 | - test
33 | categories:
34 | - title: Added
35 | labels:
36 | - feature
37 | - title: Changed
38 | labels:
39 | - change
40 | - title: Deprecated
41 | labels:
42 | - deprecate
43 | - title: Removed
44 | labels:
45 | - remove
46 | - title: Fixed
47 | labels:
48 | - fix
49 | - title: Security
50 | labels:
51 | - security
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Michael F. Collins, III
2 | #
3 | # Permission is hereby granted, free of charge, to any person obtaining a
4 | # copy of this software and associated documentation files (the "Software"),
5 | # to deal in the Software without restrictions, including without limitation
6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 | # and/or sell copies of the Software, and to permit persons to whom the
8 | # Software is furnished to do so, subject to the following conditions:
9 | #
10 | # The above copyright notice and this permission notice shall be included in
11 | # all copies or substantial portions of the Software.
12 | #
13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 | # DEALINGS IN THE SOFTWARE.
20 |
21 | build/
22 | *.xcframework/
23 | *.zip
24 |
25 | # Xcode
26 | #
27 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
28 |
29 | ## User settings
30 | xcuserdata/
31 |
32 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
33 | *.xcscmblueprint
34 | *.xccheckout
35 |
36 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
37 | build/
38 | DerivedData/
39 | *.moved-aside
40 | *.pbxuser
41 | !default.pbxuser
42 | *.mode1v3
43 | !default.mode1v3
44 | *.mode2v3
45 | !default.mode2v3
46 | *.perspectivev3
47 | !default.perspectivev3
48 |
49 | ## Obj-C/Swift specific
50 | *.hmap
51 |
52 | ## App packaging
53 | *.ipa
54 | *.dSYM.zip
55 | *.dSYM
56 |
57 | ## Playgrounds
58 | timeline.xctimeline
59 | playground.xcworkspace
60 |
61 | # Swift Package Manager
62 | #
63 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
64 | # Packages/
65 | # Package.pins
66 | # Package.resolved
67 | # *.xcodeproj
68 | #
69 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
70 | # hence it is not needed unless you have added a package configuration file to your project
71 | # .swiftpm
72 |
73 | .build/
74 |
75 | # CocoaPods
76 | #
77 | # We recommend against adding the Pods directory to your .gitignore. However
78 | # you should judge for yourself, the pros and cons are mentioned at:
79 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
80 | #
81 | # Pods/
82 | #
83 | # Add this line if you want to avoid checking in source code from the Xcode workspace
84 | # *.xcworkspace
85 |
86 | # Carthage
87 | #
88 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
89 | # Carthage/Checkouts
90 |
91 | Carthage/Build/
92 |
93 | # Accio dependency management
94 | Dependencies/
95 | .accio/
96 |
97 | # fastlane
98 | #
99 | # It is recommended to not store the screenshots in the git repo.
100 | # Instead, use fastlane to re-generate the screenshots whenever they are needed.
101 | # For more information about the recommended setup visit:
102 | # https://docs.fastlane.tools/best-practices/source-control/#source-control
103 |
104 | fastlane/report.xml
105 | fastlane/Preview.html
106 | fastlane/screenshots/**/*.png
107 | fastlane/test_output
108 |
109 | # Code Injection
110 | #
111 | # After new code Injection tools there's a generated folder /iOSInjectionProject
112 | # https://github.com/johnno1962/injectionforxcode
113 |
114 | iOSInjectionProject/
115 |
116 | # General
117 | .DS_Store
118 | .AppleDouble
119 | .LSOverride
120 |
121 | # Icon must end with two \r
122 | Icon
123 |
124 |
125 | # Thumbnails
126 | ._*
127 |
128 | # Files that might appear in the root of a volume
129 | .DocumentRevisions-V100
130 | .fseventsd
131 | .Spotlight-V100
132 | .TemporaryItems
133 | .Trashes
134 | .VolumeIcon.icns
135 | .com.apple.timemachine.donotpresent
136 |
137 | # Directories potentially created on remote AFP share
138 | .AppleDB
139 | .AppleDesktop
140 | Network Trash Folder
141 | Temporary Items
142 | .apdisk
143 |
144 | .vscode/*
145 | !.vscode/settings.json
146 | !.vscode/tasks.json
147 | !.vscode/launch.json
148 | !.vscode/extensions.json
149 | !.vscode/*.code-snippets
150 |
151 | # Local History for Visual Studio Code
152 | .history/
153 |
154 | # Built Visual Studio Code Extensions
155 | *.vsix
156 |
157 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
158 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
159 |
160 | # User-specific stuff
161 | .idea/**/workspace.xml
162 | .idea/**/tasks.xml
163 | .idea/**/usage.statistics.xml
164 | .idea/**/dictionaries
165 | .idea/**/shelf
166 |
167 | # AWS User-specific
168 | .idea/**/aws.xml
169 |
170 | # Generated files
171 | .idea/**/contentModel.xml
172 |
173 | # Sensitive or high-churn files
174 | .idea/**/dataSources/
175 | .idea/**/dataSources.ids
176 | .idea/**/dataSources.local.xml
177 | .idea/**/sqlDataSources.xml
178 | .idea/**/dynamic.xml
179 | .idea/**/uiDesigner.xml
180 | .idea/**/dbnavigator.xml
181 |
182 | # Gradle
183 | .idea/**/gradle.xml
184 | .idea/**/libraries
185 |
186 | # Gradle and Maven with auto-import
187 | # When using Gradle or Maven with auto-import, you should exclude module files,
188 | # since they will be recreated, and may cause churn. Uncomment if using
189 | # auto-import.
190 | # .idea/artifacts
191 | # .idea/compiler.xml
192 | # .idea/jarRepositories.xml
193 | # .idea/modules.xml
194 | # .idea/*.iml
195 | # .idea/modules
196 | # *.iml
197 | # *.ipr
198 |
199 | # CMake
200 | cmake-build-*/
201 |
202 | # Mongo Explorer plugin
203 | .idea/**/mongoSettings.xml
204 |
205 | # File-based project format
206 | *.iws
207 |
208 | # IntelliJ
209 | out/
210 |
211 | # mpeltonen/sbt-idea plugin
212 | .idea_modules/
213 |
214 | # JIRA plugin
215 | atlassian-ide-plugin.xml
216 |
217 | # Cursive Clojure plugin
218 | .idea/replstate.xml
219 |
220 | # SonarLint plugin
221 | .idea/sonarlint/
222 |
223 | # Crashlytics plugin (for Android Studio and IntelliJ)
224 | com_crashlytics_export_strings.xml
225 | crashlytics.properties
226 | crashlytics-build.properties
227 | fabric.properties
228 |
229 | # Editor-based Rest Client
230 | .idea/httpRequests
231 |
232 | # Android studio 3.1+ serialized cache file
233 | .idea/caches/build_file_checksums.ser
234 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "External/libgit2"]
2 | path = External/libgit2
3 | url = https://github.com/libgit2/libgit2.git
4 | [submodule "External/ios-cmake"]
5 | path = External/ios-cmake
6 | url = https://github.com/leetal/ios-cmake.git
7 |
--------------------------------------------------------------------------------
/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # The MIT License
2 |
3 | Copyright © 2022 Michael F. Collins, III
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/Package.resolved:
--------------------------------------------------------------------------------
1 | {
2 | "pins" : [
3 | {
4 | "identity" : "libssh2-apple",
5 | "kind" : "remoteSourceControl",
6 | "location" : "https://github.com/mfcollins3/libssh2-apple.git",
7 | "state" : {
8 | "revision" : "646fe3ea5a14b1414595f0fc87370385d60c580e",
9 | "version" : "0.1.1"
10 | }
11 | },
12 | {
13 | "identity" : "openssl-apple",
14 | "kind" : "remoteSourceControl",
15 | "location" : "https://github.com/mfcollins3/openssl-apple.git",
16 | "state" : {
17 | "revision" : "d5abe4124f62f118aa305e3cb07c0d370fe49191",
18 | "version" : "0.1.1"
19 | }
20 | }
21 | ],
22 | "version" : 2
23 | }
24 |
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version: 5.7
2 |
3 | // Copyright 2022 Michael F. Collins, III
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a
6 | // copy of this software and associated documentation files (the "Software"),
7 | // to deal in the Software without restrictions, including without limitation
8 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 | // and/or sell copies of the Software, and to permit persons to whom the
10 | // Software is furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 | // DEALINGS IN THE SOFTWARE.
22 |
23 | import PackageDescription
24 |
25 | let package = Package(
26 | name: "Git",
27 | platforms: [
28 | .iOS(.v13),
29 | .macOS(.v10_13)
30 | ],
31 | products: [
32 | .library(
33 | name: "Git",
34 | targets: ["Git"]
35 | ),
36 | ],
37 | dependencies: [
38 | .package(
39 | url: "https://github.com/mfcollins3/libssh2-apple.git",
40 | .upToNextMajor(from: "0.2.0")
41 | )
42 | ],
43 | targets: [
44 | .target(
45 | name: "Git",
46 | dependencies: [
47 | "CGit",
48 | "libgit2",
49 | .product(name: "SSH2", package: "libssh2-apple")
50 | ]
51 | ),
52 | .target(
53 | name: "CGit",
54 | publicHeadersPath: "./",
55 | linkerSettings: [
56 | .linkedLibrary("iconv"),
57 | .linkedLibrary("z")
58 | ]
59 | ),
60 | .binaryTarget(
61 | name: "libgit2",
62 | url: "https://github.com/mfcollins3/libgit2-apple/releases/download/0.2.0/libgit2.zip",
63 | checksum: "c1ea51a12cd8560f8d4fe5df2efd0cc8c6ff1aa87b86534a409d271746eb5223"
64 | )
65 | ]
66 | )
67 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # libgit2 Swift Package
2 |
3 | ## Overview
4 |
5 | This repository implements a Swift package that builds, includes, and wraps the [libgit2](https://libgit2.org) library. This Swift package provides a Swift API that wraps the libgit2 C APIs and allows macOS, iOS, and iPadOS applications to clone and work with Git repositories.
6 |
7 | The libgit2 library that this package builds and wraps was built on top of [libssh2](https://github.com/mfcollins3/libssh2-apple) and [OpenSSL](https://github.com/mfcollins3/openssl-apple).
8 |
9 | This Swift package supports the following platforms:
10 |
11 | * macOS (Apple Silicone and Intel)
12 | * iOS (64-bit only)
13 | * iOS Simulator (Apple Silicone and Intel)
14 | * macOS Catalyst (Apple Silicone and Intel)
15 |
16 | :warning: Please note that in order to use this Swift package, you must also agree to the license terms for libgit2, libssh2, and OpenSSL:
17 |
18 | * [libgit2 License](https://github.com/libgit2/libgit2/blob/v1.5.0/COPYING)
19 | * [libssh2 License](https://github.com/libssh2/libssh2/blob/libssh2-1.10.0/COPYING)
20 | * [OpenSSL License](https://github.com/openssl/openssl/blob/openssl-3.0.7/LICENSE.txt)
21 |
22 | ## Building libgit2
23 |
24 | :warning: Building libgit2 requires you to have installed and build the following prerequisite frameworks first:
25 |
26 | - [OpenSSL](https://github.com/mfcollins3/openssl-apple)
27 | - [libssh2](https://github.com/mfcollins3/libssh2-apple)
28 |
29 | The build process for libgit2 assumes that OpenSSL and libssh2 are siblings in the same parent directory of the file system and will look for them in the `../openssl-apple` and `../libssh2-apple` paths.
30 |
31 | If you need to build libgit2 yourself, I have provided the [build.sh](build.sh) program to automate the process. This program will build libgit2 for all supported platforms and will produce the XCFramework containing the libraries and header files for each platform.
32 |
33 | This repository includes the source code for libgit2 as a Git submodule. To begin, you need to close the repository and load the submodules:
34 |
35 | ```sh
36 | git clone https://github.com/mfcollins3/libgit2-apple.git
37 | cd libssh2-apple
38 | git submodule init
39 | git submodule update
40 | ```
41 |
42 | After cloning the repository, you can run the `build.sh` program without any arguments to build the libgit2 library and produce the XCFramework.
43 |
--------------------------------------------------------------------------------
/Sources/CGit/CGit.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 Michael F. Collins, III
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a
4 | // copy of this software and associated documentation files (the "Software"),
5 | // to deal in the Software without restrictions, including without limitation
6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 | // and/or sell copies of the Software, and to permit persons to whom the
8 | // Software is furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 | // DEALINGS IN THE SOFTWARE.
20 |
21 | #import
22 |
--------------------------------------------------------------------------------
/Sources/CGit/CGit.m:
--------------------------------------------------------------------------------
1 | // Copyright 2022 Michael F. Collins, III
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a
4 | // copy of this software and associated documentation files (the "Software"),
5 | // to deal in the Software without restrictions, including without limitation
6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 | // and/or sell copies of the Software, and to permit persons to whom the
8 | // Software is furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 | // DEALINGS IN THE SOFTWARE.
20 |
21 | #import "CGit.h"
22 |
--------------------------------------------------------------------------------
/Sources/CGit/module.modulemap:
--------------------------------------------------------------------------------
1 | module CGit {
2 | header "CGit.h"
3 | export *
4 | }
--------------------------------------------------------------------------------
/Sources/Git/Git.swift:
--------------------------------------------------------------------------------
1 | // Copyright 2022 Michael F. Collins, III
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a
4 | // copy of this software and associated documentation files (the "Software"),
5 | // to deal in the Software without restrictions, including without limitation
6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 | // and/or sell copies of the Software, and to permit persons to whom the
8 | // Software is furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 | // DEALINGS IN THE SOFTWARE.
20 |
21 | import CGit
22 |
23 | public struct Git {
24 | @discardableResult
25 | public static func initialize() -> Int {
26 | return Int(git_libgit2_init())
27 | }
28 |
29 | @discardableResult
30 | public static func shutDown() -> Int {
31 | return Int(git_libgit2_shutdown())
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Sources/Git/GitError.swift:
--------------------------------------------------------------------------------
1 | // Copyright 2022 Michael F. Collins, III
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a
4 | // copy of this software and associated documentation files (the "Software"),
5 | // to deal in the Software without restrictions, including without limitation
6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 | // and/or sell copies of the Software, and to permit persons to whom the
8 | // Software is furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 | // DEALINGS IN THE SOFTWARE.
20 |
21 | public enum GitError: Error {
22 | case error(Int)
23 | }
24 |
--------------------------------------------------------------------------------
/Sources/Git/Repository.swift:
--------------------------------------------------------------------------------
1 | // Copyright 2022 Michael F. Collins, III
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a
4 | // copy of this software and associated documentation files (the "Software"),
5 | // to deal in the Software without restrictions, including without limitation
6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 | // and/or sell copies of the Software, and to permit persons to whom the
8 | // Software is furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 | // DEALINGS IN THE SOFTWARE.
20 |
21 | import Foundation
22 | import CGit
23 |
24 | public final class Repository {
25 | private let repository: OpaquePointer
26 |
27 | public var commonURL: URL {
28 | let cString = git_repository_commondir(repository)
29 | return URL(
30 | fileURLWithPath: String(cString: cString!),
31 | isDirectory: true
32 | )
33 | }
34 |
35 | init(repository: OpaquePointer) {
36 | self.repository = repository
37 | }
38 |
39 | public static func create(
40 | at url: URL,
41 | isBare bare: Bool = false
42 | ) throws -> Self {
43 | var repository: OpaquePointer? = nil
44 | let errorCode = git_repository_init(
45 | &repository,
46 | url.path,
47 | bare ? 1 : 0
48 | )
49 | guard errorCode == 0 else {
50 | throw GitError.error(Int(errorCode))
51 | }
52 |
53 | return .init(repository: repository!)
54 | }
55 |
56 | deinit {
57 | git_repository_free(repository)
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Copyright 2022 Michael F. Collins, III
4 | #
5 | # Permission is hereby granted, free of charge, to any person obtaining a
6 | # copy of this software and associated documentation files (the "Software"),
7 | # to deal in the Software without restrictions, including without limitation
8 | # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 | # and/or sell copies of the Software, and to permit persons to whom the
10 | # Software is furnished to do so, subject to the following conditions:
11 | #
12 | # The above copyright notice and this permission notice shall be included in
13 | # all copies or substantial portions of the Software.
14 | #
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 | # DEALINGS IN THE SOFTWARE.
22 |
23 | # build.sh
24 | #
25 | # This program automated building libgit2 to be linked into an iOS or macOS
26 | # application, or to be used by other libraries that may be linked into
27 | # applications.
28 | #
29 | # Usage: build.sh
30 |
31 | ROOT_PATH=$PWD
32 |
33 | PLATFORMS="MAC MAC_ARM64 OS64 SIMULATOR64 SIMULATORARM64 MAC_CATALYST MAC_CATALYST_ARM64"
34 | for PLATFORM in $PLATFORMS; do
35 | echo "Building libgit2 for $PLATFORM"
36 |
37 | rm -rf /tmp/libgit2
38 | cp -r External/libgit2 /tmp/
39 |
40 | pushd /tmp/libgit2 > /dev/null
41 |
42 | LOG=/tmp/libgit2-$PLATFORM.log
43 | rm -rf $LOG
44 |
45 | OUTPUT_PATH=$ROOT_PATH/build/$PLATFORM
46 | rm -rf $OUTPUT_PATH
47 |
48 | case $PLATFORM in
49 | "MAC" )
50 | OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/darwin64-x86_64
51 | ;;
52 |
53 | "MAC_ARM64" )
54 | OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/darwin64-arm64
55 | ;;
56 |
57 | "OS64" )
58 | OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/openssl-ios64
59 | ;;
60 |
61 | "SIMULATOR64" )
62 | OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/openssl-iossimulator
63 | ;;
64 |
65 | "SIMULATORARM64" )
66 | OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/openssl-iossimulator-arm
67 | ;;
68 |
69 | "MAC_CATALYST" )
70 | OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/openssl-catalyst
71 | ;;
72 |
73 | "MAC_CATALYST_ARM64" )
74 | OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/openssl-catalyst-arm
75 | ;;
76 | esac
77 |
78 | LIBSSH2_ROOT_DIR=$ROOT_PATH/../libssh2-apple/build/$PLATFORM
79 |
80 | mkdir bin
81 | cd bin
82 | cmake \
83 | -DCMAKE_TOOLCHAIN_FILE=$ROOT_PATH/External/ios-cmake/ios.toolchain.cmake \
84 | -DPLATFORM=$PLATFORM \
85 | -DCMAKE_INSTALL_PREFIX=$OUTPUT_PATH \
86 | -DOPENSSL_ROOT_DIR=$OPENSSL_ROOT_DIR \
87 | -DLIBSSH2_INCLUDE_DIR=$LIBSSH2_ROOT_DIR/include \
88 | -DLIBSSH2_LIBRARY=$LIBSSH2_ROOT_DIR/lib/libssh2.a \
89 | -DENABLE_BITCODE=FALSE \
90 | -DBUILD_SHARED_LIBS=OFF \
91 | -DBUILD_TESTS=OFF \
92 | -DUSE_SSH=ON \
93 | -DGIT_RAND_GETENTROPY=0 \
94 | -DBUILD_CLI=OFF \
95 | .. >> $LOG 2>&1
96 | cmake --build . --target install >> $LOG 2>&1
97 |
98 | popd > /dev/null
99 | done
100 |
101 | echo "Creating the universal library for macOS"
102 |
103 | OUTPUT_PATH=$ROOT_PATH/build/macos
104 | rm -rf $OUTPUT_PATH
105 | mkdir -p $OUTPUT_PATH
106 | lipo -create \
107 | $ROOT_PATH/build/MAC/lib/libgit2.a \
108 | $ROOT_PATH/build/MAC_ARM64/lib/libgit2.a \
109 | -output $OUTPUT_PATH/libgit2.a
110 |
111 | echo "Creating the universal library for iOS Simulator"
112 |
113 | OUTPUT_PATH=$ROOT_PATH/build/iossimulator
114 | rm -rf $OUTPUT_PATH
115 | mkdir -p $OUTPUT_PATH
116 | lipo -create \
117 | $ROOT_PATH/build/SIMULATOR64/lib/libgit2.a \
118 | $ROOT_PATH/build/SIMULATORARM64/lib/libgit2.a \
119 | -output $OUTPUT_PATH/libgit2.a
120 |
121 | echo "Creating the universal library for Catalyst"
122 |
123 | OUTPUT_PATH=$ROOT_PATH/build/catalyst
124 | rm -rf $OUTPUT_PATH
125 | mkdir -p $OUTPUT_PATH
126 | lipo -create \
127 | $ROOT_PATH/build/MAC_CATALYST/lib/libgit2.a \
128 | $ROOT_PATH/build/MAC_CATALYST_ARM64/lib/libgit2.a \
129 | -output $OUTPUT_PATH/libgit2.a
130 |
131 | echo "Creating the libssh2 XCFramework"
132 |
133 | LIB_PATH=$ROOT_PATH
134 | LIBSSH2_PATH=$LIB_PATH/libgit2.xcframework
135 | rm -rf $LIBSSH2_PATH
136 |
137 | xcodebuild -create-xcframework \
138 | -library $ROOT_PATH/build/macos/libgit2.a \
139 | -headers $ROOT_PATH/build/MAC/include \
140 | -library $ROOT_PATH/build/OS64/lib/libgit2.a \
141 | -headers $ROOT_PATH/build/OS64/include \
142 | -library $ROOT_PATH/build/iossimulator/libgit2.a \
143 | -headers $ROOT_PATH/build/SIMULATOR64/include \
144 | -library $ROOT_PATH/build/catalyst/libgit2.a \
145 | -headers $ROOT_PATH/build/MAC_CATALYST/include \
146 | -output $LIBSSH2_PATH
147 |
148 | zip -r libgit2.zip libgit2.xcframework
149 |
150 | echo "Done; cleaning up"
151 | rm -rf $TEMP_PATH
--------------------------------------------------------------------------------