Compare commits
381 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 064aed35b6 | |||
| 0505abce23 | |||
| 89b08709e4 | |||
| f4ba5cd328 | |||
| 20b46e76dd | |||
| 5eb09593a0 | |||
| 6836608fca | |||
| 67b2ee52e8 | |||
| a5a9656732 | |||
| 6fb4054d38 | |||
| db091b107e | |||
| e76de59957 | |||
| e7315035df | |||
| 9343544dc9 | |||
| 2b7899198d | |||
| 11ca78320d | |||
| f00bb4699a | |||
| d176b1afaf | |||
| 3ebe0d82a8 | |||
| 8c461732df | |||
| bcccf31665 | |||
| edbd64318c | |||
| b620e0c08e | |||
| dc6a307153 | |||
| ac7f35a976 | |||
| cbb2207031 | |||
| 712cfc50ea | |||
| b253e02ac8 | |||
| 3dc0712e24 | |||
| 827ec79117 | |||
| 08c382a327 | |||
| f577819044 | |||
| 0842b80a3d | |||
| 734d25c15b | |||
| 84e7f996ae | |||
| ab0f592aed | |||
| ed618c6fbc | |||
| 17a0b7514d | |||
| 1e57a9ff00 | |||
| e78fe86a34 | |||
| c8a192f18b | |||
| e7656b1d88 | |||
| 62d0e15491 | |||
| 5ec4722a20 | |||
| c5cbf4cc17 | |||
| b87b66f11a | |||
| 571cdef3c4 | |||
| cc4833b334 | |||
| 3adf7e4205 | |||
| 80f4e60071 | |||
| cd3735cd71 | |||
| 71e9b51a52 | |||
| 9becf1cab0 | |||
| 690f6c9370 | |||
| 19e24dd7d8 | |||
| cb5567d6a5 | |||
| 452979bd64 | |||
| 3db2f74ac4 | |||
| d878fea696 | |||
| 18c4cd8598 | |||
| 00e23d3930 | |||
| df7bd3c2a3 | |||
| c452b80da3 | |||
| e41b2f92a5 | |||
| 12f7d8377d | |||
| e1acee35d6 | |||
| 743083d19d | |||
| 778596b71a | |||
| 00014ab96f | |||
| fb6020ad08 | |||
| d7699324a0 | |||
| dcf36660aa | |||
| 82e873eac8 | |||
| 3a38e20b0c | |||
| dcbbf4cc53 | |||
| 619c2bd165 | |||
| 45be21756c | |||
| 0a1a5d4174 | |||
| 31a755dd49 | |||
| 9f3f9034ee | |||
| ce2443bb3b | |||
| 6c27045ee8 | |||
| 0c9fbe19ee | |||
| 9d2b5e5b87 | |||
| cedeccf6f7 | |||
| 17ff9cf4f5 | |||
| cdfacb944b | |||
| cd9930cc1e | |||
| 56b3907ecf | |||
| 53438583ca | |||
| cf24dc9ed6 | |||
| e16d5c6baa | |||
| a8d0000168 | |||
| 7a7d9280ef | |||
| ef9a46c86b | |||
| 310e7a4167 | |||
| e65206c00c | |||
| f811db8047 | |||
| 8087272bc2 | |||
| 74fe90393f | |||
| 0cb2f8acc5 | |||
| 57cada1356 | |||
| 6d7cde7fe7 | |||
| 08d03fac7c | |||
| db5c22b3a7 | |||
| b29e18833d | |||
| 455ac1143f | |||
| c5017fc6c9 | |||
| 4111097604 | |||
| f152ad76b7 | |||
| 4c7aa2a276 | |||
| e6db3c0896 | |||
| 84d4ae1e33 | |||
| 3d6094b741 | |||
| 026548be12 | |||
| 3db2d73e6e | |||
| f229778abb | |||
| b193c80dc0 | |||
| 25f3ecc4e6 | |||
| 81d2fb210a | |||
| b6e94b291c | |||
| f9d7bd3b61 | |||
| 280ab5b473 | |||
| fb2fa2b5bc | |||
| b1d3488d4c | |||
| 814b954956 | |||
| 4d76f87912 | |||
| d35dac654c | |||
| 97ee009ac5 | |||
| 6e5703dab7 | |||
| 1f23feb0c5 | |||
| 118ba43fce | |||
| 6f59ce5cf3 | |||
| 11ac4767bb | |||
| c5f3b2ccfe | |||
| 0dab27d07b | |||
| 0397b29d24 | |||
| 1a369b7e9e | |||
| 87af7fcb32 | |||
| 98fcae405e | |||
| 28a1757dbe | |||
| 9a9b7a9be8 | |||
| 26f1bb7c86 | |||
| ecb5263f6b | |||
| f98664ecb3 | |||
| c0c382227e | |||
| 225f391171 | |||
| d7fff2c643 | |||
| d8ee830173 | |||
| c7bf00201e | |||
| 69413a0540 | |||
| 3f989ab522 | |||
| 9884657da6 | |||
| afaa96ec57 | |||
| 09ac23471b | |||
| db0a955e03 | |||
| a9f79a3b80 | |||
| e7b6e4509f | |||
| efe1d6eeeb | |||
| 6a59e6557e | |||
| 8bb6e30ff4 | |||
| d7154e6f40 | |||
| 5f4043bb0e | |||
| 3b9beac923 | |||
| 0d56e1b1ce | |||
| 2cff52a3d3 | |||
| 8730bb2d8d | |||
| 046d67ed97 | |||
| 48b804846f | |||
| bf2bc2ed88 | |||
| 42619872f8 | |||
| 99b638131c | |||
| edb1906231 | |||
| 253cf53d2e | |||
| 95c7da4e1b | |||
| f422571d38 | |||
| 6fc4a0c7bb | |||
| 2173a68e93 | |||
| b582e1e642 | |||
| c4388f0a07 | |||
| 82e90d3c75 | |||
| 1af59416d9 | |||
| c5eb8036d0 | |||
| 31680a50a3 | |||
| 593c4069b5 | |||
| f635f50b84 | |||
| 242741a950 | |||
| 5d0255b84c | |||
| 7ecfb710d3 | |||
| 18691cb4e6 | |||
| 06a3b62014 | |||
| a58f849456 | |||
| 8d1aaa672f | |||
| dfc2614cb2 | |||
| 9520fa03a6 | |||
| c4b7ce3716 | |||
| 8088f8b11f | |||
| 42d92319ef | |||
| d09d1f49b3 | |||
| 46cad0e668 | |||
| 500ae6dc90 | |||
| c7b8ae914f | |||
| 4dd24cad97 | |||
| 23194dd7a3 | |||
| 915b07f4a9 | |||
| 96e9cf61a7 | |||
| aa9f066e04 | |||
| de2984c695 | |||
| dc2edddac6 | |||
| e69e5ca153 | |||
| 23abfc6f6a | |||
| 3b04a2b94a | |||
| 66866049ee | |||
| 9eb91a8605 | |||
| 18ee34f681 | |||
| baa619520d | |||
| d6d9d77488 | |||
| 43d26912a1 | |||
| 0785b70123 | |||
| 20365249f9 | |||
| 9a2f5a5b31 | |||
| 3c5ffa2ba5 | |||
| 6257318a34 | |||
| f2d94c4322 | |||
| d1d0118bba | |||
| c57ea50b85 | |||
| 5b41c977d2 | |||
| 4cadad501e | |||
| bb387eb7ab | |||
| f10c8d03dd | |||
| 31a0a3dd30 | |||
| b074eff7d7 | |||
| e42270372c | |||
| 4864cc4753 | |||
| 2e7a0ce1cd | |||
| 36f934d2b6 | |||
| 98c0733592 | |||
| 992ba7bf8a | |||
| 545bf12645 | |||
| 62619af5e8 | |||
| 4741790d2c | |||
| e148cd2530 | |||
| baeb5cb3e2 | |||
| 28c01d4943 | |||
| a0f0e49ee6 | |||
| 2cc5737d77 | |||
| c746c720c3 | |||
| 6da9e7810c | |||
| 597a2fd000 | |||
| 9c13bee3ad | |||
| a4e26a4b99 | |||
| b94b975236 | |||
| afbd6672cd | |||
| ca028a4e4f | |||
| 21ee7a44c5 | |||
| 93ddcd3e9a | |||
| 2a90c7b5f3 | |||
| 94c7de848f | |||
| 3c3c3ff004 | |||
| 561b0453c5 | |||
| b660b09c7a | |||
| 31d3412310 | |||
| c8ce857e42 | |||
| 416dbaa08f | |||
| 3da641e708 | |||
| 3150d56e28 | |||
| 0f29b097e1 | |||
| 66cf46d67d | |||
| 686a41fbb7 | |||
| 8692c46a0c | |||
| 7b52e822ce | |||
| 1fb378dbaf | |||
| 160428039e | |||
| 6244bdfdc6 | |||
| 755dfe08f6 | |||
| 003464dde8 | |||
| b6c3c795bc | |||
| 59cccf62d0 | |||
| f97fcfab38 | |||
| 485b637d47 | |||
| 0218aa1123 | |||
| 9bae55743b | |||
| 4198f090fe | |||
| de0cee0806 | |||
| 869fb17c8b | |||
| fe97151d16 | |||
| d38954516a | |||
| 2289706481 | |||
| c151e05911 | |||
| dc8a391290 | |||
| 717abc1cb3 | |||
| ae34822fab | |||
| 236712b9d3 | |||
| c4c40f5173 | |||
| eee3ca4446 | |||
| 7ffe3bbb3b | |||
| a8d16010ff | |||
| d1b72d059d | |||
| a4072adf1e | |||
| d4e2413e50 | |||
| c2535ace3f | |||
| 14b7df3dac | |||
| 841e110812 | |||
| 7277c09763 | |||
| c6a8c01c87 | |||
| 322ff97332 | |||
| a4b15a2f6c | |||
| f888eefb09 | |||
| 7c9bac1ca1 | |||
| b3f71b9553 | |||
| addee4a13f | |||
| 7f5d098579 | |||
| c4544b2904 | |||
| a3006dc674 | |||
| a9c5fac6eb | |||
| 80fd0ca939 | |||
| 9552145b9e | |||
| 4a562fd653 | |||
| 853ed3f75a | |||
| 30c6452d99 | |||
| 6ba47e317d | |||
| e735a7d4cb | |||
| 40c40c6b2d | |||
| 76b3c9224e | |||
| ac3fde8763 | |||
| e1c8a536d1 | |||
| 775c582e29 | |||
| 9ea09594d4 | |||
| f097301ed7 | |||
| 60cb395cc6 | |||
| c3b155cfd4 | |||
| b8885e6509 | |||
| 86fcebd10c | |||
| 876cd3edc1 | |||
| fe02162a6a | |||
| 393414fef6 | |||
| 6268766594 | |||
| 281d1aed2b | |||
| e52387ce4f | |||
| 1292c6a78f | |||
| 1d28313725 | |||
| 8ea6f56fa0 | |||
| 97cd921046 | |||
| 433ef719eb | |||
| 778cf2b52e | |||
| 1e1655e0c9 | |||
| 6c0e55f3ca | |||
| 77e26af360 | |||
| ae91f54aa7 | |||
| 7da9b0a084 | |||
| aec66f930c | |||
| a6cde2b1d1 | |||
| cb5daab309 | |||
| 2c1fb0e21f | |||
| 92582ef3e8 | |||
| d6787e905d | |||
| b7ae8cfc9a | |||
| 9d837b1a40 | |||
| 46fddb0082 | |||
| 374c856484 | |||
| 4149f2ce5d | |||
| 9ce75607bc | |||
| d3f27174b4 | |||
| dcc9fcfd8c | |||
| 5c8a6000c4 | |||
| 44fd952378 | |||
| c4737c1098 | |||
| f6b8483145 | |||
| 37bdb9eb0b | |||
| 6e737b1190 | |||
| e550eea24f | |||
| 03032d0074 | |||
| 1d491b5dbc | |||
| 7d32dbd36e | |||
| 35f823f38d | |||
| bfe2d6d053 | |||
| 4f919ccdac | |||
| 3a7f826c51 | |||
| acd1cab2a5 | |||
| b2a8bf6f0b | |||
| 1ace7b2eb7 |
@@ -0,0 +1,11 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
@@ -0,0 +1,45 @@
|
||||
name: pull request
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
xcode: [ Xcode_14.3, Xcode_15.2.0 ]
|
||||
os: [ macos-13 ]
|
||||
include:
|
||||
- xcode: Xcode_15.4
|
||||
os: macos-14
|
||||
- xcode: Xcode_16.2
|
||||
os: macos-14
|
||||
steps:
|
||||
- name: ls Xcode
|
||||
run: ls -la /Applications/Xcode*
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: recursive
|
||||
- name: get architecture
|
||||
run: |
|
||||
echo "ARCHITECTURE=$(uname -m)" >> $GITHUB_ENV
|
||||
echo $(uname -m)
|
||||
- name: Set XCode Version
|
||||
run: sudo xcode-select -s /Applications/${{ matrix.xcode }}.app
|
||||
- name: schemes list
|
||||
run: xcodebuild -workspace SwiftGit2.xcworkspace -list
|
||||
- name: update_libgit2
|
||||
run: script/update_libgit2
|
||||
- name: bootstrap
|
||||
run: script/bootstrap
|
||||
# - name: cibuild
|
||||
# run: script/cibuild
|
||||
- name: Build project
|
||||
run: xcodebuild -workspace SwiftGit2.xcworkspace -scheme SwiftGit2-OSX -archivePath ./SwiftGit2 archive ARCHS="${{ env.ARCHITECTURE }}"
|
||||
+25
@@ -1,3 +1,6 @@
|
||||
.vscode/
|
||||
.build/
|
||||
|
||||
# Xcode
|
||||
#
|
||||
build/
|
||||
@@ -16,6 +19,28 @@ DerivedData
|
||||
*.hmap
|
||||
*.ipa
|
||||
*.xcuserstate
|
||||
*.xcscmblueprint
|
||||
*.idea*
|
||||
|
||||
External/libgit2*.a
|
||||
External/libgit2-mac
|
||||
External/ios-openssl
|
||||
External/libgit2-ios
|
||||
External/libssh2-ios
|
||||
|
||||
### fastlane ###
|
||||
# fastlane - A streamlined workflow tool for Cocoa deployment
|
||||
|
||||
# fastlane specific
|
||||
fastlane/report.xml
|
||||
|
||||
# deliver temporary files
|
||||
fastlane/Preview.html
|
||||
|
||||
# snapshot generated screenshots
|
||||
fastlane/screenshots/**/*.png
|
||||
fastlane/screenshots/screenshots.html
|
||||
|
||||
# scan temporary files
|
||||
fastlane/test_output
|
||||
test_output
|
||||
|
||||
+9
-6
@@ -1,12 +1,6 @@
|
||||
[submodule "External/libgit2"]
|
||||
path = External/libgit2
|
||||
url = https://github.com/libgit2/libgit2.git
|
||||
[submodule "Carthage/Checkouts/Guanaco"]
|
||||
path = Carthage/Checkouts/Guanaco
|
||||
url = https://github.com/modocache/Guanaco.git
|
||||
[submodule "Carthage/Checkouts/LlamaKit"]
|
||||
path = Carthage/Checkouts/LlamaKit
|
||||
url = https://github.com/LlamaKit/LlamaKit.git
|
||||
[submodule "Carthage/Checkouts/Nimble"]
|
||||
path = Carthage/Checkouts/Nimble
|
||||
url = https://github.com/Quick/Nimble.git
|
||||
@@ -16,3 +10,12 @@
|
||||
[submodule "Carthage/Checkouts/xcconfigs"]
|
||||
path = Carthage/Checkouts/xcconfigs
|
||||
url = https://github.com/jspahrsummers/xcconfigs.git
|
||||
[submodule "Carthage/Checkouts/ZipArchive"]
|
||||
path = Carthage/Checkouts/ZipArchive
|
||||
url = https://github.com/ZipArchive/ZipArchive.git
|
||||
[submodule "External/libssh2"]
|
||||
path = External/libssh2
|
||||
url = https://github.com/libssh2/libssh2.git
|
||||
[submodule "External/openssl"]
|
||||
path = External/openssl
|
||||
url = https://github.com/openssl/openssl.git
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# Configuration for Hound (https://houndci.com)
|
||||
|
||||
swiftlint:
|
||||
config_file: .swiftlint.yml
|
||||
@@ -0,0 +1,79 @@
|
||||
disabled_rules:
|
||||
- file_length
|
||||
- force_cast
|
||||
- force_try
|
||||
- function_body_length
|
||||
- identifier_name
|
||||
- redundant_optional_initialization
|
||||
- type_body_length
|
||||
|
||||
opt_in_rules:
|
||||
- array_init
|
||||
- attributes
|
||||
- closure_end_indentation
|
||||
- closure_spacing
|
||||
- collection_alignment
|
||||
- conditional_returns_on_newline
|
||||
- contains_over_first_not_nil
|
||||
- convenience_type
|
||||
- discouraged_object_literal
|
||||
- discouraged_optional_boolean
|
||||
- discouraged_optional_collection
|
||||
- empty_count
|
||||
- empty_string
|
||||
- empty_xctest_method
|
||||
- explicit_enum_raw_value
|
||||
- explicit_init
|
||||
- extension_access_modifier
|
||||
- fallthrough
|
||||
- fatal_error_message
|
||||
- first_where
|
||||
- function_default_parameter_at_end
|
||||
- identical_operands
|
||||
- implicitly_unwrapped_optional
|
||||
- joined_default_parameter
|
||||
- last_where
|
||||
- legacy_random
|
||||
- literal_expression_end_indentation
|
||||
- lower_acl_than_parent
|
||||
- modifier_order
|
||||
- multiline_arguments
|
||||
- multiline_function_chains
|
||||
- multiline_literal_brackets
|
||||
- nslocalizedstring_key
|
||||
- overridden_super_call
|
||||
- override_in_extension
|
||||
- private_action
|
||||
- private_outlet
|
||||
- prohibited_super_call
|
||||
- quick_discouraged_call
|
||||
- quick_discouraged_focused_test
|
||||
- quick_discouraged_pending_test
|
||||
- redundant_nil_coalescing
|
||||
- redundant_type_annotation
|
||||
- sorted_first_last
|
||||
- static_operator
|
||||
- strict_fileprivate
|
||||
- switch_case_on_newline
|
||||
- toggle_bool
|
||||
- unavailable_function
|
||||
- untyped_error_in_catch
|
||||
- unused_import
|
||||
- unused_private_declaration
|
||||
- vertical_parameter_alignment_on_call
|
||||
- xct_specific_matcher
|
||||
- yoda_condition
|
||||
|
||||
excluded:
|
||||
- Carthage
|
||||
- External
|
||||
|
||||
line_length:
|
||||
ignores_function_declarations: true
|
||||
|
||||
trailing_comma:
|
||||
mandatory_comma: true
|
||||
|
||||
trailing_whitespace:
|
||||
ignores_comments: false
|
||||
ignores_empty_lines: false
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
github "jspahrsummers/xcconfigs" >= 0.7.2
|
||||
github "Quick/Quick" "155f858bce082373fc60d0c0a63415bf336c676b"
|
||||
github "Quick/Nimble" "c511bc1558c1cbd4685cdb326a58c6c6b026140e"
|
||||
github "modocache/Guanaco" "18126c0c8ba9a7cb3cc5d43aec83c81047410ab6"
|
||||
github "jspahrsummers/xcconfigs" ~> 1.1
|
||||
github "Quick/Quick" ~> 2.0
|
||||
github "Quick/Nimble" ~> 8.0
|
||||
github "ZipArchive/ZipArchive" ~> 2.0
|
||||
|
||||
+4
-5
@@ -1,5 +1,4 @@
|
||||
github "modocache/Guanaco" "18126c0c8ba9a7cb3cc5d43aec83c81047410ab6"
|
||||
github "LlamaKit/LlamaKit" "v0.6.0"
|
||||
github "Quick/Nimble" "c511bc1558c1cbd4685cdb326a58c6c6b026140e"
|
||||
github "Quick/Quick" "155f858bce082373fc60d0c0a63415bf336c676b"
|
||||
github "jspahrsummers/xcconfigs" "0.7.2"
|
||||
github "Quick/Nimble" "v8.1.2"
|
||||
github "Quick/Quick" "v2.2.1"
|
||||
github "ZipArchive/ZipArchive" "v2.2.3"
|
||||
github "jspahrsummers/xcconfigs" "1.1"
|
||||
|
||||
Vendored
-1
Submodule Carthage/Checkouts/Guanaco deleted from 18126c0c8b
Vendored
-1
Submodule Carthage/Checkouts/LlamaKit deleted from e28d7f6e82
Vendored
+1
-1
Submodule Carthage/Checkouts/Nimble updated: c511bc1558...7a46a5fc86
Vendored
+1
-1
Submodule Carthage/Checkouts/Quick updated: 155f858bce...09b3becb37
+1
Submodule Carthage/Checkouts/ZipArchive added at f3379e6efa
Vendored
+1
-1
Submodule Carthage/Checkouts/xcconfigs updated: 2e77204b59...4ced0ad5a9
Vendored
-1
@@ -1 +0,0 @@
|
||||
/usr/local/opt/openssl/lib/libcrypto.a
|
||||
Vendored
+1
-1
Submodule External/libgit2 updated: 366e53d3da...7f4fa17862
+1
Submodule External/libssh2 added at 30e9c1347e
Vendored
-1
@@ -1 +0,0 @@
|
||||
/usr/local/opt/openssl/lib/libssl.a
|
||||
+1
Submodule External/openssl added at e71ebf275d
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2014-2016 SwiftGit2 contributors
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
@@ -1,25 +1,34 @@
|
||||
# SwiftGit2
|
||||
[](#carthage)
|
||||
[](https://github.com/SwiftGit2/SwiftGit2/releases)
|
||||

|
||||
|
||||
Swift bindings to [libgit2](https://github.com/libgit2/libgit2).
|
||||
|
||||
```swift
|
||||
let URL: NSURL = ...
|
||||
let repo = Repository.atURL(URL)
|
||||
if let repo = repo.value {
|
||||
let latestCommit: Result<Commit, NSError> = repo
|
||||
let URL: URL = ...
|
||||
let result = Repository.at(URL)
|
||||
switch result {
|
||||
case let .success(repo):
|
||||
let latestCommit = 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)")
|
||||
.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)")
|
||||
}
|
||||
} else {
|
||||
println("Could not open repository: \(repo.error)")
|
||||
|
||||
case let .failure(error):
|
||||
print("Could not open repository: \(error)")
|
||||
}
|
||||
```
|
||||
|
||||
SwiftGit2 requires Xcode 6.3ß2 or later.
|
||||
|
||||
## Design
|
||||
SwiftGit2 uses value objects wherever possible. That means using Swift’s `struct`s and `enum`s without holding references to libgit2 objects. This has a number of advantages:
|
||||
|
||||
@@ -31,7 +40,21 @@ This vastly simplifies the design of long-lived applications, which are the most
|
||||
|
||||
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 `struct`s and `enum`s.
|
||||
|
||||
## Importing SwiftGit2
|
||||
## 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](https://github.com/Carthage/Carthage). Simply add `github "SwiftGit2/SwiftGit2"` to your `Cartfile` and run `carthage update`.
|
||||
|
||||
If you’d like, you can do things the ~~hard~~ old-fashioned way:
|
||||
@@ -42,6 +65,13 @@ If you’d like, you can do things the ~~hard~~ old-fashioned way:
|
||||
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 :heart: to receive pull requests! GitHub makes it easy:
|
||||
|
||||
|
||||
+672
-447
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0630"
|
||||
LastUpgradeVersion = "1220"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -20,13 +20,36 @@
|
||||
ReferencedContainer = "container:SwiftGit2.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "C9CE0DD21E0710BD0053205D"
|
||||
BuildableName = "SwiftLint"
|
||||
BlueprintName = "SwiftLint"
|
||||
ReferencedContainer = "container:SwiftGit2.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
buildConfiguration = "Debug">
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "BEB31F221A0D6F7A00F525B9"
|
||||
BuildableName = "SwiftGit2.framework"
|
||||
BlueprintName = "SwiftGit2-OSX"
|
||||
ReferencedContainer = "container:SwiftGit2.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
@@ -41,13 +64,14 @@
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Debug"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
@@ -58,14 +82,12 @@
|
||||
ReferencedContainer = "container:SwiftGit2.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Release"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1220"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "621E66611C72958800A0F352"
|
||||
BuildableName = "SwiftGit2.framework"
|
||||
BlueprintName = "SwiftGit2-iOS"
|
||||
ReferencedContainer = "container:SwiftGit2.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "C9CE0DD21E0710BD0053205D"
|
||||
BuildableName = "SwiftLint"
|
||||
BlueprintName = "SwiftLint"
|
||||
ReferencedContainer = "container:SwiftGit2.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "621E66611C72958800A0F352"
|
||||
BuildableName = "SwiftGit2.framework"
|
||||
BlueprintName = "SwiftGit2-iOS"
|
||||
ReferencedContainer = "container:SwiftGit2.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "621E66B61C72958D00A0F352"
|
||||
BuildableName = "SwiftGit2-iOSTests.xctest"
|
||||
BlueprintName = "SwiftGit2-iOSTests"
|
||||
ReferencedContainer = "container:SwiftGit2.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "621E66611C72958800A0F352"
|
||||
BuildableName = "SwiftGit2.framework"
|
||||
BlueprintName = "SwiftGit2-iOS"
|
||||
ReferencedContainer = "container:SwiftGit2.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "621E66611C72958800A0F352"
|
||||
BuildableName = "SwiftGit2.framework"
|
||||
BlueprintName = "SwiftGit2-iOS"
|
||||
ReferencedContainer = "container:SwiftGit2.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
+1
-4
@@ -4,9 +4,6 @@
|
||||
<FileRef
|
||||
location = "group:SwiftGit2.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:Carthage/Checkouts/LlamaKit/LlamaKit.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:Carthage/Checkouts/Quick/Quick.xcodeproj">
|
||||
</FileRef>
|
||||
@@ -14,6 +11,6 @@
|
||||
location = "group:Carthage/Checkouts/Nimble/Nimble.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:Carthage/Checkouts/Guanaco/Guanaco.xcodeproj">
|
||||
location = "group:Carthage/Checkouts/ZipArchive/ZipArchive.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,107 @@
|
||||
//
|
||||
// CheckoutStrategy.swift
|
||||
// SwiftGit2
|
||||
//
|
||||
// Created by Matt Diephouse on 4/1/15.
|
||||
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import Clibgit2
|
||||
|
||||
/// The flags defining how a checkout should be performed.
|
||||
/// More detail is available in the libgit2 documentation for `git_checkout_strategy_t`.
|
||||
public struct CheckoutStrategy: OptionSet {
|
||||
private let value: UInt
|
||||
|
||||
// MARK: - Initialization
|
||||
|
||||
/// Create an instance initialized with `nil`.
|
||||
public init(nilLiteral: ()) {
|
||||
self.value = 0
|
||||
}
|
||||
|
||||
public init(rawValue value: UInt) {
|
||||
self.value = value
|
||||
}
|
||||
|
||||
public init(_ strategy: git_checkout_strategy_t) {
|
||||
self.value = UInt(strategy.rawValue)
|
||||
}
|
||||
|
||||
public static var allZeros: CheckoutStrategy {
|
||||
return self.init(rawValue: 0)
|
||||
}
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
public var rawValue: UInt {
|
||||
return value
|
||||
}
|
||||
|
||||
public var gitCheckoutStrategy: git_checkout_strategy_t {
|
||||
return git_checkout_strategy_t(UInt32(self.value))
|
||||
}
|
||||
|
||||
// MARK: - Values
|
||||
|
||||
/// Default is a dry run, no actual updates.
|
||||
public static let None = CheckoutStrategy(GIT_CHECKOUT_NONE)
|
||||
|
||||
/// Allow safe updates that cannot overwrite uncommitted data.
|
||||
public static let Safe = CheckoutStrategy(GIT_CHECKOUT_SAFE)
|
||||
|
||||
/// Allow all updates to force working directory to look like index
|
||||
public static let Force = CheckoutStrategy(GIT_CHECKOUT_FORCE)
|
||||
|
||||
/// Allow checkout to recreate missing files.
|
||||
public static let RecreateMissing = CheckoutStrategy(GIT_CHECKOUT_RECREATE_MISSING)
|
||||
|
||||
/// Allow checkout to make safe updates even if conflicts are found.
|
||||
public static let AllowConflicts = CheckoutStrategy(GIT_CHECKOUT_ALLOW_CONFLICTS)
|
||||
|
||||
/// Remove untracked files not in index (that are not ignored).
|
||||
public static let RemoveUntracked = CheckoutStrategy(GIT_CHECKOUT_REMOVE_UNTRACKED)
|
||||
|
||||
/// Remove ignored files not in index.
|
||||
public static let RemoveIgnored = CheckoutStrategy(GIT_CHECKOUT_REMOVE_IGNORED)
|
||||
|
||||
/// Only update existing files, don't create new ones.
|
||||
public static let UpdateOnly = CheckoutStrategy(GIT_CHECKOUT_UPDATE_ONLY)
|
||||
|
||||
/// Normally checkout updates index entries as it goes; this stops that.
|
||||
/// Implies `DontWriteIndex`.
|
||||
public static let DontUpdateIndex = CheckoutStrategy(GIT_CHECKOUT_DONT_UPDATE_INDEX)
|
||||
|
||||
/// Don't refresh index/config/etc before doing checkout
|
||||
public static let NoRefresh = CheckoutStrategy(GIT_CHECKOUT_NO_REFRESH)
|
||||
|
||||
/// Allow checkout to skip unmerged files
|
||||
public static let SkipUnmerged = CheckoutStrategy(GIT_CHECKOUT_SKIP_UNMERGED)
|
||||
|
||||
/// For unmerged files, checkout stage 2 from index
|
||||
public static let UseOurs = CheckoutStrategy(GIT_CHECKOUT_USE_OURS)
|
||||
|
||||
/// For unmerged files, checkout stage 3 from index
|
||||
public static let UseTheirs = CheckoutStrategy(GIT_CHECKOUT_USE_THEIRS)
|
||||
|
||||
/// Treat pathspec as simple list of exact match file paths
|
||||
public static let DisablePathspecMatch = CheckoutStrategy(GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH)
|
||||
|
||||
/// Ignore directories in use, they will be left empty
|
||||
public static let SkipLockedDirectories = CheckoutStrategy(GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES)
|
||||
|
||||
/// Don't overwrite ignored files that exist in the checkout target
|
||||
public static let DontOverwriteIgnored = CheckoutStrategy(GIT_CHECKOUT_DONT_OVERWRITE_IGNORED)
|
||||
|
||||
/// Write normal merge files for conflicts
|
||||
public static let ConflictStyleMerge = CheckoutStrategy(GIT_CHECKOUT_CONFLICT_STYLE_MERGE)
|
||||
|
||||
/// Include common ancestor data in diff3 format files for conflicts
|
||||
public static let ConflictStyleDiff3 = CheckoutStrategy(GIT_CHECKOUT_CONFLICT_STYLE_DIFF3)
|
||||
|
||||
/// Don't overwrite existing files or folders
|
||||
public static let DontRemoveExisting = CheckoutStrategy(GIT_CHECKOUT_DONT_REMOVE_EXISTING)
|
||||
|
||||
/// Normally checkout writes the index upon completion; this prevents that.
|
||||
public static let DontWriteIndex = CheckoutStrategy(GIT_CHECKOUT_DONT_WRITE_INDEX)
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// Created by Arnon Keereena on 4/28/17.
|
||||
// Copyright (c) 2017 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Clibgit2
|
||||
|
||||
public class CommitIterator: IteratorProtocol, Sequence {
|
||||
public typealias Iterator = CommitIterator
|
||||
public typealias Element = Result<Commit, NSError>
|
||||
let repo: Repository
|
||||
private var revisionWalker: OpaquePointer?
|
||||
|
||||
private enum Next {
|
||||
case over
|
||||
case okay
|
||||
case error(NSError)
|
||||
|
||||
init(_ result: Int32, name: String) {
|
||||
switch result {
|
||||
case GIT_ITEROVER.rawValue:
|
||||
self = .over
|
||||
case GIT_OK.rawValue:
|
||||
self = .okay
|
||||
default:
|
||||
self = .error(NSError(gitError: result, pointOfFailure: name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(repo: Repository, root: git_oid) {
|
||||
self.repo = repo
|
||||
setupRevisionWalker(root: root)
|
||||
}
|
||||
|
||||
deinit {
|
||||
git_revwalk_free(self.revisionWalker)
|
||||
}
|
||||
|
||||
private func setupRevisionWalker(root: git_oid) {
|
||||
var oid = root
|
||||
git_revwalk_new(&revisionWalker, repo.pointer)
|
||||
git_revwalk_sorting(revisionWalker, GIT_SORT_TOPOLOGICAL.rawValue)
|
||||
git_revwalk_sorting(revisionWalker, GIT_SORT_TIME.rawValue)
|
||||
git_revwalk_push(revisionWalker, &oid)
|
||||
}
|
||||
|
||||
public func next() -> Element? {
|
||||
var oid = git_oid()
|
||||
let revwalkGitResult = git_revwalk_next(&oid, revisionWalker)
|
||||
let nextResult = Next(revwalkGitResult, name: "git_revwalk_next")
|
||||
switch nextResult {
|
||||
case let .error(error):
|
||||
return Result.failure(error)
|
||||
case .over:
|
||||
return nil
|
||||
case .okay:
|
||||
var unsafeCommit: OpaquePointer? = nil
|
||||
let lookupGitResult = git_commit_lookup(&unsafeCommit, repo.pointer, &oid)
|
||||
guard lookupGitResult == GIT_OK.rawValue,
|
||||
let unwrapCommit = unsafeCommit else {
|
||||
return Result.failure(NSError(gitError: lookupGitResult, pointOfFailure: "git_commit_lookup"))
|
||||
}
|
||||
let result: Element = Result.success(Commit(unwrapCommit))
|
||||
git_commit_free(unsafeCommit)
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// Credentials.swift
|
||||
// SwiftGit2
|
||||
//
|
||||
// Created by Tom Booth on 29/02/2016.
|
||||
// Copyright © 2016 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import Clibgit2
|
||||
|
||||
private class Wrapper<T> {
|
||||
let value: T
|
||||
|
||||
init(_ value: T) {
|
||||
self.value = value
|
||||
}
|
||||
}
|
||||
|
||||
public enum Credentials {
|
||||
case `default`
|
||||
case sshAgent
|
||||
case plaintext(username: String, password: String)
|
||||
case sshMemory(username: String, publicKey: String, privateKey: String, passphrase: String)
|
||||
|
||||
internal static func fromPointer(_ pointer: UnsafeMutableRawPointer) -> Credentials {
|
||||
return Unmanaged<Wrapper<Credentials>>.fromOpaque(UnsafeRawPointer(pointer)).takeRetainedValue().value
|
||||
}
|
||||
|
||||
internal func toPointer() -> UnsafeMutableRawPointer {
|
||||
return Unmanaged.passRetained(Wrapper(self)).toOpaque()
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle the request of credentials, passing through to a wrapped block after converting the arguments.
|
||||
/// Converts the result to the correct error code required by libgit2 (0 = success, 1 = rejected setting creds,
|
||||
/// -1 = error)
|
||||
internal func credentialsCallback(
|
||||
cred: UnsafeMutablePointer<UnsafeMutablePointer<git_cred>?>?,
|
||||
url: UnsafePointer<CChar>?,
|
||||
username: UnsafePointer<CChar>?,
|
||||
_: UInt32,
|
||||
payload: UnsafeMutableRawPointer? ) -> Int32 {
|
||||
|
||||
let result: Int32
|
||||
|
||||
// Find username_from_url
|
||||
let name = username.map(String.init(cString:))
|
||||
|
||||
switch Credentials.fromPointer(payload!) {
|
||||
case .default:
|
||||
result = git_cred_default_new(cred)
|
||||
case .sshAgent:
|
||||
result = git_cred_ssh_key_from_agent(cred, name!)
|
||||
case .plaintext(let username, let password):
|
||||
result = git_cred_userpass_plaintext_new(cred, username, password)
|
||||
case .sshMemory(let username, let publicKey, let privateKey, let passphrase):
|
||||
result = git_cred_ssh_key_memory_new(cred, username, publicKey, privateKey, passphrase)
|
||||
}
|
||||
|
||||
return (result != GIT_OK.rawValue) ? -1 : 0
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// Diffs.swift
|
||||
// SwiftGit2
|
||||
//
|
||||
// Created by Jake Van Alstyne on 8/20/17.
|
||||
// Copyright © 2017 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import Clibgit2
|
||||
|
||||
public struct StatusEntry {
|
||||
public var status: Diff.Status
|
||||
public var headToIndex: Diff.Delta?
|
||||
public var indexToWorkDir: Diff.Delta?
|
||||
|
||||
public init(from statusEntry: git_status_entry) {
|
||||
self.status = Diff.Status(rawValue: statusEntry.status.rawValue)
|
||||
|
||||
if let htoi = statusEntry.head_to_index {
|
||||
self.headToIndex = Diff.Delta(htoi.pointee)
|
||||
}
|
||||
|
||||
if let itow = statusEntry.index_to_workdir {
|
||||
self.indexToWorkDir = Diff.Delta(itow.pointee)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct Diff {
|
||||
|
||||
/// The set of deltas.
|
||||
public var deltas = [Delta]()
|
||||
|
||||
public struct Delta {
|
||||
public static let type = GIT_OBJECT_REF_DELTA
|
||||
|
||||
public var status: Status
|
||||
public var flags: Flags
|
||||
public var oldFile: File?
|
||||
public var newFile: File?
|
||||
|
||||
public init(_ delta: git_diff_delta) {
|
||||
self.status = Status(rawValue: UInt32(git_diff_status_char(delta.status)))
|
||||
self.flags = Flags(rawValue: delta.flags)
|
||||
self.oldFile = File(delta.old_file)
|
||||
self.newFile = File(delta.new_file)
|
||||
}
|
||||
}
|
||||
|
||||
public struct File {
|
||||
public var oid: OID
|
||||
public var path: String
|
||||
public var size: UInt64
|
||||
public var flags: Flags
|
||||
|
||||
public init(_ diffFile: git_diff_file) {
|
||||
self.oid = OID(diffFile.id)
|
||||
let path = diffFile.path
|
||||
self.path = path.map(String.init(cString:))!
|
||||
self.size = diffFile.size
|
||||
self.flags = Flags(rawValue: diffFile.flags)
|
||||
}
|
||||
}
|
||||
|
||||
public struct Status: OptionSet {
|
||||
// This appears to be necessary due to bug in Swift
|
||||
// https://bugs.swift.org/browse/SR-3003
|
||||
public init(rawValue: UInt32) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
public let rawValue: UInt32
|
||||
|
||||
public static let current = Status(rawValue: GIT_STATUS_CURRENT.rawValue)
|
||||
public static let indexNew = Status(rawValue: GIT_STATUS_INDEX_NEW.rawValue)
|
||||
public static let indexModified = Status(rawValue: GIT_STATUS_INDEX_MODIFIED.rawValue)
|
||||
public static let indexDeleted = Status(rawValue: GIT_STATUS_INDEX_DELETED.rawValue)
|
||||
public static let indexRenamed = Status(rawValue: GIT_STATUS_INDEX_RENAMED.rawValue)
|
||||
public static let indexTypeChange = Status(rawValue: GIT_STATUS_INDEX_TYPECHANGE.rawValue)
|
||||
public static let workTreeNew = Status(rawValue: GIT_STATUS_WT_NEW.rawValue)
|
||||
public static let workTreeModified = Status(rawValue: GIT_STATUS_WT_MODIFIED.rawValue)
|
||||
public static let workTreeDeleted = Status(rawValue: GIT_STATUS_WT_DELETED.rawValue)
|
||||
public static let workTreeTypeChange = Status(rawValue: GIT_STATUS_WT_TYPECHANGE.rawValue)
|
||||
public static let workTreeRenamed = Status(rawValue: GIT_STATUS_WT_RENAMED.rawValue)
|
||||
public static let workTreeUnreadable = Status(rawValue: GIT_STATUS_WT_UNREADABLE.rawValue)
|
||||
public static let ignored = Status(rawValue: GIT_STATUS_IGNORED.rawValue)
|
||||
public static let conflicted = Status(rawValue: GIT_STATUS_CONFLICTED.rawValue)
|
||||
}
|
||||
|
||||
public struct Flags: OptionSet {
|
||||
// This appears to be necessary due to bug in Swift
|
||||
// https://bugs.swift.org/browse/SR-3003
|
||||
public init(rawValue: UInt32) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
public let rawValue: UInt32
|
||||
|
||||
public static let binary = Flags([])
|
||||
public static let notBinary = Flags(rawValue: 1 << 0)
|
||||
public static let validId = Flags(rawValue: 1 << 1)
|
||||
public static let exists = Flags(rawValue: 1 << 2)
|
||||
}
|
||||
|
||||
/// Create an instance with a libgit2 `git_diff`.
|
||||
public init(_ pointer: OpaquePointer) {
|
||||
for i in 0..<git_diff_num_deltas(pointer) {
|
||||
if let delta = git_diff_get_delta(pointer, i) {
|
||||
deltas.append(Diff.Delta(delta.pointee))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
-25
@@ -1,31 +1,33 @@
|
||||
import Foundation
|
||||
import Clibgit2
|
||||
|
||||
public let libGit2ErrorDomain = "org.libgit2.libgit2"
|
||||
|
||||
/// Returns an NSError with an error domain and message for libgit2 errors.
|
||||
///
|
||||
/// :param: errorCode An error code returned by a libgit2 function.
|
||||
/// :param: libGit2PointOfFailure The name of the libgit2 function that produced the
|
||||
/// error code.
|
||||
/// :returns: An NSError with a libgit2 error domain, code, and message.
|
||||
internal func libGit2Error(errorCode: Int32, libGit2PointOfFailure: String? = nil) -> NSError {
|
||||
let code = Int(errorCode)
|
||||
var userInfo: [String: String] = [:]
|
||||
internal extension NSError {
|
||||
/// Returns an NSError with an error domain and message for libgit2 errors.
|
||||
///
|
||||
/// :param: errorCode An error code returned by a libgit2 function.
|
||||
/// :param: libGit2PointOfFailure The name of the libgit2 function that produced the
|
||||
/// error code.
|
||||
/// :returns: An NSError with a libgit2 error domain, code, and message.
|
||||
convenience init(gitError errorCode: Int32, pointOfFailure: String? = nil) {
|
||||
let code = Int(errorCode)
|
||||
var userInfo: [String: String] = [:]
|
||||
|
||||
if let message = errorMessage(errorCode) {
|
||||
userInfo[NSLocalizedDescriptionKey] = message
|
||||
} else {
|
||||
userInfo[NSLocalizedDescriptionKey] = "Unknown libgit2 error."
|
||||
if let message = errorMessage(errorCode) {
|
||||
userInfo[NSLocalizedDescriptionKey] = message
|
||||
} else {
|
||||
userInfo[NSLocalizedDescriptionKey] = "Unknown libgit2 error."
|
||||
}
|
||||
|
||||
if let pointOfFailure = pointOfFailure {
|
||||
userInfo[NSLocalizedFailureReasonErrorKey] = "\(pointOfFailure) failed."
|
||||
}
|
||||
|
||||
self.init(domain: libGit2ErrorDomain, code: code, userInfo: userInfo)
|
||||
}
|
||||
|
||||
if let pointOfFailure = libGit2PointOfFailure {
|
||||
userInfo[NSLocalizedFailureReasonErrorKey] = "\(pointOfFailure) failed."
|
||||
}
|
||||
|
||||
return NSError(domain: libGit2ErrorDomain, code: code, userInfo: userInfo)
|
||||
}
|
||||
|
||||
|
||||
/// Returns the libgit2 error message for the given error code.
|
||||
///
|
||||
/// The error message represents the last error message generated by
|
||||
@@ -36,12 +38,12 @@ internal func libGit2Error(errorCode: Int32, libGit2PointOfFailure: String? = ni
|
||||
/// or errno has been set by the system, this function returns the
|
||||
/// corresponding string representation of that error. Otherwise, it returns
|
||||
/// nil.
|
||||
private func errorMessage(errorCode: Int32) -> String? {
|
||||
private func errorMessage(_ errorCode: Int32) -> String? {
|
||||
let last = giterr_last()
|
||||
if last != nil {
|
||||
return String.fromCString(last.memory.message)
|
||||
} else if UInt32(errorCode) == GITERR_OS.value {
|
||||
return String.fromCString(strerror(errno))
|
||||
if let lastErrorPointer = last {
|
||||
return String(validatingUTF8: lastErrorPointer.pointee.message)
|
||||
} else if UInt32(errorCode) == GIT_ERROR_OS.rawValue {
|
||||
return String(validatingUTF8: strerror(errno))
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.libgit2.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
|
||||
+8
-11
@@ -6,20 +6,17 @@
|
||||
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
func == (lhs: git_otype, rhs: git_otype) -> Bool {
|
||||
return lhs.value == rhs.value
|
||||
}
|
||||
import Clibgit2
|
||||
|
||||
extension git_strarray {
|
||||
func filter(f: (String) -> Bool) -> [String] {
|
||||
return map { $0 }.filter(f)
|
||||
func filter(_ isIncluded: (String) -> Bool) -> [String] {
|
||||
return map { $0 }.filter(isIncluded)
|
||||
}
|
||||
|
||||
func map<T>(f: (String) -> T) -> [T] {
|
||||
return Swift.map(0..<self.count) {
|
||||
let string = String.fromCString(self.strings[Int($0)])!
|
||||
return f(string)
|
||||
|
||||
func map<T>(_ transform: (String) -> T) -> [T] {
|
||||
return (0..<self.count).map {
|
||||
let string = String(validatingUTF8: self.strings[$0]!)!
|
||||
return transform(string)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
-41
@@ -6,76 +6,65 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import LlamaKit
|
||||
import Clibgit2
|
||||
|
||||
/// An identifier for a Git object.
|
||||
public struct OID {
|
||||
|
||||
|
||||
// MARK: - Initializers
|
||||
|
||||
|
||||
/// Create an instance from a hex formatted string.
|
||||
///
|
||||
/// string - A 40-byte hex formatted string.
|
||||
public init?(string: String) {
|
||||
// libgit2 doesn't enforce a maximum length
|
||||
if (string.lengthOfBytesUsingEncoding(NSASCIIStringEncoding) > 40) {
|
||||
if string.lengthOfBytes(using: String.Encoding.ascii) > 40 {
|
||||
return nil
|
||||
}
|
||||
|
||||
let pointer = UnsafeMutablePointer<git_oid>.alloc(1)
|
||||
|
||||
let pointer = UnsafeMutablePointer<git_oid>.allocate(capacity: 1)
|
||||
let result = git_oid_fromstr(pointer, string)
|
||||
|
||||
if result < GIT_OK.value {
|
||||
pointer.dealloc(1)
|
||||
return nil;
|
||||
|
||||
if result < GIT_OK.rawValue {
|
||||
pointer.deallocate()
|
||||
return nil
|
||||
}
|
||||
|
||||
oid = pointer.memory;
|
||||
pointer.dealloc(1)
|
||||
|
||||
oid = pointer.pointee
|
||||
pointer.deallocate()
|
||||
}
|
||||
|
||||
|
||||
/// Create an instance from a libgit2 `git_oid`.
|
||||
public init(_ oid: git_oid) {
|
||||
self.oid = oid
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
|
||||
public let oid: git_oid
|
||||
}
|
||||
|
||||
extension OID: Printable {
|
||||
extension OID: CustomStringConvertible {
|
||||
public var description: String {
|
||||
let length = Int(GIT_OID_RAWSZ) * 2
|
||||
let string = UnsafeMutablePointer<Int8>.alloc(length)
|
||||
let string = UnsafeMutablePointer<Int8>.allocate(capacity: length)
|
||||
var oid = self.oid
|
||||
git_oid_fmt(string, &oid)
|
||||
|
||||
return String(bytesNoCopy: string, length: length, encoding: NSASCIIStringEncoding, freeWhenDone: true)!
|
||||
|
||||
return String(bytesNoCopy: string, length: length, encoding: .ascii, freeWhenDone: true)!
|
||||
}
|
||||
}
|
||||
|
||||
extension OID: Hashable {
|
||||
public var hashValue: Int {
|
||||
let bytes = [
|
||||
self.oid.id.0,
|
||||
self.oid.id.1,
|
||||
self.oid.id.2,
|
||||
self.oid.id.3,
|
||||
self.oid.id.4,
|
||||
self.oid.id.5,
|
||||
self.oid.id.6,
|
||||
self.oid.id.7
|
||||
]
|
||||
return reduce(bytes, 0, { (hash, byte) in
|
||||
return Int(hash << 8) | Int(byte)
|
||||
})
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
withUnsafeBytes(of: oid.id) {
|
||||
hasher.combine(bytes: $0)
|
||||
}
|
||||
}
|
||||
|
||||
public static func == (lhs: OID, rhs: OID) -> Bool {
|
||||
var left = lhs.oid
|
||||
var right = rhs.oid
|
||||
return git_oid_cmp(&left, &right) == 0
|
||||
}
|
||||
}
|
||||
|
||||
public func == (lhs: OID, rhs: OID) -> Bool {
|
||||
var left = lhs.oid
|
||||
var right = rhs.oid
|
||||
return git_oid_cmp(&left, &right) == 0
|
||||
}
|
||||
|
||||
+114
-127
@@ -7,122 +7,140 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Clibgit2
|
||||
|
||||
/// A git object.
|
||||
public protocol ObjectType {
|
||||
static var type: git_otype { get }
|
||||
|
||||
static var type: git_object_t { get }
|
||||
|
||||
/// The OID of the object.
|
||||
var oid: OID { get }
|
||||
|
||||
|
||||
/// Create an instance with the underlying libgit2 type.
|
||||
init(_ pointer: COpaquePointer)
|
||||
init(_ pointer: OpaquePointer)
|
||||
}
|
||||
|
||||
public func == <O: ObjectType>(lhs: O, rhs: O) -> Bool {
|
||||
return lhs.oid == rhs.oid
|
||||
public extension ObjectType {
|
||||
static func == (lhs: Self, rhs: Self) -> Bool {
|
||||
return lhs.oid == rhs.oid
|
||||
}
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(oid)
|
||||
}
|
||||
}
|
||||
|
||||
public struct Signature {
|
||||
/// The name of the person.
|
||||
public let name: String
|
||||
|
||||
|
||||
/// The email of the person.
|
||||
public let email: String
|
||||
|
||||
|
||||
/// The time when the action happened.
|
||||
public let time: NSDate
|
||||
|
||||
public let time: Date
|
||||
|
||||
/// The time zone that `time` should be interpreted relative to.
|
||||
public let timeZone: NSTimeZone
|
||||
|
||||
public let timeZone: TimeZone
|
||||
|
||||
/// Create an instance with custom name, email, dates, etc.
|
||||
public init(name: String, email: String, time: Date = Date(), timeZone: TimeZone = TimeZone.autoupdatingCurrent) {
|
||||
self.name = name
|
||||
self.email = email
|
||||
self.time = time
|
||||
self.timeZone = timeZone
|
||||
}
|
||||
|
||||
/// Create an instance with a libgit2 `git_signature`.
|
||||
public init(_ signature: git_signature) {
|
||||
name = String.fromCString(signature.name)!
|
||||
email = String.fromCString(signature.email)!
|
||||
time = NSDate(timeIntervalSince1970: NSTimeInterval(signature.when.time))
|
||||
timeZone = NSTimeZone(forSecondsFromGMT: NSInteger(60 * signature.when.offset))
|
||||
name = String(validatingUTF8: signature.name)!
|
||||
email = String(validatingUTF8: signature.email)!
|
||||
time = Date(timeIntervalSince1970: TimeInterval(signature.when.time))
|
||||
timeZone = TimeZone(secondsFromGMT: 60 * Int(signature.when.offset))!
|
||||
}
|
||||
|
||||
/// Return an unsafe pointer to the `git_signature` struct.
|
||||
/// Caller is responsible for freeing it with `git_signature_free`.
|
||||
func makeUnsafeSignature() -> Result<UnsafeMutablePointer<git_signature>, NSError> {
|
||||
var signature: UnsafeMutablePointer<git_signature>? = nil
|
||||
let time = git_time_t(self.time.timeIntervalSince1970) // Unix epoch time
|
||||
let offset = Int32(timeZone.secondsFromGMT(for: self.time) / 60)
|
||||
let signatureResult = git_signature_new(&signature, name, email, time, offset)
|
||||
guard signatureResult == GIT_OK.rawValue, let signatureUnwrap = signature else {
|
||||
let err = NSError(gitError: signatureResult, pointOfFailure: "git_signature_new")
|
||||
return .failure(err)
|
||||
}
|
||||
return .success(signatureUnwrap)
|
||||
}
|
||||
}
|
||||
|
||||
extension Signature: Hashable {
|
||||
public var hashValue: Int {
|
||||
return name.hashValue ^ email.hashValue ^ time.timeIntervalSince1970.hashValue
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(name)
|
||||
hasher.combine(email)
|
||||
hasher.combine(time)
|
||||
}
|
||||
}
|
||||
|
||||
public func == (lhs: Signature, rhs: Signature) -> Bool {
|
||||
return lhs.name == rhs.name
|
||||
&& lhs.email == rhs.email
|
||||
&& lhs.time == rhs.time
|
||||
&& lhs.timeZone.secondsFromGMT == rhs.timeZone.secondsFromGMT
|
||||
}
|
||||
|
||||
/// A git commit.
|
||||
public struct Commit: ObjectType {
|
||||
public static let type = GIT_OBJ_COMMIT
|
||||
|
||||
public struct Commit: ObjectType, Hashable {
|
||||
public static let type = GIT_OBJECT_COMMIT
|
||||
|
||||
/// The OID of the commit.
|
||||
public let oid: OID
|
||||
|
||||
|
||||
/// The OID of the commit's tree.
|
||||
public let tree: PointerTo<Tree>
|
||||
|
||||
|
||||
/// The OIDs of the commit's parents.
|
||||
public let parents: [PointerTo<Commit>]
|
||||
|
||||
|
||||
/// The author of the commit.
|
||||
public let author: Signature
|
||||
|
||||
|
||||
/// The committer of the commit.
|
||||
public let committer: Signature
|
||||
|
||||
|
||||
/// The full message of the commit.
|
||||
public let message: String
|
||||
|
||||
/// Create an instance with a libgit2 `git_commit` object.
|
||||
public init(_ pointer: COpaquePointer) {
|
||||
oid = OID(git_object_id(pointer).memory)
|
||||
message = String.fromCString(git_commit_message(pointer))!
|
||||
author = Signature(git_commit_author(pointer).memory)
|
||||
committer = Signature(git_commit_committer(pointer).memory)
|
||||
tree = PointerTo(OID(git_commit_tree_id(pointer).memory))
|
||||
|
||||
self.parents = map(0..<git_commit_parentcount(pointer)) {
|
||||
return PointerTo(OID(git_commit_parent_id(pointer, $0).memory))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Commit: Hashable {
|
||||
public var hashValue: Int {
|
||||
return self.oid.hashValue
|
||||
/// Create an instance with a libgit2 `git_commit` object.
|
||||
public init(_ pointer: OpaquePointer) {
|
||||
oid = OID(git_object_id(pointer).pointee)
|
||||
message = String(validatingUTF8: git_commit_message(pointer))!
|
||||
author = Signature(git_commit_author(pointer).pointee)
|
||||
committer = Signature(git_commit_committer(pointer).pointee)
|
||||
tree = PointerTo(OID(git_commit_tree_id(pointer).pointee))
|
||||
|
||||
self.parents = (0..<git_commit_parentcount(pointer)).map {
|
||||
return PointerTo(OID(git_commit_parent_id(pointer, $0).pointee))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A git tree.
|
||||
public struct Tree: ObjectType {
|
||||
public static let type = GIT_OBJ_TREE
|
||||
|
||||
public struct Tree: ObjectType, Hashable {
|
||||
public static let type = GIT_OBJECT_TREE
|
||||
|
||||
/// An entry in a `Tree`.
|
||||
public struct Entry {
|
||||
public struct Entry: Hashable {
|
||||
/// The entry's UNIX file attributes.
|
||||
public let attributes: Int32
|
||||
|
||||
|
||||
/// The object pointed to by the entry.
|
||||
public let object: Pointer
|
||||
|
||||
|
||||
/// The file name of the entry.
|
||||
public let name: String
|
||||
|
||||
|
||||
/// Create an instance with a libgit2 `git_tree_entry`.
|
||||
public init(_ pointer: COpaquePointer) {
|
||||
let oid = OID(git_tree_entry_id(pointer).memory)
|
||||
attributes = Int32(git_tree_entry_filemode(pointer).value)
|
||||
public init(_ pointer: OpaquePointer) {
|
||||
let oid = OID(git_tree_entry_id(pointer).pointee)
|
||||
attributes = Int32(git_tree_entry_filemode(pointer).rawValue)
|
||||
object = Pointer(oid: oid, type: git_tree_entry_type(pointer))!
|
||||
name = String.fromCString(git_tree_entry_name(pointer))!
|
||||
name = String(validatingUTF8: git_tree_entry_name(pointer))!
|
||||
}
|
||||
|
||||
|
||||
/// Create an instance with the individual values.
|
||||
public init(attributes: Int32, object: Pointer, name: String) {
|
||||
self.attributes = attributes
|
||||
@@ -133,105 +151,74 @@ public struct Tree: ObjectType {
|
||||
|
||||
/// The OID of the tree.
|
||||
public let oid: OID
|
||||
|
||||
|
||||
/// The entries in the tree.
|
||||
public let entries: [String: Entry]
|
||||
|
||||
|
||||
/// Create an instance with a libgit2 `git_tree`.
|
||||
public init(_ pointer: COpaquePointer) {
|
||||
oid = OID(git_object_id(pointer).memory)
|
||||
|
||||
public init(_ pointer: OpaquePointer) {
|
||||
oid = OID(git_object_id(pointer).pointee)
|
||||
|
||||
var entries: [String: Entry] = [:]
|
||||
for idx in 0..<git_tree_entrycount(pointer) {
|
||||
let entry = Entry(git_tree_entry_byindex(pointer, idx))
|
||||
let entry = Entry(git_tree_entry_byindex(pointer, idx)!)
|
||||
entries[entry.name] = entry
|
||||
}
|
||||
self.entries = entries
|
||||
}
|
||||
}
|
||||
|
||||
extension Tree.Entry: Hashable {
|
||||
public var hashValue: Int {
|
||||
return Int(attributes) ^ object.hashValue ^ name.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
extension Tree.Entry: Printable {
|
||||
extension Tree.Entry: CustomStringConvertible {
|
||||
public var description: String {
|
||||
return "\(attributes) \(object) \(name)"
|
||||
}
|
||||
}
|
||||
|
||||
public func == (lhs: Tree.Entry, rhs: Tree.Entry) -> Bool {
|
||||
return lhs.attributes == rhs.attributes
|
||||
&& lhs.object == rhs.object
|
||||
&& lhs.name == rhs.name
|
||||
}
|
||||
|
||||
extension Tree: Hashable {
|
||||
public var hashValue: Int {
|
||||
return oid.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
/// A git blob.
|
||||
public struct Blob: ObjectType {
|
||||
public static let type = GIT_OBJ_BLOB
|
||||
|
||||
public struct Blob: ObjectType, Hashable {
|
||||
public static let type = GIT_OBJECT_BLOB
|
||||
|
||||
/// The OID of the blob.
|
||||
public let oid: OID
|
||||
|
||||
/// The contents of the blob.
|
||||
public let data: NSData
|
||||
|
||||
/// Create an instance with a libgit2 `git_blob`.
|
||||
public init(_ pointer: COpaquePointer) {
|
||||
oid = OID(git_object_id(pointer).memory)
|
||||
|
||||
// Swift doesn't get the types right without `Int(Int64(...))` :(
|
||||
let length = Int(Int64(git_blob_rawsize(pointer).value))
|
||||
data = NSData(bytes: git_blob_rawcontent(pointer), length: length)
|
||||
}
|
||||
}
|
||||
|
||||
extension Blob: Hashable {
|
||||
public var hashValue: Int {
|
||||
return oid.hashValue
|
||||
/// The contents of the blob.
|
||||
public let data: Data
|
||||
|
||||
/// Create an instance with a libgit2 `git_blob`.
|
||||
public init(_ pointer: OpaquePointer) {
|
||||
oid = OID(git_object_id(pointer).pointee)
|
||||
|
||||
let length = Int(git_blob_rawsize(pointer))
|
||||
data = Data(bytes: git_blob_rawcontent(pointer), count: length)
|
||||
}
|
||||
}
|
||||
|
||||
/// An annotated git tag.
|
||||
public struct Tag: ObjectType {
|
||||
public static let type = GIT_OBJ_TAG
|
||||
|
||||
public struct Tag: ObjectType, Hashable {
|
||||
public static let type = GIT_OBJECT_TAG
|
||||
|
||||
/// The OID of the tag.
|
||||
public let oid: OID
|
||||
|
||||
|
||||
/// The tagged object.
|
||||
public let target: Pointer
|
||||
|
||||
|
||||
/// The name of the tag.
|
||||
public let name: String
|
||||
|
||||
|
||||
/// The tagger (author) of the tag.
|
||||
public let tagger: Signature
|
||||
|
||||
|
||||
/// The message of the tag.
|
||||
public let message: String
|
||||
|
||||
/// Create an instance with a libgit2 `git_tag`.
|
||||
public init(_ pointer: COpaquePointer) {
|
||||
oid = OID(git_object_id(pointer).memory)
|
||||
let targetOID = OID(git_tag_target_id(pointer).memory)
|
||||
target = Pointer(oid: targetOID, type: git_tag_target_type(pointer))!
|
||||
name = String.fromCString(git_tag_name(pointer))!
|
||||
tagger = Signature(git_tag_tagger(pointer).memory)
|
||||
message = String.fromCString(git_tag_message(pointer))!
|
||||
}
|
||||
}
|
||||
|
||||
extension Tag: Hashable {
|
||||
public var hashValue: Int {
|
||||
return oid.hashValue
|
||||
/// Create an instance with a libgit2 `git_tag`.
|
||||
public init(_ pointer: OpaquePointer) {
|
||||
oid = OID(git_object_id(pointer).pointee)
|
||||
let targetOID = OID(git_tag_target_id(pointer).pointee)
|
||||
target = Pointer(oid: targetOID, type: git_tag_target_type(pointer))!
|
||||
name = String(validatingUTF8: git_tag_name(pointer))!
|
||||
tagger = Signature(git_tag_tagger(pointer).pointee)
|
||||
message = String(validatingUTF8: git_tag_message(pointer))!
|
||||
}
|
||||
}
|
||||
|
||||
+52
-59
@@ -6,89 +6,88 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
import Foundation
|
||||
import Clibgit2
|
||||
|
||||
/// A pointer to a git object.
|
||||
public protocol PointerType: Equatable, Hashable {
|
||||
public protocol PointerType: Hashable {
|
||||
/// The OID of the referenced object.
|
||||
var oid: OID { get }
|
||||
|
||||
/// The libgit2 `git_otype` of the referenced object.
|
||||
var type: git_otype { get }
|
||||
|
||||
/// The libgit2 `git_object_t` of the referenced object.
|
||||
var type: git_object_t { get }
|
||||
}
|
||||
|
||||
public func == <P: PointerType>(lhs: P, rhs: P) -> Bool {
|
||||
return lhs.oid == rhs.oid && lhs.type.value == rhs.type.value
|
||||
public extension PointerType {
|
||||
static func == (lhs: Self, rhs: Self) -> Bool {
|
||||
return lhs.oid == rhs.oid
|
||||
&& lhs.type == rhs.type
|
||||
}
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(oid)
|
||||
}
|
||||
}
|
||||
|
||||
/// A pointer to a git object.
|
||||
public enum Pointer: PointerType {
|
||||
case Commit(OID)
|
||||
case Tree(OID)
|
||||
case Blob(OID)
|
||||
case Tag(OID)
|
||||
|
||||
case commit(OID)
|
||||
case tree(OID)
|
||||
case blob(OID)
|
||||
case tag(OID)
|
||||
|
||||
public var oid: OID {
|
||||
switch self {
|
||||
case let Commit(oid):
|
||||
case let .commit(oid):
|
||||
return oid
|
||||
case let Tree(oid):
|
||||
case let .tree(oid):
|
||||
return oid
|
||||
case let Blob(oid):
|
||||
case let .blob(oid):
|
||||
return oid
|
||||
case let Tag(oid):
|
||||
case let .tag(oid):
|
||||
return oid
|
||||
}
|
||||
}
|
||||
|
||||
public var type: git_otype {
|
||||
|
||||
public var type: git_object_t {
|
||||
switch self {
|
||||
case let Commit(oid):
|
||||
return GIT_OBJ_COMMIT
|
||||
case let Tree(oid):
|
||||
return GIT_OBJ_TREE
|
||||
case let Blob(oid):
|
||||
return GIT_OBJ_BLOB
|
||||
case let Tag(oid):
|
||||
return GIT_OBJ_TAG
|
||||
case .commit:
|
||||
return GIT_OBJECT_COMMIT
|
||||
case .tree:
|
||||
return GIT_OBJECT_TREE
|
||||
case .blob:
|
||||
return GIT_OBJECT_BLOB
|
||||
case .tag:
|
||||
return GIT_OBJECT_TAG
|
||||
}
|
||||
}
|
||||
|
||||
/// Create an instance with an OID and a libgit2 `git_otype`.
|
||||
init?(oid: OID, type: git_otype) {
|
||||
switch type.value {
|
||||
case GIT_OBJ_COMMIT.value:
|
||||
self = Commit(oid)
|
||||
case GIT_OBJ_TREE.value:
|
||||
self = Tree(oid)
|
||||
case GIT_OBJ_BLOB.value:
|
||||
self = Blob(oid)
|
||||
case GIT_OBJ_TAG.value:
|
||||
self = Tag(oid)
|
||||
|
||||
/// Create an instance with an OID and a libgit2 `git_object_t`.
|
||||
init?(oid: OID, type: git_object_t) {
|
||||
switch type {
|
||||
case GIT_OBJECT_COMMIT:
|
||||
self = .commit(oid)
|
||||
case GIT_OBJECT_TREE:
|
||||
self = .tree(oid)
|
||||
case GIT_OBJECT_BLOB:
|
||||
self = .blob(oid)
|
||||
case GIT_OBJECT_TAG:
|
||||
self = .tag(oid)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Pointer: Hashable {
|
||||
public var hashValue: Int {
|
||||
return oid.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
extension Pointer: Printable {
|
||||
extension Pointer: CustomStringConvertible {
|
||||
public var description: String {
|
||||
switch self {
|
||||
case Commit:
|
||||
case .commit:
|
||||
return "commit(\(oid))"
|
||||
case Tree:
|
||||
case .tree:
|
||||
return "tree(\(oid))"
|
||||
case Blob:
|
||||
case .blob:
|
||||
return "blob(\(oid))"
|
||||
case Tag:
|
||||
case .tag:
|
||||
return "tag(\(oid))"
|
||||
}
|
||||
}
|
||||
@@ -96,8 +95,8 @@ extension Pointer: Printable {
|
||||
|
||||
public struct PointerTo<T: ObjectType>: PointerType {
|
||||
public let oid: OID
|
||||
|
||||
public var type: git_otype {
|
||||
|
||||
public var type: git_object_t {
|
||||
return T.type
|
||||
}
|
||||
|
||||
@@ -105,9 +104,3 @@ public struct PointerTo<T: ObjectType>: PointerType {
|
||||
self.oid = oid
|
||||
}
|
||||
}
|
||||
|
||||
extension PointerTo: Hashable {
|
||||
public var hashValue: Int {
|
||||
return oid.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
+72
-84
@@ -6,25 +6,34 @@
|
||||
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import Clibgit2
|
||||
|
||||
/// A reference to a git object.
|
||||
public protocol ReferenceType {
|
||||
/// The full name of the reference (e.g., `refs/heads/master`).
|
||||
var longName: String { get }
|
||||
|
||||
|
||||
/// The short human-readable name of the reference if one exists (e.g., `master`).
|
||||
var shortName: String? { get }
|
||||
|
||||
|
||||
/// The OID of the referenced object.
|
||||
var oid: OID { get }
|
||||
}
|
||||
|
||||
public func ==<T: ReferenceType>(lhs: T, rhs: T) -> Bool {
|
||||
return lhs.longName == rhs.longName
|
||||
&& lhs.oid == rhs.oid
|
||||
public extension ReferenceType {
|
||||
static func == (lhs: Self, rhs: Self) -> Bool {
|
||||
return lhs.longName == rhs.longName
|
||||
&& lhs.oid == rhs.oid
|
||||
}
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(longName)
|
||||
hasher.combine(oid)
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a Reference, Branch, or TagReference from a libgit2 `git_reference`.
|
||||
internal func referenceWithLibGit2Reference(pointer: COpaquePointer) -> ReferenceType {
|
||||
internal func referenceWithLibGit2Reference(_ pointer: OpaquePointer) -> ReferenceType {
|
||||
if git_reference_is_branch(pointer) != 0 || git_reference_is_remote(pointer) != 0 {
|
||||
return Branch(pointer)!
|
||||
} else if git_reference_is_tag(pointer) != 0 {
|
||||
@@ -35,167 +44,146 @@ internal func referenceWithLibGit2Reference(pointer: COpaquePointer) -> Referenc
|
||||
}
|
||||
|
||||
/// A generic reference to a git object.
|
||||
public struct Reference: ReferenceType {
|
||||
public struct Reference: ReferenceType, Hashable {
|
||||
/// The full name of the reference (e.g., `refs/heads/master`).
|
||||
public let longName: String
|
||||
|
||||
|
||||
/// The short human-readable name of the reference if one exists (e.g., `master`).
|
||||
public let shortName: String?
|
||||
|
||||
|
||||
/// The OID of the referenced object.
|
||||
public let oid: OID
|
||||
|
||||
/// Create an instance with a libgit2 `git_reference` object.
|
||||
public init(_ pointer: COpaquePointer) {
|
||||
let shorthand = String.fromCString(git_reference_shorthand(pointer))!
|
||||
longName = String.fromCString(git_reference_name(pointer))!
|
||||
shortName = (shorthand == longName ? nil : shorthand)
|
||||
oid = OID(git_reference_target(pointer).memory)
|
||||
}
|
||||
}
|
||||
|
||||
extension Reference: Hashable {
|
||||
public var hashValue: Int {
|
||||
return longName.hashValue ^ oid.hashValue
|
||||
/// Create an instance with a libgit2 `git_reference` object.
|
||||
public init(_ pointer: OpaquePointer) {
|
||||
let shorthand = String(validatingUTF8: git_reference_shorthand(pointer))!
|
||||
longName = String(validatingUTF8: git_reference_name(pointer))!
|
||||
shortName = (shorthand == longName ? nil : shorthand)
|
||||
oid = OID(git_reference_target(pointer).pointee)
|
||||
}
|
||||
}
|
||||
|
||||
/// A git branch.
|
||||
public struct Branch: ReferenceType {
|
||||
public struct Branch: ReferenceType, Hashable {
|
||||
/// The full name of the reference (e.g., `refs/heads/master`).
|
||||
public let longName: String
|
||||
|
||||
|
||||
/// The short human-readable name of the branch (e.g., `master`).
|
||||
public let name: String
|
||||
|
||||
|
||||
/// A pointer to the referenced commit.
|
||||
public let commit: PointerTo<Commit>
|
||||
|
||||
|
||||
// MARK: Derived Properties
|
||||
|
||||
|
||||
/// The short human-readable name of the branch (e.g., `master`).
|
||||
///
|
||||
/// This is the same as `name`, but is declared with an Optional type to adhere to
|
||||
/// `ReferenceType`.
|
||||
public var shortName: String? { return name }
|
||||
|
||||
|
||||
/// The OID of the referenced object.
|
||||
///
|
||||
/// This is the same as `commit.oid`, but is declared here to adhere to `ReferenceType`.
|
||||
public var oid: OID { return commit.oid }
|
||||
|
||||
|
||||
/// Whether the branch is a local branch.
|
||||
public var isLocal: Bool { return longName.hasPrefix("refs/heads/") }
|
||||
|
||||
|
||||
/// Whether the branch is a remote branch.
|
||||
public var isRemote: Bool { return longName.hasPrefix("refs/remotes/") }
|
||||
|
||||
|
||||
/// Create an instance with a libgit2 `git_reference` object.
|
||||
///
|
||||
/// Returns `nil` if the pointer isn't a branch.
|
||||
public init?(_ pointer: COpaquePointer) {
|
||||
let namePointer = UnsafeMutablePointer<UnsafePointer<Int8>>.alloc(1)
|
||||
let success = git_branch_name(namePointer, pointer)
|
||||
if success != GIT_OK.value {
|
||||
namePointer.dealloc(1)
|
||||
public init?(_ pointer: OpaquePointer) {
|
||||
var namePointer: UnsafePointer<Int8>? = nil
|
||||
let success = git_branch_name(&namePointer, pointer)
|
||||
guard success == GIT_OK.rawValue else {
|
||||
return nil
|
||||
}
|
||||
name = String.fromCString(namePointer.memory)!
|
||||
namePointer.dealloc(1)
|
||||
|
||||
longName = String.fromCString(git_reference_name(pointer))!
|
||||
|
||||
name = String(validatingUTF8: namePointer!)!
|
||||
|
||||
longName = String(validatingUTF8: git_reference_name(pointer))!
|
||||
|
||||
var oid: OID
|
||||
if git_reference_type(pointer).value == GIT_REF_SYMBOLIC.value {
|
||||
var resolved: COpaquePointer = nil
|
||||
if git_reference_type(pointer).rawValue == GIT_REFERENCE_SYMBOLIC.rawValue {
|
||||
var resolved: OpaquePointer? = nil
|
||||
let success = git_reference_resolve(&resolved, pointer)
|
||||
if success != GIT_OK.value {
|
||||
guard success == GIT_OK.rawValue else {
|
||||
return nil
|
||||
}
|
||||
oid = OID(git_reference_target(resolved).memory)
|
||||
oid = OID(git_reference_target(resolved).pointee)
|
||||
git_reference_free(resolved)
|
||||
} else {
|
||||
oid = OID(git_reference_target(pointer).memory)
|
||||
oid = OID(git_reference_target(pointer).pointee)
|
||||
}
|
||||
commit = PointerTo<Commit>(oid)
|
||||
}
|
||||
}
|
||||
|
||||
extension Branch: Hashable {
|
||||
public var hashValue: Int {
|
||||
return longName.hashValue ^ oid.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
/// A git tag reference, which can be either a lightweight tag or a Tag object.
|
||||
public enum TagReference: ReferenceType {
|
||||
public enum TagReference: ReferenceType, Hashable {
|
||||
/// A lightweight tag, which is just a name and an OID.
|
||||
case Lightweight(String, OID)
|
||||
|
||||
case lightweight(String, OID)
|
||||
|
||||
/// An annotated tag, which points to a Tag object.
|
||||
case Annotated(String, Tag)
|
||||
|
||||
case annotated(String, Tag)
|
||||
|
||||
/// The full name of the reference (e.g., `refs/tags/my-tag`).
|
||||
public var longName: String {
|
||||
switch self {
|
||||
case let .Lightweight(name, _):
|
||||
case let .lightweight(name, _):
|
||||
return name
|
||||
case let .Annotated(name, _):
|
||||
case let .annotated(name, _):
|
||||
return name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// The short human-readable name of the branch (e.g., `master`).
|
||||
public var name: String {
|
||||
return longName.substringFromIndex("refs/tags/".endIndex)
|
||||
return String(longName["refs/tags/".endIndex...])
|
||||
}
|
||||
|
||||
|
||||
/// The OID of the target object.
|
||||
///
|
||||
/// If this is an annotated tag, the OID will be the tag's target.
|
||||
public var oid: OID {
|
||||
switch self {
|
||||
case let .Lightweight(_, oid):
|
||||
case let .lightweight(_, oid):
|
||||
return oid
|
||||
case let .Annotated(_, tag):
|
||||
case let .annotated(_, tag):
|
||||
return tag.target.oid
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Derived Properties
|
||||
|
||||
|
||||
/// The short human-readable name of the branch (e.g., `master`).
|
||||
///
|
||||
/// This is the same as `name`, but is declared with an Optional type to adhere to
|
||||
/// `ReferenceType`.
|
||||
public var shortName: String? { return name }
|
||||
|
||||
|
||||
/// Create an instance with a libgit2 `git_reference` object.
|
||||
///
|
||||
/// Returns `nil` if the pointer isn't a branch.
|
||||
public init?(_ pointer: COpaquePointer) {
|
||||
public init?(_ pointer: OpaquePointer) {
|
||||
if git_reference_is_tag(pointer) == 0 {
|
||||
return nil;
|
||||
return nil
|
||||
}
|
||||
|
||||
let name = String.fromCString(git_reference_name(pointer))!
|
||||
|
||||
let name = String(validatingUTF8: git_reference_name(pointer))!
|
||||
let repo = git_reference_owner(pointer)
|
||||
var oid = git_reference_target(pointer).memory
|
||||
|
||||
var pointer: COpaquePointer = nil
|
||||
let result = git_object_lookup(&pointer, repo, &oid, GIT_OBJ_TAG)
|
||||
if result == GIT_OK.value {
|
||||
self = .Annotated(name, Tag(pointer))
|
||||
var oid = git_reference_target(pointer).pointee
|
||||
|
||||
var pointer: OpaquePointer? = nil
|
||||
let result = git_object_lookup(&pointer, repo, &oid, GIT_OBJECT_TAG)
|
||||
if result == GIT_OK.rawValue {
|
||||
self = .annotated(name, Tag(pointer!))
|
||||
} else {
|
||||
self = .Lightweight(name, OID(oid))
|
||||
self = .lightweight(name, OID(oid))
|
||||
}
|
||||
git_object_free(pointer)
|
||||
}
|
||||
}
|
||||
|
||||
extension TagReference: Hashable {
|
||||
public var hashValue: Int {
|
||||
return longName.hashValue ^ oid.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-16
@@ -6,29 +6,21 @@
|
||||
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import Clibgit2
|
||||
|
||||
/// A remote in a git repository.
|
||||
public struct Remote {
|
||||
public struct Remote: Hashable {
|
||||
/// The name of the remote.
|
||||
public let name: String
|
||||
|
||||
|
||||
/// The URL of the remote.
|
||||
///
|
||||
/// This may be an SSH URL, which isn't representable using `NSURL`.
|
||||
public let URL: String
|
||||
|
||||
|
||||
/// Create an instance with a libgit2 `git_remote`.
|
||||
public init(_ pointer: COpaquePointer) {
|
||||
name = String.fromCString(git_remote_name(pointer))!
|
||||
URL = String.fromCString(git_remote_url(pointer))!
|
||||
public init(_ pointer: OpaquePointer) {
|
||||
name = String(validatingUTF8: git_remote_name(pointer))!
|
||||
URL = String(validatingUTF8: git_remote_url(pointer))!
|
||||
}
|
||||
}
|
||||
|
||||
extension Remote: Hashable {
|
||||
public var hashValue: Int {
|
||||
return name.hashValue ^ URL.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
public func == (lhs: Remote, rhs: Remote) -> Bool {
|
||||
return lhs.name == rhs.name && lhs.URL == rhs.URL
|
||||
}
|
||||
|
||||
+792
-150
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// Copyright © 2020 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import Clibgit2
|
||||
import Foundation
|
||||
|
||||
public struct StatusOptions: OptionSet {
|
||||
public let rawValue: UInt32
|
||||
|
||||
public init(rawValue: UInt32) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
public static let includeUntracked = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_INCLUDE_UNTRACKED.rawValue
|
||||
)
|
||||
public static let includeIgnored = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_INCLUDE_IGNORED.rawValue
|
||||
)
|
||||
public static let includeUnmodified = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_INCLUDE_UNMODIFIED.rawValue
|
||||
)
|
||||
public static let excludeSubmodules = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_EXCLUDE_SUBMODULES.rawValue
|
||||
)
|
||||
public static let recurseUntrackedDirs = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS.rawValue
|
||||
)
|
||||
public static let disablePathSpecMatch = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH.rawValue
|
||||
)
|
||||
public static let recurseIgnoredDirs = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_RECURSE_IGNORED_DIRS.rawValue
|
||||
)
|
||||
public static let renamesHeadToIndex = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX.rawValue
|
||||
)
|
||||
public static let renamesIndexToWorkDir = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR.rawValue
|
||||
)
|
||||
public static let sortCasesSensitively = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_SORT_CASE_SENSITIVELY.rawValue
|
||||
)
|
||||
public static let sortCasesInSensitively = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY.rawValue
|
||||
)
|
||||
public static let renamesFromRewrites = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_RENAMES_FROM_REWRITES.rawValue
|
||||
)
|
||||
public static let noRefresh = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_NO_REFRESH.rawValue
|
||||
)
|
||||
public static let updateIndex = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_UPDATE_INDEX.rawValue
|
||||
)
|
||||
public static let includeUnreadable = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_INCLUDE_UNREADABLE.rawValue
|
||||
)
|
||||
public static let includeUnreadableAsUntracked = StatusOptions(
|
||||
rawValue: GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED.rawValue
|
||||
)
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@import Foundation;
|
||||
|
||||
//! Project version number for SwiftGit2.
|
||||
FOUNDATION_EXPORT double SwiftGit2VersionNumber;
|
||||
@@ -15,5 +15,3 @@ FOUNDATION_EXPORT double SwiftGit2VersionNumber;
|
||||
FOUNDATION_EXPORT const unsigned char SwiftGit2VersionString[];
|
||||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <SwiftGit2/PublicHeader.h>
|
||||
|
||||
#import "git2.h"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
#import "SwiftGit2.h"
|
||||
|
||||
#import "git2.h"
|
||||
|
||||
__attribute__((constructor))
|
||||
static void SwiftGit2Init(void) {
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
|
||||
framework module SwiftGit2 {
|
||||
umbrella header "SwiftGit2.h"
|
||||
|
||||
header "git2/annotated_commit.h"
|
||||
header "git2/attr.h"
|
||||
header "git2/blame.h"
|
||||
header "git2/blob.h"
|
||||
header "git2/branch.h"
|
||||
header "git2/buffer.h"
|
||||
header "git2/checkout.h"
|
||||
header "git2/cherrypick.h"
|
||||
header "git2/clone.h"
|
||||
header "git2/commit.h"
|
||||
header "git2/common.h"
|
||||
header "git2/config.h"
|
||||
header "git2/cred_helpers.h"
|
||||
header "git2/describe.h"
|
||||
header "git2/diff.h"
|
||||
header "git2/errors.h"
|
||||
header "git2/filter.h"
|
||||
header "git2/global.h"
|
||||
header "git2/graph.h"
|
||||
header "git2/ignore.h"
|
||||
header "git2/index.h"
|
||||
header "git2/indexer.h"
|
||||
header "git2/merge.h"
|
||||
header "git2/message.h"
|
||||
header "git2/net.h"
|
||||
header "git2/notes.h"
|
||||
header "git2/object.h"
|
||||
header "git2/odb_backend.h"
|
||||
header "git2/odb.h"
|
||||
header "git2/oid.h"
|
||||
header "git2/oidarray.h"
|
||||
header "git2/pack.h"
|
||||
header "git2/patch.h"
|
||||
header "git2/pathspec.h"
|
||||
header "git2/push.h"
|
||||
header "git2/rebase.h"
|
||||
header "git2/refdb.h"
|
||||
header "git2/reflog.h"
|
||||
header "git2/refs.h"
|
||||
header "git2/refspec.h"
|
||||
header "git2/remote.h"
|
||||
header "git2/repository.h"
|
||||
header "git2/reset.h"
|
||||
header "git2/revert.h"
|
||||
header "git2/revparse.h"
|
||||
header "git2/revwalk.h"
|
||||
header "git2/signature.h"
|
||||
header "git2/stash.h"
|
||||
header "git2/status.h"
|
||||
header "git2/strarray.h"
|
||||
header "git2/submodule.h"
|
||||
header "git2/tag.h"
|
||||
header "git2/trace.h"
|
||||
header "git2/transaction.h"
|
||||
header "git2/transport.h"
|
||||
header "git2/tree.h"
|
||||
header "git2/types.h"
|
||||
header "git2/version.h"
|
||||
|
||||
export *
|
||||
module * { export * }
|
||||
}
|
||||
@@ -6,73 +6,69 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftGit2
|
||||
import ZipArchive
|
||||
|
||||
final class Fixtures {
|
||||
|
||||
|
||||
// MARK: Lifecycle
|
||||
|
||||
|
||||
class var sharedInstance: Fixtures {
|
||||
struct Singleton {
|
||||
enum Singleton {
|
||||
static let instance = Fixtures()
|
||||
}
|
||||
return Singleton.instance
|
||||
}
|
||||
|
||||
|
||||
init() {
|
||||
let path = NSTemporaryDirectory()
|
||||
.stringByAppendingPathComponent("org.libgit2.SwiftGit2")
|
||||
.stringByAppendingPathComponent(NSProcessInfo.processInfo().globallyUniqueString)
|
||||
directoryURL = NSURL.fileURLWithPath(path, isDirectory: true)!
|
||||
directoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
||||
.appendingPathComponent("org.libgit2.SwiftGit2")
|
||||
.appendingPathComponent(ProcessInfo.processInfo.globallyUniqueString)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Setup and Teardown
|
||||
|
||||
let directoryURL: NSURL
|
||||
|
||||
|
||||
let directoryURL: URL
|
||||
|
||||
func setUp() {
|
||||
NSFileManager.defaultManager().createDirectoryAtURL(directoryURL, withIntermediateDirectories: true, attributes: nil, error: nil)
|
||||
|
||||
let bundle = NSBundle(identifier: "org.libgit2.SwiftGit2-OSXTests")!
|
||||
let zipURLs = bundle.URLsForResourcesWithExtension("zip", subdirectory: nil)! as! [NSURL]
|
||||
|
||||
try! FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil)
|
||||
|
||||
#if os(OSX)
|
||||
let platform = "OSX"
|
||||
#else
|
||||
let platform = "iOS"
|
||||
#endif
|
||||
let bundleIdentifier = String(format: "org.libgit2.SwiftGit2-%@Tests", arguments: [platform])
|
||||
let bundle = Bundle(identifier: bundleIdentifier)!
|
||||
let zipURLs = bundle.urls(forResourcesWithExtension: "zip", subdirectory: nil)!
|
||||
|
||||
for URL in zipURLs {
|
||||
unzipFileAtURL(URL, intoDirectoryAtURL: directoryURL)
|
||||
SSZipArchive.unzipFile(atPath: URL.path, toDestination: directoryURL.path)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func tearDown() {
|
||||
NSFileManager.defaultManager().removeItemAtURL(directoryURL, error: nil)
|
||||
try! FileManager.default.removeItem(at: directoryURL)
|
||||
}
|
||||
|
||||
func unzipFileAtURL(fileURL: NSURL, intoDirectoryAtURL directoryURL: NSURL) {
|
||||
let task = NSTask()
|
||||
task.launchPath = "/usr/bin/unzip"
|
||||
task.arguments = [ "-qq", "-d", directoryURL.path!, fileURL.path! ]
|
||||
|
||||
task.launch()
|
||||
task.waitUntilExit()
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
func repositoryWithName(name: String) -> Repository {
|
||||
let url = directoryURL.URLByAppendingPathComponent(name, isDirectory: true)
|
||||
return Repository.atURL(url).value!
|
||||
|
||||
func repository(named name: String) -> Repository {
|
||||
let url = directoryURL.appendingPathComponent(name, isDirectory: true)
|
||||
return Repository.at(url).value!
|
||||
}
|
||||
|
||||
|
||||
// MARK: - The Fixtures
|
||||
|
||||
|
||||
class var detachedHeadRepository: Repository {
|
||||
return Fixtures.sharedInstance.repositoryWithName("detached-head")
|
||||
return Fixtures.sharedInstance.repository(named: "detached-head")
|
||||
}
|
||||
|
||||
|
||||
class var simpleRepository: Repository {
|
||||
return Fixtures.sharedInstance.repositoryWithName("simple-repository")
|
||||
return Fixtures.sharedInstance.repository(named: "simple-repository")
|
||||
}
|
||||
|
||||
|
||||
class var mantleRepository: Repository {
|
||||
return Fixtures.sharedInstance.repositoryWithName("Mantle")
|
||||
return Fixtures.sharedInstance.repository(named: "Mantle")
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -13,7 +13,7 @@ class FixturesSpec: QuickSpec {
|
||||
beforeSuite {
|
||||
Fixtures.sharedInstance.setUp()
|
||||
}
|
||||
|
||||
|
||||
afterSuite {
|
||||
Fixtures.sharedInstance.tearDown()
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.libgit2.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import LlamaKit
|
||||
import SwiftGit2
|
||||
import Nimble
|
||||
import Quick
|
||||
@@ -25,19 +24,19 @@ class OIDSpec: QuickSpec {
|
||||
it("should not be nil if string is just right") {
|
||||
expect(OID(string: "1234567890123456789012345678ABCDEFabcdef")).notTo(beNil())
|
||||
}
|
||||
|
||||
|
||||
it("should be nil with non-hex characters") {
|
||||
expect(OID(string: "123456789012345678901234567890123456789j")).to(beNil())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("OID(oid)") {
|
||||
it("should equal an OID with the same git_oid") {
|
||||
let oid = OID(string: "1234567890123456789012345678901234567890")!
|
||||
expect(OID(oid.oid)).to(equal(oid))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("OID.description") {
|
||||
it("should return the SHA") {
|
||||
let SHA = "1234567890123456789012345678901234567890"
|
||||
@@ -45,7 +44,7 @@ class OIDSpec: QuickSpec {
|
||||
expect(oid.description).to(equal(SHA))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("==(OID, OID)") {
|
||||
it("should be equal when identical") {
|
||||
let SHA = "1234567890123456789012345678901234567890"
|
||||
@@ -53,14 +52,14 @@ class OIDSpec: QuickSpec {
|
||||
let oid2 = OID(string: SHA)!
|
||||
expect(oid1).to(equal(oid2))
|
||||
}
|
||||
|
||||
|
||||
it("should be not equal when different") {
|
||||
let oid1 = OID(string: "1234567890123456789012345678901234567890")!
|
||||
let oid2 = OID(string: "0000000000000000000000000000000000000000")!
|
||||
expect(oid1).notTo(equal(oid2))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("OID.hashValue") {
|
||||
it("should be equal when OIDs are equal") {
|
||||
let SHA = "1234567890123456789012345678901234567890"
|
||||
|
||||
+119
-115
@@ -6,79 +6,81 @@
|
||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import LlamaKit
|
||||
import SwiftGit2
|
||||
import Nimble
|
||||
import Quick
|
||||
import Clibgit2
|
||||
|
||||
func from_git_object<T>(repository: Repository, oid: OID, f: COpaquePointer -> T) -> T {
|
||||
let repository = repository.pointer
|
||||
var oid = oid.oid
|
||||
|
||||
var pointer: COpaquePointer = nil
|
||||
git_object_lookup(&pointer, repository, &oid, GIT_OBJ_ANY)
|
||||
let result = f(pointer)
|
||||
git_object_free(pointer)
|
||||
|
||||
return result
|
||||
private extension Repository {
|
||||
func withGitObject<T>(_ oid: OID, transform: (OpaquePointer) -> T) -> T {
|
||||
let repository = self.pointer
|
||||
var oid = oid.oid
|
||||
|
||||
var pointer: OpaquePointer? = nil
|
||||
git_object_lookup(&pointer, repository, &oid, GIT_OBJECT_ANY)
|
||||
let result = transform(pointer!)
|
||||
git_object_free(pointer)
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
class SignatureSpec: QuickSpec {
|
||||
class SignatureSpec: FixturesSpec {
|
||||
override func spec() {
|
||||
describe("Signature(signature)") {
|
||||
it("should initialize its properties") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
|
||||
|
||||
let raw_signature = from_git_object(repo, oid) { git_commit_author($0).memory }
|
||||
|
||||
let raw_signature = repo.withGitObject(oid) { git_commit_author($0).pointee }
|
||||
let signature = Signature(raw_signature)
|
||||
|
||||
|
||||
expect(signature.name).to(equal("Matt Diephouse"))
|
||||
expect(signature.email).to(equal("matt@diephouse.com"))
|
||||
expect(signature.time).to(equal(NSDate(timeIntervalSince1970: 1416186947)))
|
||||
expect(signature.timeZone.abbreviation).to(equal("GMT-5"))
|
||||
expect(signature.time).to(equal(Date(timeIntervalSince1970: 1416186947)))
|
||||
expect(signature.timeZone.abbreviation()).to(equal("GMT-5"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("==(Signature, Signature)") {
|
||||
it("should be true with equal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
|
||||
|
||||
let author1 = from_git_object(repo, oid) { commit in
|
||||
Signature(git_commit_author(commit).memory)
|
||||
|
||||
let author1 = repo.withGitObject(oid) { commit in
|
||||
Signature(git_commit_author(commit).pointee)
|
||||
}
|
||||
let author2 = author1
|
||||
|
||||
|
||||
expect(author1).to(equal(author2))
|
||||
}
|
||||
|
||||
|
||||
it("should be false with unequal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid1 = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
|
||||
let oid2 = OID(string: "24e1e40ee77525d9e279f079f9906ad6d98c8940")!
|
||||
|
||||
let author1 = from_git_object(repo, oid1) { commit in
|
||||
Signature(git_commit_author(commit).memory)
|
||||
|
||||
let author1 = repo.withGitObject(oid1) { commit in
|
||||
Signature(git_commit_author(commit).pointee)
|
||||
}
|
||||
let author2 = from_git_object(repo, oid2) { commit in
|
||||
Signature(git_commit_author(commit).memory)
|
||||
let author2 = repo.withGitObject(oid2) { commit in
|
||||
Signature(git_commit_author(commit).pointee)
|
||||
}
|
||||
|
||||
|
||||
expect(author1).notTo(equal(author2))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("Signature.hashValue") {
|
||||
it("should be equal with equal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
|
||||
|
||||
let author1 = from_git_object(repo, oid) { commit in
|
||||
Signature(git_commit_author(commit).memory)
|
||||
|
||||
let author1 = repo.withGitObject(oid) { commit in
|
||||
Signature(git_commit_author(commit).pointee)
|
||||
}
|
||||
let author2 = author1
|
||||
|
||||
|
||||
expect(author1.hashValue).to(equal(author2.hashValue))
|
||||
}
|
||||
}
|
||||
@@ -91,13 +93,13 @@ class CommitSpec: QuickSpec {
|
||||
it("should initialize its properties") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "24e1e40ee77525d9e279f079f9906ad6d98c8940")!
|
||||
|
||||
let commit = from_git_object(repo, oid) { Commit($0) }
|
||||
let author = from_git_object(repo, oid) { commit in
|
||||
Signature(git_commit_author(commit).memory)
|
||||
|
||||
let commit = repo.withGitObject(oid) { Commit($0) }
|
||||
let author = repo.withGitObject(oid) { commit in
|
||||
Signature(git_commit_author(commit).pointee)
|
||||
}
|
||||
let committer = from_git_object(repo, oid) { commit in
|
||||
Signature(git_commit_committer(commit).memory)
|
||||
let committer = repo.withGitObject(oid) { commit in
|
||||
Signature(git_commit_committer(commit).pointee)
|
||||
}
|
||||
let tree = PointerTo<Tree>(OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!)
|
||||
let parents: [PointerTo<Commit>] = [
|
||||
@@ -110,20 +112,20 @@ class CommitSpec: QuickSpec {
|
||||
expect(commit.author).to(equal(author))
|
||||
expect(commit.committer).to(equal(committer))
|
||||
}
|
||||
|
||||
|
||||
it("should handle 0 parents") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
|
||||
|
||||
let commit = from_git_object(repo, oid) { Commit($0) }
|
||||
|
||||
let commit = repo.withGitObject(oid) { Commit($0) }
|
||||
expect(commit.parents).to(equal([]))
|
||||
}
|
||||
|
||||
|
||||
it("should handle multiple parents") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "c4ed03a6b7d7ce837d31d83757febbe84dd465fd")!
|
||||
|
||||
let commit = from_git_object(repo, oid) { Commit($0) }
|
||||
|
||||
let commit = repo.withGitObject(oid) { Commit($0) }
|
||||
let parents: [PointerTo<Commit>] = [
|
||||
PointerTo(OID(string: "315b3f344221db91ddc54b269f3c9af422da0f2e")!),
|
||||
PointerTo(OID(string: "57f6197561d1f99b03c160f4026a07f06b43cf20")!),
|
||||
@@ -131,34 +133,34 @@ class CommitSpec: QuickSpec {
|
||||
expect(commit.parents).to(equal(parents))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("==(Commit, Commit)") {
|
||||
it("should be true with equal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
|
||||
|
||||
let commit1 = from_git_object(repo, oid) { Commit($0) }
|
||||
|
||||
let commit1 = repo.withGitObject(oid) { Commit($0) }
|
||||
let commit2 = commit1
|
||||
expect(commit1).to(equal(commit2))
|
||||
}
|
||||
|
||||
|
||||
it("should be false with unequal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid1 = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
|
||||
let oid2 = OID(string: "c4ed03a6b7d7ce837d31d83757febbe84dd465fd")!
|
||||
|
||||
let commit1 = from_git_object(repo, oid1) { Commit($0) }
|
||||
let commit2 = from_git_object(repo, oid2) { Commit($0) }
|
||||
|
||||
let commit1 = repo.withGitObject(oid1) { Commit($0) }
|
||||
let commit2 = repo.withGitObject(oid2) { Commit($0) }
|
||||
expect(commit1).notTo(equal(commit2))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("Commit.hashValue") {
|
||||
it("should be equal with equal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!
|
||||
|
||||
let commit1 = from_git_object(repo, oid) { Commit($0) }
|
||||
|
||||
let commit1 = repo.withGitObject(oid) { Commit($0) }
|
||||
let commit2 = commit1
|
||||
expect(commit1.hashValue).to(equal(commit2.hashValue))
|
||||
}
|
||||
@@ -170,56 +172,56 @@ class TreeEntrySpec: QuickSpec {
|
||||
override func spec() {
|
||||
describe("Tree.Entry(attributes:object:name:)") {
|
||||
it("should set its properties") {
|
||||
let attributes = Int32(GIT_FILEMODE_BLOB.value)
|
||||
let object = Pointer.Blob(OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!)
|
||||
let attributes = Int32(GIT_FILEMODE_BLOB.rawValue)
|
||||
let object = Pointer.blob(OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!)
|
||||
let name = "README.md"
|
||||
|
||||
|
||||
let entry = Tree.Entry(attributes: attributes, object: object, name: name)
|
||||
expect(entry.attributes).to(equal(attributes))
|
||||
expect(entry.object).to(equal(object))
|
||||
expect(entry.name).to(equal(name))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("Tree.Entry(pointer)") {
|
||||
it("should set its properties") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
|
||||
|
||||
let entry = from_git_object(repo, oid) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
|
||||
expect(entry.attributes).to(equal(Int32(GIT_FILEMODE_BLOB.value)))
|
||||
expect(entry.object).to(equal(Pointer.Blob(OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!)))
|
||||
|
||||
let entry = repo.withGitObject(oid) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
|
||||
expect(entry.attributes).to(equal(Int32(GIT_FILEMODE_BLOB.rawValue)))
|
||||
expect(entry.object).to(equal(Pointer.blob(OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!)))
|
||||
expect(entry.name).to(equal("README.md"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("==(Tree.Entry, Tree.Entry)") {
|
||||
it("should be true with equal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
|
||||
|
||||
let entry1 = from_git_object(repo, oid) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
|
||||
|
||||
let entry1 = repo.withGitObject(oid) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
|
||||
let entry2 = entry1
|
||||
expect(entry1).to(equal(entry2))
|
||||
}
|
||||
|
||||
|
||||
it("should be false with unequal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid1 = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
|
||||
let oid2 = OID(string: "f93e3a1a1525fb5b91020da86e44810c87a2d7bc")!
|
||||
|
||||
let entry1 = from_git_object(repo, oid1) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
|
||||
let entry2 = from_git_object(repo, oid2) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
|
||||
|
||||
let entry1 = repo.withGitObject(oid1) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
|
||||
let entry2 = repo.withGitObject(oid2) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
|
||||
expect(entry1).notTo(equal(entry2))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("Tree.Entry.hashValue") {
|
||||
it("should be equal with equal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
|
||||
|
||||
let entry1 = from_git_object(repo, oid) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
|
||||
|
||||
let entry1 = repo.withGitObject(oid) { Tree.Entry(git_tree_entry_byindex($0, 0)) }
|
||||
let entry2 = entry1
|
||||
expect(entry1.hashValue).to(equal(entry2.hashValue))
|
||||
}
|
||||
@@ -233,42 +235,44 @@ class TreeSpec: QuickSpec {
|
||||
it("should initialize its properties") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
|
||||
|
||||
let tree = from_git_object(repo, oid) { Tree($0) }
|
||||
|
||||
let tree = repo.withGitObject(oid) { Tree($0) }
|
||||
let entries = [
|
||||
"README.md": Tree.Entry(attributes: Int32(GIT_FILEMODE_BLOB.value), object: .Blob(OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!), name: "README.md"),
|
||||
"README.md": Tree.Entry(attributes: Int32(GIT_FILEMODE_BLOB.rawValue),
|
||||
object: .blob(OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!),
|
||||
name: "README.md"),
|
||||
]
|
||||
expect(tree.entries).to(equal(entries))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("==(Tree, Tree)") {
|
||||
it("should be true with equal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
|
||||
|
||||
let tree1 = from_git_object(repo, oid) { Tree($0) }
|
||||
|
||||
let tree1 = repo.withGitObject(oid) { Tree($0) }
|
||||
let tree2 = tree1
|
||||
expect(tree1).to(equal(tree2))
|
||||
}
|
||||
|
||||
|
||||
it("should be false with unequal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid1 = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
|
||||
let oid2 = OID(string: "f93e3a1a1525fb5b91020da86e44810c87a2d7bc")!
|
||||
|
||||
let tree1 = from_git_object(repo, oid1) { Tree($0) }
|
||||
let tree2 = from_git_object(repo, oid2) { Tree($0) }
|
||||
|
||||
let tree1 = repo.withGitObject(oid1) { Tree($0) }
|
||||
let tree2 = repo.withGitObject(oid2) { Tree($0) }
|
||||
expect(tree1).notTo(equal(tree2))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("Tree.hashValue") {
|
||||
it("should be equal with equal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "219e9f39c2fb59ed1dfb3e78ed75055a57528f31")!
|
||||
|
||||
let tree1 = from_git_object(repo, oid) { Tree($0) }
|
||||
|
||||
let tree1 = repo.withGitObject(oid) { Tree($0) }
|
||||
let tree2 = tree1
|
||||
expect(tree1.hashValue).to(equal(tree2.hashValue))
|
||||
}
|
||||
@@ -282,42 +286,42 @@ class BlobSpec: QuickSpec {
|
||||
it("should initialize its properties") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!
|
||||
|
||||
let blob = from_git_object(repo, oid) { Blob($0) }
|
||||
|
||||
let blob = repo.withGitObject(oid) { Blob($0) }
|
||||
let contents = "# Simple Repository\nA simple repository used for testing SwiftGit2.\n\n## Branches\n\n- master\n\n"
|
||||
let data = (contents as NSString).dataUsingEncoding(NSUTF8StringEncoding)!
|
||||
let data = contents.data(using: String.Encoding.utf8)!
|
||||
expect(blob.oid).to(equal(oid))
|
||||
expect(blob.data).to(equal(data))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("==(Blob, Blob)") {
|
||||
it("should be true with equal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!
|
||||
|
||||
let blob1 = from_git_object(repo, oid) { Blob($0) }
|
||||
|
||||
let blob1 = repo.withGitObject(oid) { Blob($0) }
|
||||
let blob2 = blob1
|
||||
expect(blob1).to(equal(blob2))
|
||||
}
|
||||
|
||||
|
||||
it("should be false with unequal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid1 = OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!
|
||||
let oid2 = OID(string: "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")!
|
||||
|
||||
let blob1 = from_git_object(repo, oid1) { Blob($0) }
|
||||
let blob2 = from_git_object(repo, oid2) { Blob($0) }
|
||||
|
||||
let blob1 = repo.withGitObject(oid1) { Blob($0) }
|
||||
let blob2 = repo.withGitObject(oid2) { Blob($0) }
|
||||
expect(blob1).notTo(equal(blob2))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("Blob.hashValue") {
|
||||
it("should be equal with equal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "41078396f5187daed5f673e4a13b185bbad71fba")!
|
||||
|
||||
let blob1 = from_git_object(repo, oid) { Blob($0) }
|
||||
|
||||
let blob1 = repo.withGitObject(oid) { Blob($0) }
|
||||
let blob2 = blob1
|
||||
expect(blob1.hashValue).to(equal(blob2.hashValue))
|
||||
}
|
||||
@@ -331,45 +335,45 @@ class TagSpec: QuickSpec {
|
||||
it("should set its properties") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "57943b8ee00348180ceeedc960451562750f6d33")!
|
||||
|
||||
let tag = from_git_object(repo, oid) { Tag($0) }
|
||||
let tagger = from_git_object(repo, oid) { Signature(git_tag_tagger($0).memory) }
|
||||
|
||||
|
||||
let tag = repo.withGitObject(oid) { Tag($0) }
|
||||
let tagger = repo.withGitObject(oid) { Signature(git_tag_tagger($0).pointee) }
|
||||
|
||||
expect(tag.oid).to(equal(oid))
|
||||
expect(tag.target).to(equal(Pointer.Commit(OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!)))
|
||||
expect(tag.target).to(equal(Pointer.commit(OID(string: "dc220a3f0c22920dab86d4a8d3a3cb7e69d6205a")!)))
|
||||
expect(tag.name).to(equal("tag-1"))
|
||||
expect(tag.tagger).to(equal(tagger))
|
||||
expect(tag.message).to(equal("tag-1\n"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("==(Tag, Tag)") {
|
||||
it("should be true with equal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "57943b8ee00348180ceeedc960451562750f6d33")!
|
||||
|
||||
let tag1 = from_git_object(repo, oid) { Tag($0) }
|
||||
|
||||
let tag1 = repo.withGitObject(oid) { Tag($0) }
|
||||
let tag2 = tag1
|
||||
expect(tag1).to(equal(tag2))
|
||||
}
|
||||
|
||||
|
||||
it("should be false with unequal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid1 = OID(string: "57943b8ee00348180ceeedc960451562750f6d33")!
|
||||
let oid2 = OID(string: "13bda91157f255ab224ff88d0a11a82041c9d0c1")!
|
||||
|
||||
let tag1 = from_git_object(repo, oid1) { Tag($0) }
|
||||
let tag2 = from_git_object(repo, oid2) { Tag($0) }
|
||||
|
||||
let tag1 = repo.withGitObject(oid1) { Tag($0) }
|
||||
let tag2 = repo.withGitObject(oid2) { Tag($0) }
|
||||
expect(tag1).notTo(equal(tag2))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("Tag.hashValue") {
|
||||
it("should be equal with equal objects") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let oid = OID(string: "57943b8ee00348180ceeedc960451562750f6d33")!
|
||||
|
||||
let tag1 = from_git_object(repo, oid) { Tag($0) }
|
||||
|
||||
let tag1 = repo.withGitObject(oid) { Tag($0) }
|
||||
let tag2 = tag1
|
||||
expect(tag1.hashValue).to(equal(tag2.hashValue))
|
||||
}
|
||||
|
||||
@@ -6,46 +6,48 @@
|
||||
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import LlamaKit
|
||||
import SwiftGit2
|
||||
import Nimble
|
||||
import Quick
|
||||
import Clibgit2
|
||||
|
||||
func from_git_reference<T>(repository: Repository, name: String, f: COpaquePointer -> T) -> T {
|
||||
let repository = repository.pointer
|
||||
|
||||
var pointer: COpaquePointer = nil
|
||||
git_reference_lookup(&pointer, repository, name)
|
||||
let result = f(pointer)
|
||||
git_object_free(pointer)
|
||||
|
||||
return result
|
||||
private extension Repository {
|
||||
func withGitReference<T>(named name: String, transform: (OpaquePointer) -> T) -> T {
|
||||
let repository = self.pointer
|
||||
|
||||
var pointer: OpaquePointer? = nil
|
||||
git_reference_lookup(&pointer, repository, name)
|
||||
let result = transform(pointer!)
|
||||
git_reference_free(pointer)
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
class ReferenceSpec: QuickSpec {
|
||||
class ReferenceSpec: FixturesSpec {
|
||||
override func spec() {
|
||||
describe("Reference(pointer)") {
|
||||
it("should initialize its properties") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let ref = from_git_reference(repo, "refs/heads/master") { Reference($0) }
|
||||
let ref = repo.withGitReference(named: "refs/heads/master") { Reference($0) }
|
||||
expect(ref.longName).to(equal("refs/heads/master"))
|
||||
expect(ref.shortName).to(equal("master"))
|
||||
expect(ref.oid).to(equal(OID(string: "c4ed03a6b7d7ce837d31d83757febbe84dd465fd")!))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("==(Reference, Reference)") {
|
||||
it("should be true with equal references") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let ref1 = from_git_reference(repo, "refs/heads/master") { Reference($0) }
|
||||
let ref2 = from_git_reference(repo, "refs/heads/master") { Reference($0) }
|
||||
let ref1 = repo.withGitReference(named: "refs/heads/master") { Reference($0) }
|
||||
let ref2 = repo.withGitReference(named: "refs/heads/master") { Reference($0) }
|
||||
expect(ref1).to(equal(ref2))
|
||||
}
|
||||
|
||||
|
||||
it("should be false with unequal references") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let ref1 = from_git_reference(repo, "refs/heads/master") { Reference($0) }
|
||||
let ref2 = from_git_reference(repo, "refs/heads/another-branch") { Reference($0) }
|
||||
let ref1 = repo.withGitReference(named: "refs/heads/master") { Reference($0) }
|
||||
let ref2 = repo.withGitReference(named: "refs/heads/another-branch") { Reference($0) }
|
||||
expect(ref1).notTo(equal(ref2))
|
||||
}
|
||||
}
|
||||
@@ -53,8 +55,8 @@ class ReferenceSpec: QuickSpec {
|
||||
describe("Reference.hashValue") {
|
||||
it("should be equal with equal references") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let ref1 = from_git_reference(repo, "refs/heads/master") { Reference($0) }
|
||||
let ref2 = from_git_reference(repo, "refs/heads/master") { Reference($0) }
|
||||
let ref1 = repo.withGitReference(named: "refs/heads/master") { Reference($0) }
|
||||
let ref2 = repo.withGitReference(named: "refs/heads/master") { Reference($0) }
|
||||
expect(ref1.hashValue).to(equal(ref2.hashValue))
|
||||
}
|
||||
}
|
||||
@@ -66,7 +68,7 @@ class BranchSpec: QuickSpec {
|
||||
describe("Branch(pointer)") {
|
||||
it("should initialize its properties") {
|
||||
let repo = Fixtures.mantleRepository
|
||||
let branch = from_git_reference(repo, "refs/heads/master") { Branch($0)! }
|
||||
let branch = repo.withGitReference(named: "refs/heads/master") { Branch($0)! }
|
||||
expect(branch.longName).to(equal("refs/heads/master"))
|
||||
expect(branch.name).to(equal("master"))
|
||||
expect(branch.shortName).to(equal(branch.name))
|
||||
@@ -75,10 +77,10 @@ class BranchSpec: QuickSpec {
|
||||
expect(branch.isLocal).to(beTrue())
|
||||
expect(branch.isRemote).to(beFalse())
|
||||
}
|
||||
|
||||
|
||||
it("should work with symoblic refs") {
|
||||
let repo = Fixtures.mantleRepository
|
||||
let branch = from_git_reference(repo, "refs/remotes/origin/HEAD") { Branch($0)! }
|
||||
let branch = repo.withGitReference(named: "refs/remotes/origin/HEAD") { Branch($0)! }
|
||||
expect(branch.longName).to(equal("refs/remotes/origin/HEAD"))
|
||||
expect(branch.name).to(equal("origin/HEAD"))
|
||||
expect(branch.shortName).to(equal(branch.name))
|
||||
@@ -88,19 +90,19 @@ class BranchSpec: QuickSpec {
|
||||
expect(branch.isRemote).to(beTrue())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("==(Branch, Branch)") {
|
||||
it("should be true with equal branches") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let branch1 = from_git_reference(repo, "refs/heads/master") { Branch($0)! }
|
||||
let branch2 = from_git_reference(repo, "refs/heads/master") { Branch($0)! }
|
||||
let branch1 = repo.withGitReference(named: "refs/heads/master") { Branch($0)! }
|
||||
let branch2 = repo.withGitReference(named: "refs/heads/master") { Branch($0)! }
|
||||
expect(branch1).to(equal(branch2))
|
||||
}
|
||||
|
||||
|
||||
it("should be false with unequal branches") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let branch1 = from_git_reference(repo, "refs/heads/master") { Branch($0)! }
|
||||
let branch2 = from_git_reference(repo, "refs/heads/another-branch") { Branch($0)! }
|
||||
let branch1 = repo.withGitReference(named: "refs/heads/master") { Branch($0)! }
|
||||
let branch2 = repo.withGitReference(named: "refs/heads/another-branch") { Branch($0)! }
|
||||
expect(branch1).notTo(equal(branch2))
|
||||
}
|
||||
}
|
||||
@@ -108,8 +110,8 @@ class BranchSpec: QuickSpec {
|
||||
describe("Branch.hashValue") {
|
||||
it("should be equal with equal references") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let branch1 = from_git_reference(repo, "refs/heads/master") { Branch($0)! }
|
||||
let branch2 = from_git_reference(repo, "refs/heads/master") { Branch($0)! }
|
||||
let branch1 = repo.withGitReference(named: "refs/heads/master") { Branch($0)! }
|
||||
let branch2 = repo.withGitReference(named: "refs/heads/master") { Branch($0)! }
|
||||
expect(branch1.hashValue).to(equal(branch2.hashValue))
|
||||
}
|
||||
}
|
||||
@@ -121,41 +123,41 @@ class TagReferenceSpec: QuickSpec {
|
||||
describe("TagReference(pointer)") {
|
||||
it("should work with an annotated tag") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let tag = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! }
|
||||
let tag = repo.withGitReference(named: "refs/tags/tag-2") { TagReference($0)! }
|
||||
expect(tag.longName).to(equal("refs/tags/tag-2"))
|
||||
expect(tag.name).to(equal("tag-2"))
|
||||
expect(tag.shortName).to(equal(tag.name))
|
||||
expect(tag.oid).to(equal(OID(string: "24e1e40ee77525d9e279f079f9906ad6d98c8940")!))
|
||||
}
|
||||
|
||||
|
||||
it("should work with a lightweight tag") {
|
||||
let repo = Fixtures.mantleRepository
|
||||
let tag = from_git_reference(repo, "refs/tags/1.5.4") { TagReference($0)! }
|
||||
let tag = repo.withGitReference(named: "refs/tags/1.5.4") { TagReference($0)! }
|
||||
expect(tag.longName).to(equal("refs/tags/1.5.4"))
|
||||
expect(tag.name).to(equal("1.5.4"))
|
||||
expect(tag.shortName).to(equal(tag.name))
|
||||
expect(tag.oid).to(equal(OID(string: "d9dc95002cfbf3929d2b70d2c8a77e6bf5b1b88a")!))
|
||||
}
|
||||
|
||||
|
||||
it("should return nil if not a tag") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let tag = from_git_reference(repo, "refs/heads/master") { TagReference($0) }
|
||||
let tag = repo.withGitReference(named: "refs/heads/master") { TagReference($0) }
|
||||
expect(tag).to(beNil())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("==(TagReference, TagReference)") {
|
||||
it("should be true with equal tag references") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let tag1 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! }
|
||||
let tag2 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! }
|
||||
let tag1 = repo.withGitReference(named: "refs/tags/tag-2") { TagReference($0)! }
|
||||
let tag2 = repo.withGitReference(named: "refs/tags/tag-2") { TagReference($0)! }
|
||||
expect(tag1).to(equal(tag2))
|
||||
}
|
||||
|
||||
|
||||
it("should be false with unequal tag references") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let tag1 = from_git_reference(repo, "refs/tags/tag-1") { TagReference($0)! }
|
||||
let tag2 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! }
|
||||
let tag1 = repo.withGitReference(named: "refs/tags/tag-1") { TagReference($0)! }
|
||||
let tag2 = repo.withGitReference(named: "refs/tags/tag-2") { TagReference($0)! }
|
||||
expect(tag1).notTo(equal(tag2))
|
||||
}
|
||||
}
|
||||
@@ -163,8 +165,8 @@ class TagReferenceSpec: QuickSpec {
|
||||
describe("TagReference.hashValue") {
|
||||
it("should be equal with equal references") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let tag1 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! }
|
||||
let tag2 = from_git_reference(repo, "refs/tags/tag-2") { TagReference($0)! }
|
||||
let tag1 = repo.withGitReference(named: "refs/tags/tag-2") { TagReference($0)! }
|
||||
let tag2 = repo.withGitReference(named: "refs/tags/tag-2") { TagReference($0)! }
|
||||
expect(tag1.hashValue).to(equal(tag2.hashValue))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,54 +6,56 @@
|
||||
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import LlamaKit
|
||||
import SwiftGit2
|
||||
import Nimble
|
||||
import Quick
|
||||
import Clibgit2
|
||||
|
||||
func with_git_remote<T>(repository: Repository, name: String, f: COpaquePointer -> T) -> T {
|
||||
let repository = repository.pointer
|
||||
|
||||
var pointer: COpaquePointer = nil
|
||||
git_remote_lookup(&pointer, repository, name)
|
||||
let result = f(pointer)
|
||||
git_object_free(pointer)
|
||||
|
||||
return result
|
||||
private extension Repository {
|
||||
func withGitRemote<T>(named name: String, transform: (OpaquePointer) -> T) -> T {
|
||||
let repository = self.pointer
|
||||
|
||||
var pointer: OpaquePointer? = nil
|
||||
git_remote_lookup(&pointer, repository, name)
|
||||
let result = transform(pointer!)
|
||||
git_remote_free(pointer)
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
class RemoteSpec: QuickSpec {
|
||||
class RemoteSpec: FixturesSpec {
|
||||
override func spec() {
|
||||
describe("Remote(pointer)") {
|
||||
it("should initialize its properties") {
|
||||
let repo = Fixtures.mantleRepository
|
||||
let remote = with_git_remote(repo, "upstream") { Remote($0) }
|
||||
|
||||
let remote = repo.withGitRemote(named: "upstream") { Remote($0) }
|
||||
|
||||
expect(remote.name).to(equal("upstream"))
|
||||
expect(remote.URL).to(equal("git@github.com:Mantle/Mantle.git"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("==(Remote, Remote)") {
|
||||
it("should be true with equal objects") {
|
||||
let repo = Fixtures.mantleRepository
|
||||
let remote1 = with_git_remote(repo, "upstream") { Remote($0) }
|
||||
let remote1 = repo.withGitRemote(named: "upstream") { Remote($0) }
|
||||
let remote2 = remote1
|
||||
expect(remote1).to(equal(remote2))
|
||||
}
|
||||
|
||||
|
||||
it("should be false with unequal objcets") {
|
||||
let repo = Fixtures.mantleRepository
|
||||
let origin = with_git_remote(repo, "origin") { Remote($0) }
|
||||
let upstream = with_git_remote(repo, "upstream") { Remote($0) }
|
||||
let origin = repo.withGitRemote(named: "origin") { Remote($0) }
|
||||
let upstream = repo.withGitRemote(named: "upstream") { Remote($0) }
|
||||
expect(origin).notTo(equal(upstream))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("Remote.hashValue") {
|
||||
it("should be equal with equal objcets") {
|
||||
let repo = Fixtures.mantleRepository
|
||||
let remote1 = with_git_remote(repo, "upstream") { Remote($0) }
|
||||
let remote1 = repo.withGitRemote(named: "upstream") { Remote($0) }
|
||||
let remote2 = remote1
|
||||
expect(remote1.hashValue).to(equal(remote2.hashValue))
|
||||
}
|
||||
|
||||
+735
-180
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,16 @@
|
||||
// Once Nimble adds matchers for the Result type, remove these shims and refactor the tests that use them.
|
||||
extension Result {
|
||||
var value: Success? {
|
||||
guard case .success(let value) = self else {
|
||||
return nil
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
var error: Failure? {
|
||||
guard case .failure(let error) = self else {
|
||||
return nil
|
||||
}
|
||||
return error
|
||||
}
|
||||
}
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../External/libgit2/include/git2
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../External/libgit2/include/git2.h
|
||||
@@ -0,0 +1,31 @@
|
||||
module Clibgit2 {
|
||||
umbrella header "git2.h"
|
||||
|
||||
export *
|
||||
module * { export * }
|
||||
|
||||
// Exclude headers intended only for Microsoft compilers
|
||||
exclude header "git2/inttypes.h"
|
||||
exclude header "git2/stdint.h"
|
||||
|
||||
// Explicit modules for headers not included in the umbrella header:
|
||||
explicit module cred_helpers {
|
||||
header "git2/cred_helpers.h"
|
||||
|
||||
export *
|
||||
}
|
||||
|
||||
explicit module trace {
|
||||
header "git2/trace.h"
|
||||
|
||||
export *
|
||||
}
|
||||
|
||||
// Explicit module for the "sys" headers:
|
||||
explicit module sys {
|
||||
umbrella "git2/sys"
|
||||
|
||||
export *
|
||||
module * { export * }
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
**Copyright (c) 2013 Justin Spahr-Summers**
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
@@ -1,82 +0,0 @@
|
||||
# objc-build-scripts
|
||||
|
||||
This project is a collection of scripts created with two goals:
|
||||
|
||||
1. To standardize how Objective-C projects are bootstrapped after cloning
|
||||
1. To easily build Objective-C projects on continuous integration servers
|
||||
|
||||
## Scripts
|
||||
|
||||
Right now, there are two important scripts: [`bootstrap`](#bootstrap) and
|
||||
[`cibuild`](#cibuild). Both are Bash scripts, to maximize compatibility and
|
||||
eliminate pesky system configuration issues (like setting up a working Ruby
|
||||
environment).
|
||||
|
||||
The structure of the scripts on disk is meant to follow that of a typical Ruby
|
||||
project:
|
||||
|
||||
```
|
||||
script/
|
||||
bootstrap
|
||||
cibuild
|
||||
```
|
||||
|
||||
### bootstrap
|
||||
|
||||
This script is responsible for bootstrapping (initializing) your project after
|
||||
it's been checked out. Here, you should install or clone any dependencies that
|
||||
are required for a working build and development environment.
|
||||
|
||||
By default, the script will verify that [xctool][] is installed, then initialize
|
||||
and update submodules recursively. If any submodules contain `script/bootstrap`,
|
||||
that will be run as well.
|
||||
|
||||
To check that other tools are installed, you can set the `REQUIRED_TOOLS`
|
||||
environment variable before running `script/bootstrap`, or edit it within the
|
||||
script directly. Note that no installation is performed automatically, though
|
||||
this can always be added within your specific project.
|
||||
|
||||
### cibuild
|
||||
|
||||
This script is responsible for building the project, as you would want it built
|
||||
for continuous integration. This is preferable to putting the logic on the CI
|
||||
server itself, since it ensures that any changes are versioned along with the
|
||||
source.
|
||||
|
||||
By default, the script will run [`bootstrap`](#bootstrap), look for any Xcode
|
||||
workspace or project in the working directory, then build all targets/schemes
|
||||
(as found by `xcodebuild -list`) using [xctool][].
|
||||
|
||||
You can also specify the schemes to build by passing them into the script:
|
||||
|
||||
```sh
|
||||
script/cibuild ReactiveCocoa-Mac ReactiveCocoa-iOS
|
||||
```
|
||||
|
||||
As with the `bootstrap` script, there are several environment variables that can
|
||||
be used to customize behavior. They can be set on the command line before
|
||||
invoking the script, or the defaults changed within the script directly.
|
||||
|
||||
## Getting Started
|
||||
|
||||
To add the scripts to your project, read the contents of this repository into
|
||||
a `script` folder:
|
||||
|
||||
```
|
||||
$ git remote add objc-build-scripts https://github.com/jspahrsummers/objc-build-scripts.git
|
||||
$ git fetch objc-build-scripts
|
||||
$ git read-tree --prefix=script/ -u objc-build-scripts/master
|
||||
```
|
||||
|
||||
Then commit the changes, to incorporate the scripts into your own repository's
|
||||
history. You can also freely tweak the scripts for your specific project's
|
||||
needs.
|
||||
|
||||
To merge in upstream changes later:
|
||||
|
||||
```
|
||||
$ git fetch -p objc-build-scripts
|
||||
$ git merge --ff --squash -Xsubtree=script objc-build-scripts/master
|
||||
```
|
||||
|
||||
[xctool]: https://github.com/facebook/xctool
|
||||
+77
-42
@@ -9,7 +9,8 @@ export SCRIPT_DIR=$(dirname "$0")
|
||||
config ()
|
||||
{
|
||||
# A whitespace-separated list of executables that must be present and locatable.
|
||||
: ${REQUIRED_TOOLS="xctool cmake"}
|
||||
# These will each be installed through Homebrew if not found.
|
||||
: ${REQUIRED_TOOLS="cmake libssh2 libtool autoconf automake pkg-config"}
|
||||
|
||||
export REQUIRED_TOOLS
|
||||
}
|
||||
@@ -22,12 +23,6 @@ main ()
|
||||
{
|
||||
config
|
||||
|
||||
if [ -n "$REQUIRED_TOOLS" ]
|
||||
then
|
||||
echo "*** Checking dependencies..."
|
||||
check_deps
|
||||
fi
|
||||
|
||||
local submodules=$(git submodule status)
|
||||
local result=$?
|
||||
|
||||
@@ -41,62 +36,100 @@ main ()
|
||||
echo "*** Updating submodules..."
|
||||
update_submodules
|
||||
fi
|
||||
|
||||
if [ -n "$REQUIRED_TOOLS" ]
|
||||
then
|
||||
echo "*** Checking dependencies..."
|
||||
check_deps
|
||||
fi
|
||||
}
|
||||
|
||||
check_deps ()
|
||||
{
|
||||
for tool in $REQUIRED_TOOLS
|
||||
do
|
||||
which -s "$tool"
|
||||
if [ "$?" -ne "0" ]
|
||||
echo "** check_deps **"
|
||||
# Check if Homebrew is installed
|
||||
which -s brew
|
||||
local result=$?
|
||||
|
||||
if [ "$result" -ne "0" ]
|
||||
then
|
||||
echo
|
||||
echo "Homebrew is not installed (http://brew.sh). You will need to manually ensure the following tools are installed:"
|
||||
echo " $REQUIRED_TOOLS"
|
||||
echo
|
||||
echo "Additionally, the following libssh2 files must be symlinked under /usr/local or /opt/homebrew :"
|
||||
echo " lib/libssh2.a include/libssh2.h include/libssh2_sftp.h include/libssh2_publickey.h"
|
||||
|
||||
if [ ! -z "$CI" ]
|
||||
then
|
||||
echo "*** Error: $tool not found. Please install it and bootstrap again."
|
||||
exit 1
|
||||
echo
|
||||
echo "I will try to install brew now on the github runner"
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
|
||||
eval "$(/opt/homebrew/bin/brew shellenv)"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Ensure that we have libgit2's dependencies installed.
|
||||
installed=`brew list`
|
||||
libs="libssh2 libtool autoconf automake"
|
||||
installed=$(brew list)
|
||||
|
||||
for lib in $libs
|
||||
for tool in $REQUIRED_TOOLS
|
||||
do
|
||||
# Skip packages that are already installed.
|
||||
echo "$installed" | grep -q "$lib" && code=$? || code=$?
|
||||
echo "$installed" | grep -q "$tool" && code=$? || code=$?
|
||||
|
||||
if [ "$code" -eq "0" ]
|
||||
then
|
||||
echo "*** $tool is available 👍"
|
||||
continue
|
||||
elif [ "$code" -ne "1" ]
|
||||
then
|
||||
exit $code
|
||||
fi
|
||||
|
||||
echo "*** Installing $lib with Homebrew..."
|
||||
brew install "$lib"
|
||||
echo "*** Installing $tool with Homebrew..."
|
||||
brew install "$tool"
|
||||
done
|
||||
|
||||
brew_prefix=`brew --prefix`
|
||||
expected_prefix=/usr/local
|
||||
|
||||
if [ "$brew_prefix" != "$expected_prefix" ]
|
||||
then
|
||||
echo "*** Adding soft links into $expected_prefix..."
|
||||
|
||||
products=(lib/libssh2.a include/libssh2.h include/libssh2_sftp.h include/libssh2_publickey.h)
|
||||
|
||||
for product in "${products[@]}"
|
||||
do
|
||||
destination="$expected_prefix/$product"
|
||||
if [ -e "$destination" ]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
sudo mkdir -p "$(dirname "$destination")"
|
||||
sudo ln -s "$brew_prefix/$product" "$destination"
|
||||
done
|
||||
brew_prefix=$(brew --prefix)
|
||||
if [[ $(uname -m) == 'arm64' ]]; then
|
||||
echo "** Running on a Apple Silicon M1"
|
||||
expected_prefix=/opt/homebrew
|
||||
else
|
||||
echo "** Running on a Apple x86"
|
||||
expected_prefix=/usr/local
|
||||
fi
|
||||
|
||||
install_path="./External"
|
||||
pwd
|
||||
set -x
|
||||
cp "$brew_prefix"/lib/libcrypto.a $install_path
|
||||
cp "$brew_prefix"/lib/libssl.a $install_path
|
||||
cp "$brew_prefix"/lib/libssh2.a $install_path
|
||||
set +x
|
||||
if [ "$brew_prefix" != "$expected_prefix" ]
|
||||
then
|
||||
echo "*** Adding soft links into $expected_prefix..."
|
||||
|
||||
products=(lib/libssh2.a include/libssh2.h include/libssh2_sftp.h include/libssh2_publickey.h)
|
||||
|
||||
for product in "${products[@]}"
|
||||
do
|
||||
destination="$expected_prefix/$product"
|
||||
if [ -e "$destination" ]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
sudo mkdir -p "$(dirname "$destination")"
|
||||
sudo ln -s "$brew_prefix/$product" "$destination"
|
||||
done
|
||||
fi
|
||||
|
||||
# openssl@1 is expected
|
||||
#sslSource=$(find $brew_prefix -name libcrypto.a | grep openssl | sort | head -1 | xargs dirname)
|
||||
#echo "Find libcrypto.a and take first $sslSource and copy to install_path=$install_path"
|
||||
#cp $sslSource/* "$install_path" 2>/dev/null | echo "Copy and ignore subdirectory. This makes build work on x86 and arm64"
|
||||
}
|
||||
|
||||
bootstrap_submodule ()
|
||||
@@ -105,7 +138,7 @@ bootstrap_submodule ()
|
||||
|
||||
if [ -e "$bootstrap" ]
|
||||
then
|
||||
echo "*** Bootstrapping $name..."
|
||||
echo "*** Bootstrapping ..."
|
||||
"$bootstrap" >/dev/null
|
||||
else
|
||||
update_submodules
|
||||
@@ -114,7 +147,9 @@ bootstrap_submodule ()
|
||||
|
||||
update_submodules ()
|
||||
{
|
||||
git submodule sync --quiet && git submodule update --init && git submodule foreach --quiet bootstrap_submodule
|
||||
git submodule sync --quiet && \
|
||||
git submodule update --init && \
|
||||
git submodule foreach --quiet bootstrap_submodule
|
||||
}
|
||||
|
||||
export -f bootstrap_submodule
|
||||
|
||||
+69
-133
@@ -1,150 +1,86 @@
|
||||
#!/bin/bash
|
||||
#!/bin/bash -ex
|
||||
#
|
||||
# script/cibuild
|
||||
# SwiftGit2
|
||||
#
|
||||
# Executes the build and runs tests for Mac and iOS. Designed to be invoked by
|
||||
# Travis as a matrix build so that the two platform builds can run in parallel.
|
||||
#
|
||||
# Dependent tools & scripts:
|
||||
# - script/bootstrap
|
||||
# - script/update_libssl_ios
|
||||
# - [xcodebuild](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html)
|
||||
# - xcpretty (gem)
|
||||
# - xcpretty-travis-formatter (gem)
|
||||
#
|
||||
# Environment Variables:
|
||||
# - SCHEME: specifies which Xcode scheme to build. Set to one of the following:
|
||||
# - SwiftGit2-OSX
|
||||
# - SwiftGit2-iOS
|
||||
# - TRAVIS: indicates when the build is being run by travis, used to invoke
|
||||
# the xcpretty-travis-formatter gem for output.
|
||||
|
||||
if [ -z "$SCHEME" ]; then
|
||||
echo "The SCHEME environment variable is empty. Please set this to one of:"
|
||||
echo "- SwiftGit2-OSX"
|
||||
echo "- SwiftGit2-iOS"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export SCRIPT_DIR=$(dirname "$0")
|
||||
|
||||
##
|
||||
## Configuration Variables
|
||||
##
|
||||
|
||||
SCHEMES="$@"
|
||||
set -o pipefail
|
||||
SCRIPT_DIR=$(dirname "$0")
|
||||
XCWORKSPACE="SwiftGit2.xcworkspace"
|
||||
XCODE_OPTIONS=$(RUN_CLANG_STATIC_ANALYZER=NO ONLY_ACTIVE_ARCH=NO CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO)
|
||||
|
||||
config ()
|
||||
{
|
||||
# The workspace to build.
|
||||
#
|
||||
# If not set and no workspace is found, the -workspace flag will not be passed
|
||||
# to `xctool`.
|
||||
#
|
||||
# Only one of `XCWORKSPACE` and `XCODEPROJ` needs to be set. The former will
|
||||
# take precedence.
|
||||
: ${XCWORKSPACE=$(find_pattern "*.xcworkspace")}
|
||||
|
||||
# The project to build.
|
||||
#
|
||||
# If not set and no project is found, the -project flag will not be passed
|
||||
# to `xctool`.
|
||||
#
|
||||
# Only one of `XCWORKSPACE` and `XCODEPROJ` needs to be set. The former will
|
||||
# take precedence.
|
||||
: ${XCODEPROJ=$(find_pattern "*.xcodeproj")}
|
||||
|
||||
# A bootstrap script to run before building.
|
||||
#
|
||||
# If this file does not exist, it is not considered an error.
|
||||
: ${BOOTSTRAP="$SCRIPT_DIR/bootstrap"}
|
||||
|
||||
# Extra options to pass to xctool.
|
||||
: ${XCTOOL_OPTIONS="RUN_CLANG_STATIC_ANALYZER=NO"}
|
||||
|
||||
# A whitespace-separated list of default schemes to build.
|
||||
#
|
||||
# Individual names can be quoted to avoid word splitting.
|
||||
: ${SCHEMES:=$(xcodebuild -list -project "$XCODEPROJ" 2>/dev/null | awk -f "$SCRIPT_DIR/schemes.awk")}
|
||||
|
||||
export XCWORKSPACE
|
||||
export XCODEPROJ
|
||||
export BOOTSTRAP
|
||||
export XCTOOL_OPTIONS
|
||||
export SCHEMES
|
||||
}
|
||||
if [ -n "$TRAVIS" ]; then
|
||||
# Use a special formatter when running on TravisCI
|
||||
XCPRETTY_FORMAT_OPTIONS="-f `xcpretty-travis-formatter`"
|
||||
else
|
||||
XCPRETTY_FORMAT_OPTIONS="--color"
|
||||
fi
|
||||
|
||||
##
|
||||
## Build Process
|
||||
##
|
||||
|
||||
main ()
|
||||
{
|
||||
config
|
||||
echo "*** Bootstrapping..."
|
||||
"$SCRIPT_DIR/bootstrap"
|
||||
|
||||
if [ -f "$BOOTSTRAP" ]
|
||||
then
|
||||
echo "*** Bootstrapping..."
|
||||
"$BOOTSTRAP" || exit $?
|
||||
fi
|
||||
if [ "$SCHEME" == "SwiftGit2-OSX" ]; then
|
||||
echo "*** Building and testing $SCHEME..."
|
||||
echo
|
||||
|
||||
echo "*** The following schemes will be built:"
|
||||
echo "$SCHEMES" | xargs -n 1 echo " "
|
||||
echo
|
||||
xcodebuild -workspace "$XCWORKSPACE" \
|
||||
-scheme "$SCHEME" \
|
||||
"${XCODE_OPTIONS[*]}" \
|
||||
build test \
|
||||
2>&1 | xcpretty $XCPRETTY_FORMAT_OPTIONS
|
||||
elif [ "$SCHEME" == "SwiftGit2-iOS" ]; then
|
||||
echo "*** Prebuilding OpenSSL"
|
||||
"$SCRIPT_DIR/update_libssl_ios"
|
||||
|
||||
echo "$SCHEMES" | xargs -n 1 | (
|
||||
local status=0
|
||||
echo "*** Creating a simulator for testing..."
|
||||
# Create a new simulator device and reference it by id to avoid xcodebuild exit status 70 with the following errors:
|
||||
# "The requested device could not be found because no available devices matched the request."
|
||||
# "The requested device could not be found because multiple devices matched the request."
|
||||
SIMULATOR_NAME="Custom Simulator"
|
||||
DEVICE_ID=com.apple.CoreSimulator.SimDeviceType.iPhone-X
|
||||
RUNTIME_ID=com.apple.CoreSimulator.SimRuntime.iOS-11-4
|
||||
DESTINATION_ID=$(xcrun simctl create "$SIMULATOR_NAME" $DEVICE_ID $RUNTIME_ID)
|
||||
|
||||
while read scheme
|
||||
do
|
||||
build_scheme "$scheme" || status=1
|
||||
done
|
||||
echo "*** Building and testing $SCHEME..."
|
||||
echo
|
||||
|
||||
exit $status
|
||||
)
|
||||
}
|
||||
|
||||
find_pattern ()
|
||||
{
|
||||
ls -d $1 2>/dev/null | head -n 1
|
||||
}
|
||||
|
||||
run_xctool ()
|
||||
{
|
||||
if [ -n "$XCWORKSPACE" ]
|
||||
then
|
||||
xctool -workspace "$XCWORKSPACE" $XCTOOL_OPTIONS "$@" 2>&1
|
||||
elif [ -n "$XCODEPROJ" ]
|
||||
then
|
||||
xctool -project "$XCODEPROJ" $XCTOOL_OPTIONS "$@" 2>&1
|
||||
else
|
||||
echo "*** No workspace or project file found."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
parse_build ()
|
||||
{
|
||||
awk -f "$SCRIPT_DIR/xctool.awk" 2>&1 >/dev/null
|
||||
}
|
||||
|
||||
build_scheme ()
|
||||
{
|
||||
local scheme=$1
|
||||
|
||||
echo "*** Building and testing $scheme..."
|
||||
echo
|
||||
|
||||
local sdkflag=
|
||||
local action=test
|
||||
|
||||
# Determine whether we can run unit tests for this target.
|
||||
run_xctool -scheme "$scheme" run-tests | parse_build
|
||||
|
||||
local awkstatus=$?
|
||||
|
||||
if [ "$awkstatus" -eq "1" ]
|
||||
then
|
||||
# SDK not found, try for iphonesimulator.
|
||||
sdkflag="-sdk iphonesimulator"
|
||||
|
||||
# Determine whether the unit tests will run with iphonesimulator
|
||||
run_xctool $sdkflag -scheme "$scheme" run-tests | parse_build
|
||||
|
||||
awkstatus=$?
|
||||
|
||||
if [ "$awkstatus" -ne "0" ]
|
||||
then
|
||||
# Unit tests will not run on iphonesimulator.
|
||||
sdkflag=""
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$awkstatus" -ne "0" ]
|
||||
then
|
||||
# Unit tests aren't supported.
|
||||
action=build
|
||||
fi
|
||||
|
||||
run_xctool $sdkflag -scheme "$scheme" $action
|
||||
}
|
||||
|
||||
export -f build_scheme
|
||||
export -f run_xctool
|
||||
export -f parse_build
|
||||
|
||||
main
|
||||
xcodebuild -workspace "$XCWORKSPACE" \
|
||||
-scheme "$SCHEME" \
|
||||
-destination "id=$DESTINATION_ID" \
|
||||
-sdk iphonesimulator \
|
||||
"${XCODE_OPTIONS[*]}" \
|
||||
build test \
|
||||
2>&1 | xcpretty $XCPRETTY_FORMAT_OPTIONS
|
||||
fi
|
||||
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash -ex
|
||||
|
||||
#
|
||||
# clean_externals
|
||||
# SwiftGit2
|
||||
#
|
||||
# Removes the outputs from the various static library targets.
|
||||
# Necessary when switching platforms/architectures as Xcode does not clean
|
||||
# these for you.
|
||||
#
|
||||
|
||||
# A list of external static libraries included in the SwiftGit2 framework
|
||||
libraries=(
|
||||
External/libgit2.a
|
||||
External/libgit2-ios/libgit2-ios.a
|
||||
External/libssh2-ios/lib/libssh2-ios.a
|
||||
External/ios-openssl/lib/libssl.a
|
||||
External/ios-openssl/lib/libcrypto.a
|
||||
External/ios-openssl/include
|
||||
)
|
||||
|
||||
rm -vrf "${libraries[@]}"
|
||||
@@ -9,7 +9,7 @@ function setup_build_environment ()
|
||||
# e.g. via brew. Xcode's Run Script phase doesn't seem to honor
|
||||
# ~/.MacOSX/environment.plist
|
||||
PATH="/usr/local/bin:/opt/boxen/homebrew/bin:$PATH"
|
||||
|
||||
|
||||
pushd "$SCRIPT_DIR/.." > /dev/null
|
||||
ROOT_PATH="$PWD"
|
||||
popd > /dev/null
|
||||
@@ -22,7 +22,7 @@ function setup_build_environment ()
|
||||
MACOSX_DEPLOYMENT_TARGET=""
|
||||
|
||||
XCODE_MAJOR_VERSION=$(xcode_major_version)
|
||||
|
||||
|
||||
CAN_BUILD_64BIT="0"
|
||||
|
||||
# If IPHONEOS_DEPLOYMENT_TARGET has not been specified
|
||||
@@ -32,7 +32,7 @@ function setup_build_environment ()
|
||||
then
|
||||
IPHONEOS_DEPLOYMENT_TARGET="6.0"
|
||||
fi
|
||||
|
||||
|
||||
# Determine if we can be building 64-bit binaries
|
||||
if [ "${XCODE_MAJOR_VERSION}" -ge "5" ] && [ $(echo ${IPHONEOS_DEPLOYMENT_TARGET} '>=' 6.0 | bc -l) == "1" ]
|
||||
then
|
||||
@@ -51,7 +51,7 @@ function setup_build_environment ()
|
||||
function build_all_archs ()
|
||||
{
|
||||
setup_build_environment
|
||||
|
||||
|
||||
local setup=$1
|
||||
local build_arch=$2
|
||||
local finish_build=$3
|
||||
@@ -80,8 +80,8 @@ function build_all_archs ()
|
||||
fi
|
||||
|
||||
SDKNAME="${PLATFORM}${SDKVERSION}"
|
||||
SDKROOT="$(ios_sdk_path ${SDKNAME})"
|
||||
|
||||
SDKROOT="$(sdk_path ${SDKNAME})"
|
||||
|
||||
echo "Building ${LIBRARY_NAME} for ${SDKNAME} ${ARCH}"
|
||||
echo "Please stand by..."
|
||||
|
||||
@@ -92,4 +92,3 @@ function build_all_archs ()
|
||||
# finish the build (usually lipo)
|
||||
eval $finish_build
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
BEGIN {
|
||||
FS = "\n";
|
||||
}
|
||||
|
||||
/Schemes:/ {
|
||||
while (getline && $0 != "") {
|
||||
sub(/^ +/, "");
|
||||
print "'" $0 "'";
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
BEGIN {
|
||||
FS = "\n";
|
||||
}
|
||||
|
||||
/Targets:/ {
|
||||
while (getline && $0 != "") {
|
||||
if ($0 ~ /Tests/) continue;
|
||||
|
||||
sub(/^ +/, "");
|
||||
print "'" $0 "'";
|
||||
}
|
||||
}
|
||||
+127
-18
@@ -5,30 +5,139 @@ set -e
|
||||
# augment path to help it find cmake installed in /usr/local/bin,
|
||||
# e.g. via brew. Xcode's Run Script phase doesn't seem to honor
|
||||
# ~/.MacOSX/environment.plist
|
||||
PATH="/usr/local/bin:$PATH"
|
||||
|
||||
if [ "External/libgit2.a" -nt "External/libgit2" ]
|
||||
then
|
||||
echo "No update needed."
|
||||
exit 0
|
||||
if [[ `uname -m` == 'arm64' ]]; then
|
||||
echo "** Running on a Apple Silicon M1"
|
||||
PATH="/opt/homebrew/bin:$PATH"
|
||||
else
|
||||
echo "** Running on a Apple x86"
|
||||
PATH="/usr/local/bin:$PATH"
|
||||
fi
|
||||
|
||||
cd "External/libgit2"
|
||||
SCRIPT_DIR=$(dirname "$0")
|
||||
source "${SCRIPT_DIR}/xcode_functions.sh"
|
||||
|
||||
if [ -d "build" ]; then
|
||||
function setup_build_environment ()
|
||||
{
|
||||
pushd "$SCRIPT_DIR/.." > /dev/null
|
||||
ROOT_PATH="$PWD"
|
||||
popd > /dev/null
|
||||
|
||||
CLANG="/usr/bin/xcrun clang"
|
||||
CC="${CLANG}"
|
||||
CPP="${CLANG} -E"
|
||||
|
||||
# We need to clear this so that cmake doesn't have a conniption
|
||||
MACOSX_DEPLOYMENT_TARGET=""
|
||||
|
||||
XCODE_MAJOR_VERSION=$(xcode_major_version)
|
||||
XCODE_MINOR_VERSION=$(xcode_minor_version)
|
||||
|
||||
CAN_BUILD_ARM="0"
|
||||
|
||||
# Determine if we can be building for ARM Macs
|
||||
if [ "${XCODE_MAJOR_VERSION}" -ge "13" ]
|
||||
then
|
||||
CAN_BUILD_ARM="1"
|
||||
elif [ "${XCODE_MAJOR_VERSION}" -eq "12" ] && [ "${XCODE_MINOR_VERSION}" -ge "2" ]
|
||||
then
|
||||
CAN_BUILD_ARM="1"
|
||||
fi
|
||||
|
||||
ARCHS="x86_64"
|
||||
if [ "${CAN_BUILD_ARM}" -eq "1" ]
|
||||
then
|
||||
ARCHS="${ARCHS} arm64 arm64e"
|
||||
fi
|
||||
}
|
||||
|
||||
function build_all_archs ()
|
||||
{
|
||||
setup_build_environment
|
||||
|
||||
local setup=$1
|
||||
local build_arch=$2
|
||||
local finish_build=$3
|
||||
|
||||
# run the prepare function
|
||||
eval $setup
|
||||
|
||||
echo "Building for ${ARCHS}"
|
||||
|
||||
for ARCH in ${ARCHS}
|
||||
do
|
||||
PLATFORM="macosx"
|
||||
SDKVERSION=$(macos_sdk_version)
|
||||
|
||||
SDKNAME="${PLATFORM}${SDKVERSION}"
|
||||
SDKROOT="$(sdk_path ${SDKNAME})"
|
||||
|
||||
echo "Building ${LIBRARY_NAME} for ${SDKNAME} ${ARCH}"
|
||||
echo "Please stand by..."
|
||||
|
||||
# run the per arch build command
|
||||
eval $build_arch
|
||||
done
|
||||
|
||||
# finish the build (usually lipo)
|
||||
eval $finish_build
|
||||
}
|
||||
|
||||
function setup ()
|
||||
{
|
||||
if [ "${ROOT_PATH}/External/libgit2-mac/libgit2-mac.a" -nt "${ROOT_PATH}/External/libgit2" ]
|
||||
then
|
||||
echo "No update needed."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
LIBRARY_NAME="libgit2"
|
||||
LIB_PATH="${ROOT_PATH}/External/libgit2-mac"
|
||||
rm -rf "${LIB_PATH}"
|
||||
|
||||
pushd "${ROOT_PATH}/External/libgit2" > /dev/null
|
||||
}
|
||||
|
||||
function build_libgit2 ()
|
||||
{
|
||||
rm -rf "build"
|
||||
fi
|
||||
mkdir "build"
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
pushd "build" > /dev/null
|
||||
|
||||
cmake -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_CLAR:BOOL=OFF -DTHREADSAFE:BOOL=ON ..
|
||||
cmake --build .
|
||||
# install the each built arch somewhere sane
|
||||
INSTALL_PREFIX="${LIB_PATH}/${SDKNAME}-${ARCH}.sdk"
|
||||
|
||||
product="libgit2.a"
|
||||
install_path="../../${product}"
|
||||
if [ "${product}" -nt "${install_path}" ]; then
|
||||
cp -v "${product}" "${install_path}"
|
||||
fi
|
||||
mkdir -p "${INSTALL_PREFIX}"
|
||||
|
||||
LOG="${INSTALL_PREFIX}/build-libgit2.log"
|
||||
echo "$LOG"
|
||||
|
||||
MACOSX_DEPLOYMENT_TARGET="10.9" cmake \
|
||||
-DBUILD_SHARED_LIBS:BOOL=OFF \
|
||||
-DCMAKE_PREFIX_PATH:PATH="${ROOT_PATH}/External/libssh2-mac/bin/${SDKNAME}-${ARCH}.sdk" \
|
||||
-DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PREFIX}/" \
|
||||
-DBUILD_CLAR:BOOL=OFF \
|
||||
-DTHREADSAFE:BOOL=ON \
|
||||
-DCMAKE_OSX_ARCHITECTURES:STRING="${ARCH}" \
|
||||
.. >> "${LOG}" 2>&1
|
||||
cmake --build . --target install >> "${LOG}" 2>&1
|
||||
|
||||
# push the built library into the list
|
||||
BUILT_LIB_PATHS+=("${INSTALL_PREFIX}/lib/libgit2.a")
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
function fat_binary ()
|
||||
{
|
||||
echo "Building fat binary..."
|
||||
|
||||
lipo -create "${BUILT_LIB_PATHS[@]}" -output "${ROOT_PATH}/External/libgit2-mac/libgit2-mac.a"
|
||||
|
||||
echo "Building done."
|
||||
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
build_all_archs setup build_libgit2 fat_binary
|
||||
|
||||
echo "libgit2 has been updated."
|
||||
|
||||
@@ -42,18 +42,16 @@ function build_libgit2 ()
|
||||
LOG="${INSTALL_PREFIX}/build-libgit2.log"
|
||||
echo "$LOG"
|
||||
|
||||
cmake -DCMAKE_C_COMPILER=clang \
|
||||
cmake \
|
||||
-DCMAKE_C_COMPILER_WORKS:BOOL=ON \
|
||||
-DBUILD_SHARED_LIBS:BOOL=OFF \
|
||||
-DOPENSSL_INCLUDE_DIR:PATH=../../External/ios-openssl/include/ \
|
||||
-DCMAKE_LIBRARY_PATH:PATH=../../External/libssh2-ios/lib/ \
|
||||
-DCMAKE_INCLUDE_PATH:PATH=../../External/libssh2-ios/include/libssh2/ \
|
||||
-DOPENSSL_SSL_LIBRARY:FILEPATH=../../External/ios-openssl/lib/libssl.a \
|
||||
-DCMAKE_LIBRARY_PATH:PATH="${SDKROOT}/usr/lib/" \
|
||||
-DOPENSSL_CRYPTO_LIBRARY:FILEPATH=../../External/ios-openssl/lib/libcrypto.a \
|
||||
-DCMAKE_PREFIX_PATH:PATH="${ROOT_PATH}/External/libssh2-ios/bin/${SDKNAME}-${ARCH}.sdk" \
|
||||
-DPKG_CONFIG_USE_CMAKE_PREFIX_PATH:BOOL=ON \
|
||||
-DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PREFIX}/" \
|
||||
-DBUILD_CLAR:BOOL=OFF \
|
||||
-DTHREADSAFE:BOOL=ON \
|
||||
-DCURL:BOOL=OFF \
|
||||
-DCMAKE_C_FLAGS:STRING="-fembed-bitcode" \
|
||||
"${SYS_ROOT}" \
|
||||
-DCMAKE_OSX_ARCHITECTURES:STRING="${ARCH}" \
|
||||
.. >> "${LOG}" 2>&1
|
||||
|
||||
@@ -24,8 +24,8 @@ function build_ssh2 ()
|
||||
cp -R "${ROOT_PATH}/External/libssh2" "${ROOT_PATH}/External/libssh2-ios/src/"
|
||||
pushd "${ROOT_PATH}/External/libssh2-ios/src/libssh2" > /dev/null
|
||||
|
||||
export CFLAGS="-arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${SDKROOT} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET}"
|
||||
export CPPFLAGS="-arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${SDKROOT} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET}"
|
||||
export CFLAGS="-arch ${ARCH} -fembed-bitcode -pipe -no-cpp-precomp -isysroot ${SDKROOT} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET}"
|
||||
export CPPFLAGS="-arch ${ARCH} -fembed-bitcode -pipe -no-cpp-precomp -isysroot ${SDKROOT} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET}"
|
||||
|
||||
mkdir -p "${ROOT_PATH}/External/libssh2-ios/bin/${SDKNAME}-${ARCH}.sdk"
|
||||
LOG="${ROOT_PATH}/External/libssh2-ios/bin/${SDKNAME}-${ARCH}.sdk/build-libssh2.log"
|
||||
|
||||
@@ -43,7 +43,7 @@ function build_ssl ()
|
||||
echo "$LOG"
|
||||
|
||||
./Configure ${HOST} ${CONFIG} --openssldir="/tmp/openssl-${ARCH}" >> "${LOG}" 2>&1
|
||||
perl -i -pe "s|^CC= gcc|CC= ${CLANG} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET} -arch ${ARCH} |g" Makefile >> "${LOG}" 2>&1
|
||||
perl -i -pe "s|^CC= gcc|CC= ${CLANG} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET} -arch ${ARCH} -fembed-bitcode |g" Makefile >> "${LOG}" 2>&1
|
||||
perl -i -pe "s|^CFLAG= (.*)|CFLAG= -isysroot ${SDKROOT} \$1|g" Makefile >> "${LOG}" 2>&1
|
||||
make >> "${LOG}" 2>&1
|
||||
|
||||
|
||||
@@ -14,17 +14,39 @@ function xcode_major_version ()
|
||||
xcode_version | awk -F '.' '{ print $1 }'
|
||||
}
|
||||
|
||||
# Returns the latest iOS SDK version available
|
||||
# via xcodebuild
|
||||
function xcode_minor_version ()
|
||||
{
|
||||
xcode_version | awk -F '.' '{ print $2 }'
|
||||
}
|
||||
|
||||
# Returns the latest iOS SDK version available via xcodebuild.
|
||||
function ios_sdk_version ()
|
||||
{
|
||||
# This relies on the fact that the latest iPhone SDK
|
||||
# is the last thing listed before the Xcode version.
|
||||
/usr/bin/xcodebuild -version -sdk 2> /dev/null | grep SDKVersion | tail -n 1 | awk '{ print $2 }'
|
||||
# The grep command produces output like the following, singling out the
|
||||
# SDKVersion of just the iPhone* SDKs:
|
||||
#
|
||||
# iPhoneOS9.0.sdk - iOS 9.0 (iphoneos9.0)
|
||||
# SDKVersion: 9.0
|
||||
# --
|
||||
# iPhoneSimulator9.0.sdk - Simulator - iOS 9.0 (iphonesimulator9.0)
|
||||
# SDKVersion: 9.0
|
||||
|
||||
/usr/bin/xcodebuild -version -sdk 2> /dev/null | grep -A 1 '^iPhone' | tail -n 1 | awk '{ print $2 }'
|
||||
}
|
||||
|
||||
function macos_sdk_version ()
|
||||
{
|
||||
# The grep command produces output like the following, singling out the
|
||||
# SDKVersion of just the Mac SDKs:
|
||||
#
|
||||
# MacOSX11.0.sdk - macOS 11.0 (macosx11.0)
|
||||
# SDKVersion: 11.0
|
||||
# ...
|
||||
/usr/bin/xcodebuild -version -sdk 2> /dev/null | grep -A 1 '^MacOSX' | tail -n 1 | awk '{ print $2 }'
|
||||
}
|
||||
|
||||
# Returns the path to the specified iOS SDK name
|
||||
function ios_sdk_path ()
|
||||
function sdk_path ()
|
||||
{
|
||||
/usr/bin/xcodebuild -version -sdk 2> /dev/null | grep -i $1 | grep 'Path:' | awk '{ print $2 }'
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
# Exit statuses:
|
||||
#
|
||||
# 0 - No errors found.
|
||||
# 1 - Build or test failure. Errors will be logged automatically.
|
||||
# 2 - Untestable target. Retry with the "build" action.
|
||||
|
||||
BEGIN {
|
||||
status = 0;
|
||||
}
|
||||
|
||||
{
|
||||
print;
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/is not valid for Testing/ {
|
||||
exit 2;
|
||||
}
|
||||
|
||||
/[0-9]+: (error|warning):/ {
|
||||
errors = errors $0 "\n";
|
||||
}
|
||||
|
||||
/(TEST|BUILD) FAILED/ {
|
||||
status = 1;
|
||||
}
|
||||
|
||||
END {
|
||||
if (length(errors) > 0) {
|
||||
print "\n*** All errors:\n" errors;
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
exit status;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
# Exit statuses:
|
||||
#
|
||||
# 0 - No errors found.
|
||||
# 1 - Wrong SDK. Retry with SDK `iphonesimulator`.
|
||||
# 2 - Missing target.
|
||||
|
||||
BEGIN {
|
||||
status = 0;
|
||||
}
|
||||
|
||||
{
|
||||
print;
|
||||
}
|
||||
|
||||
/Testing with the '(.+)' SDK is not yet supported/ {
|
||||
status = 1;
|
||||
}
|
||||
|
||||
/does not contain a target named/ {
|
||||
status = 2;
|
||||
}
|
||||
|
||||
END {
|
||||
exit status;
|
||||
}
|
||||
Reference in New Issue
Block a user