Skip to content

Commit dae0b10

Browse files
committed
Merge branch 'master' into pull
# Conflicts: # ObjectiveGitFramework.xcodeproj/project.pbxproj
2 parents 4feb8c6 + 6e5a9d9 commit dae0b10

27 files changed

+867
-125
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616
[submodule "Carthage/Checkouts/xcconfigs"]
1717
path = Carthage/Checkouts/xcconfigs
1818
url = https://github.com/jspahrsummers/xcconfigs.git
19+
[submodule "Carthage/Checkouts/ZipArchive"]
20+
path = Carthage/Checkouts/ZipArchive
21+
url = https://github.com/ZipArchive/ZipArchive.git

Cartfile.private

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
github "jspahrsummers/xcconfigs" >= 0.7.1
22
github "Quick/Quick" ~> 0.3
33
github "Quick/Nimble" ~> 0.4
4+
github "ZipArchive/ZipArchive" ~> 0.3

Cartfile.resolved

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
github "Quick/Nimble" "v0.4.2"
22
github "Quick/Quick" "v0.3.1"
3+
github "ZipArchive/ZipArchive" "v0.3.2"
34
github "jspahrsummers/xcconfigs" "0.7.2"

Carthage/Checkouts/ZipArchive

Submodule ZipArchive added at 60312c1

ObjectiveGit/GTBranch.h

-3
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ NS_ASSUME_NONNULL_BEGIN
132132
/// Returns whether the calculation was successful.
133133
- (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind relativeTo:(GTBranch *)branch error:(NSError **)error;
134134

135-
#pragma mark Deprecations
136-
- (nullable GTCommit *)targetCommitAndReturnError:(NSError **)error __deprecated_msg("use targetCommitWithError: instead.");
137-
138135
@end
139136

140137
NS_ASSUME_NONNULL_END

ObjectiveGit/GTBranch.m

-5
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,4 @@ - (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind relativeTo:(GTBra
223223
return [self.repository calculateAhead:ahead behind:behind ofOID:self.OID relativeToOID:branch.OID error:error];
224224
}
225225

226-
#pragma mark Deprecations
227-
- (GTCommit *)targetCommitAndReturnError:(NSError **)error {
228-
return [self targetCommitWithError:error];
229-
}
230-
231226
@end

ObjectiveGit/GTCredential.h

+12
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ NS_ASSUME_NONNULL_BEGIN
7474
/// Return a new GTCredential instance, or nil if an error occurred
7575
+ (nullable instancetype)credentialWithUserName:(NSString *)userName publicKeyURL:(nullable NSURL *)publicKeyURL privateKeyURL:(NSURL *)privateKeyURL passphrase:(nullable NSString *)passphrase error:(NSError **)error;
7676

77+
/// Create a credential object from a SSH keyfile data string
78+
///
79+
/// userName - The username to authenticate as.
80+
/// publicKeyString - The string containing the public key for that user.
81+
/// Can be omitted to reconstruct the public key from the private key.
82+
/// privateKeyString - The URL to the private key for that user.
83+
/// passphrase - The passPhrase for the private key. Optional if the private key has no password.
84+
/// error - If not NULL, set to any errors that occur.
85+
///
86+
/// Return a new GTCredential instance, or nil if an error occurred
87+
+ (nullable instancetype)credentialWithUserName:(NSString *)userName publicKeyString:(nullable NSString *)publicKeyString privateKeyString:(NSString *)privateKeyString passphrase:(nullable NSString *)passphrase error:(NSError **)error;
88+
7789
/// The underlying `git_cred` object.
7890
- (git_cred *)git_cred __attribute__((objc_returns_inner_pointer));
7991

ObjectiveGit/GTCredential.m

+13
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ + (instancetype)credentialWithUserName:(NSString *)userName publicKeyURL:(NSURL
7171
return [[self alloc] initWithGitCred:cred];
7272
}
7373

74+
+ (instancetype)credentialWithUserName:(NSString *)userName publicKeyString:(NSString *)publicKeyString privateKeyString:(NSString *)privateKeyString passphrase:(NSString *)passphrase error:(NSError **)error {
75+
NSParameterAssert(privateKeyString != nil);
76+
77+
git_cred *cred;
78+
int gitError = git_cred_ssh_key_memory_new(&cred, userName.UTF8String, publicKeyString.UTF8String, privateKeyString.UTF8String, passphrase.UTF8String);
79+
if (gitError != GIT_OK) {
80+
if (error) *error = [NSError git_errorFor:gitError description:@"Failed to create credentials object" failureReason:@"There was an error creating a credential object for username %@ with the provided public/private key pair.\nPublic key: %@\nPrivate key: %@", userName, publicKeyString, privateKeyString];
81+
return nil;
82+
}
83+
84+
return [[self alloc] initWithGitCred:cred];
85+
}
86+
7487
- (instancetype)initWithGitCred:(git_cred *)cred {
7588
NSParameterAssert(cred != nil);
7689
self = [self init];

ObjectiveGit/GTRepository+RemoteOperations.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ - (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions
219219

220220
git_remote_callbacks remote_callbacks = GIT_REMOTE_CALLBACKS_INIT;
221221
remote_callbacks.credentials = (credProvider != nil ? GTCredentialAcquireCallback : NULL),
222-
remote_callbacks.transfer_progress = GTRemoteFetchTransferProgressCallback,
222+
remote_callbacks.push_transfer_progress = GTRemotePushTransferProgressCallback;
223223
remote_callbacks.payload = &connectionInfo,
224224

225225
gitError = git_remote_connect(remote.git_remote, GIT_DIRECTION_PUSH, &remote_callbacks);
@@ -239,6 +239,8 @@ - (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions
239239
return NO;
240240
}
241241

242+
push_options.callbacks = remote_callbacks;
243+
242244
const git_strarray git_refspecs = refspecs.git_strarray;
243245

244246
gitError = git_remote_upload(remote.git_remote, &git_refspecs, &push_options);

ObjectiveGit/GTRepository+Stashing.h

+39
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@ typedef NS_OPTIONS(NSInteger, GTRepositoryStashFlag) {
1919
GTRepositoryStashFlagIncludeIgnored = GIT_STASH_INCLUDE_IGNORED
2020
};
2121

22+
/// Flags for -applyStashAtIndex:flags:error: and
23+
/// -popStashAtIndex:flags:error.
24+
/// Those can be ORed together. See git_stash_apply_flags for additional information.
25+
typedef NS_OPTIONS(NSInteger, GTRepositoryStashApplyFlag) {
26+
GTRepositoryStashApplyFlagDefault = GIT_STASH_APPLY_DEFAULT,
27+
GTRepositoryStashApplyFlagReinstateIndex = GIT_STASH_APPLY_REINSTATE_INDEX,
28+
};
29+
30+
/// Enum representing the current state of a stash apply/pop operation.
31+
/// See git_stash_apply_progress_t for additional information.
32+
typedef NS_ENUM(NSInteger, GTRepositoryStashApplyProgress) {
33+
GTRepositoryStashApplyProgressNone = GIT_STASH_APPLY_PROGRESS_NONE,
34+
GTRepositoryStashApplyProgressLoadingStash = GIT_STASH_APPLY_PROGRESS_LOADING_STASH,
35+
GTRepositoryStashApplyProgressAnalyzeIndex = GIT_STASH_APPLY_PROGRESS_ANALYZE_INDEX,
36+
GTRepositoryStashApplyProgressAnalyzeModified = GIT_STASH_APPLY_PROGRESS_ANALYZE_MODIFIED,
37+
GTRepositoryStashApplyProgressAnalyzeUntracked = GIT_STASH_APPLY_PROGRESS_ANALYZE_UNTRACKED,
38+
GTRepositoryStashApplyProgressGheckoutUntracked = GIT_STASH_APPLY_PROGRESS_CHECKOUT_UNTRACKED,
39+
GTRepositoryStashApplyProgressCheckoutModified = GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED,
40+
GTRepositoryStashApplyProgressDone = GIT_STASH_APPLY_PROGRESS_DONE,
41+
};
42+
2243
NS_ASSUME_NONNULL_BEGIN
2344

2445
@interface GTRepository (Stashing)
@@ -41,6 +62,24 @@ NS_ASSUME_NONNULL_BEGIN
4162
/// will cause enumeration to stop after the block returns. Must not be nil.
4263
- (void)enumerateStashesUsingBlock:(void (^)(NSUInteger index, NSString * __nullable message, GTOID * __nullable oid, BOOL *stop))block;
4364

65+
/// Apply stashed changes.
66+
///
67+
/// index - The index of the stash to apply. 0 is the latest one.
68+
/// flags - The flags to use when applying the stash.
69+
/// error - If not NULL, set to any error that occurred.
70+
///
71+
/// Returns YES if the requested stash was successfully applied, NO otherwise.
72+
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock;
73+
74+
/// Pop stashed changes.
75+
///
76+
/// index - The index of the stash to apply. 0 is the most recent stash.
77+
/// flags - The flags to use when applying the stash.
78+
/// error - If not NULL, set to any error that occurred.
79+
///
80+
/// Returns YES if the requested stash was successfully applied, NO otherwise.
81+
- (BOOL)popStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock;
82+
4483
/// Drop a stash from the repository's list of stashes.
4584
///
4685
/// index - The index of the stash to drop, where 0 is the most recent stash.

ObjectiveGit/GTRepository+Stashing.m

+44-1
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,53 @@ - (void)enumerateStashesUsingBlock:(GTRepositoryStashEnumerationBlock)block {
5050
git_stash_foreach(self.git_repository, &stashEnumerationCallback, (__bridge void *)block);
5151
}
5252

53+
static int stashApplyProgressCallback(git_stash_apply_progress_t progress, void *payload) {
54+
void (^block)(GTRepositoryStashApplyProgress, BOOL *) = (__bridge id)payload;
55+
56+
BOOL stop = NO;
57+
block((GTRepositoryStashApplyProgress)progress, &stop);
58+
59+
return (stop ? GIT_EUSER : 0);
60+
}
61+
62+
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
63+
git_stash_apply_options stash_options = GIT_STASH_APPLY_OPTIONS_INIT;
64+
65+
stash_options.flags = (git_stash_apply_flags)flags;
66+
if (progressBlock != nil) {
67+
stash_options.progress_cb = stashApplyProgressCallback;
68+
stash_options.progress_payload = (__bridge void *)progressBlock;
69+
}
70+
71+
int gitError = git_stash_apply(self.git_repository, index, &stash_options);
72+
if (gitError != GIT_OK) {
73+
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Stash apply failed" failureReason:@"The stash at index %ld couldn't be applied.", (unsigned long)index];
74+
return NO;
75+
}
76+
return YES;
77+
}
78+
79+
- (BOOL)popStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
80+
git_stash_apply_options stash_options = GIT_STASH_APPLY_OPTIONS_INIT;
81+
82+
stash_options.flags = (git_stash_apply_flags)flags;
83+
if (progressBlock != nil) {
84+
stash_options.progress_cb = stashApplyProgressCallback;
85+
stash_options.progress_payload = (__bridge void *)progressBlock;
86+
}
87+
88+
int gitError = git_stash_pop(self.git_repository, index, &stash_options);
89+
if (gitError != GIT_OK) {
90+
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Stash pop failed" failureReason:@"The stash at index %ld couldn't be applied.", (unsigned long)index];
91+
return NO;
92+
}
93+
return YES;
94+
}
95+
5396
- (BOOL)dropStashAtIndex:(NSUInteger)index error:(NSError **)error {
5497
int gitError = git_stash_drop(self.git_repository, index);
5598
if (gitError != GIT_OK) {
56-
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to drop stash."];
99+
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Stash drop failed" failureReason:@"The stash at index %ld couldn't be dropped", (unsigned long)index];
57100
return NO;
58101
}
59102

ObjectiveGit/GTRepository+Status.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ - (BOOL)isWorkingDirectoryClean {
7878
}
7979

8080
// any untracked files?
81-
if (indexToWorkDirStatus == GTStatusDeltaStatusAdded) {
81+
if (indexToWorkDirStatus == GTStatusDeltaStatusUntracked) {
8282
clean = NO;
8383
*stop = YES;
8484
}

ObjectiveGit/GTRepository.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ extern NSString * const GTRepositoryInitOptionsOriginURLString;
228228
/// May be NULL.
229229
///
230230
/// returns nil (and fills the error parameter) if an error occurred, or a GTRepository object if successful.
231-
+ (nullable instancetype)cloneFromURL:(NSURL *)originURL toWorkingDirectory:(NSURL *)workdirURL options:(nullable NSDictionary *)options error:(NSError **)error transferProgressBlock:(nullable void (^)(const git_transfer_progress *, BOOL *stop))transferProgressBlock checkoutProgressBlock:(nullable void (^) (NSString *path, NSUInteger completedSteps, NSUInteger totalSteps))checkoutProgressBlock;
231+
+ (nullable instancetype)cloneFromURL:(NSURL *)originURL toWorkingDirectory:(NSURL *)workdirURL options:(nullable NSDictionary *)options error:(NSError **)error transferProgressBlock:(nullable void (^)(const git_transfer_progress *, BOOL *stop))transferProgressBlock checkoutProgressBlock:(nullable void (^) (NSString *__nullable path, NSUInteger completedSteps, NSUInteger totalSteps))checkoutProgressBlock;
232232

233233
/// Lookup objects in the repo by oid or sha1
234234
- (nullable id)lookUpObjectByOID:(GTOID *)oid objectType:(GTObjectType)type error:(NSError **)error;

ObjectiveGit/GTRepository.m

+10-9
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static int remoteCreate(git_remote **remote, git_repository *repo, const char *n
226226
return GIT_OK;
227227
}
228228

229-
+ (instancetype)cloneFromURL:(NSURL *)originURL toWorkingDirectory:(NSURL *)workdirURL options:(NSDictionary *)options error:(NSError **)error transferProgressBlock:(void (^)(const git_transfer_progress *, BOOL *stop))transferProgressBlock checkoutProgressBlock:(void (^)(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps))checkoutProgressBlock {
229+
+ (instancetype)cloneFromURL:(NSURL *)originURL toWorkingDirectory:(NSURL *)workdirURL options:(NSDictionary *)options error:(NSError **)error transferProgressBlock:(void (^)(const git_transfer_progress *, BOOL *stop))transferProgressBlock checkoutProgressBlock:(void (^)(NSString *__nullable path, NSUInteger completedSteps, NSUInteger totalSteps))checkoutProgressBlock {
230230

231231
git_clone_options cloneOptions = GIT_CLONE_OPTIONS_INIT;
232232

@@ -816,7 +816,7 @@ - (BOOL)moveHEADToCommit:(GTCommit *)commit error:(NSError **)error {
816816
return gitError == GIT_OK;
817817
}
818818

819-
- (BOOL)performCheckoutWithStrategy:(GTCheckoutStrategyType)strategy notifyFlags:(GTCheckoutNotifyFlags)notifyFlags error:(NSError **)error progressBlock:(GTCheckoutProgressBlock)progressBlock notifyBlock:(GTCheckoutNotifyBlock)notifyBlock {
819+
- (BOOL)performCheckout:(GTObject *)target withStrategy:(GTCheckoutStrategyType)strategy notifyFlags:(GTCheckoutNotifyFlags)notifyFlags error:(NSError **)error progressBlock:(GTCheckoutProgressBlock)progressBlock notifyBlock:(GTCheckoutNotifyBlock)notifyBlock {
820820

821821
git_checkout_options checkoutOptions = GIT_CHECKOUT_OPTIONS_INIT;
822822

@@ -828,7 +828,7 @@ - (BOOL)performCheckoutWithStrategy:(GTCheckoutStrategyType)strategy notifyFlags
828828
checkoutOptions.notify_flags = notifyFlags;
829829
checkoutOptions.notify_payload = (__bridge void *)notifyBlock;
830830

831-
int gitError = git_checkout_head(self.git_repository, &checkoutOptions);
831+
int gitError = git_checkout_tree(self.git_repository, target.git_object, &checkoutOptions);
832832
if (gitError < GIT_OK) {
833833
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to checkout tree."];
834834
}
@@ -837,17 +837,18 @@ - (BOOL)performCheckoutWithStrategy:(GTCheckoutStrategyType)strategy notifyFlags
837837
}
838838

839839
- (BOOL)checkoutCommit:(GTCommit *)targetCommit strategy:(GTCheckoutStrategyType)strategy notifyFlags:(GTCheckoutNotifyFlags)notifyFlags error:(NSError **)error progressBlock:(GTCheckoutProgressBlock)progressBlock notifyBlock:(GTCheckoutNotifyBlock)notifyBlock {
840-
BOOL success = [self moveHEADToCommit:targetCommit error:error];
840+
BOOL success = [self performCheckout:targetCommit withStrategy:strategy notifyFlags:notifyFlags error:error progressBlock:progressBlock notifyBlock:notifyBlock];
841841
if (success == NO) return NO;
842-
843-
return [self performCheckoutWithStrategy:strategy notifyFlags:notifyFlags error:error progressBlock:progressBlock notifyBlock:notifyBlock];
842+
return [self moveHEADToCommit:targetCommit error:error];
844843
}
845844

846845
- (BOOL)checkoutReference:(GTReference *)targetReference strategy:(GTCheckoutStrategyType)strategy notifyFlags:(GTCheckoutNotifyFlags)notifyFlags error:(NSError **)error progressBlock:(GTCheckoutProgressBlock)progressBlock notifyBlock:(GTCheckoutNotifyBlock)notifyBlock {
847-
BOOL success = [self moveHEADToReference:targetReference error:error];
846+
GTOID *targetOID = [targetReference targetOID];
847+
GTObject *target = [self lookUpObjectByOID:targetOID error:error];
848+
if (target == nil) return NO;
849+
BOOL success = [self performCheckout:target withStrategy:strategy notifyFlags:notifyFlags error:error progressBlock:progressBlock notifyBlock:notifyBlock];
848850
if (success == NO) return NO;
849-
850-
return [self performCheckoutWithStrategy:strategy notifyFlags:notifyFlags error:error progressBlock:progressBlock notifyBlock:notifyBlock];
851+
return [self moveHEADToReference:targetReference error:error];
851852
}
852853

853854
- (BOOL)checkoutCommit:(GTCommit *)target strategy:(GTCheckoutStrategyType)strategy error:(NSError **)error progressBlock:(GTCheckoutProgressBlock)progressBlock {

0 commit comments

Comments
 (0)