Skip to content

Commit a98f83a

Browse files
committed
Ability to checkout from an index
1 parent 7a0e172 commit a98f83a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ObjectiveGit/GTRepository.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,15 @@ typedef NS_ENUM(NSInteger, GTRepositoryStateType) {
526526
/// Returns YES if operation was successful, NO otherwise
527527
- (BOOL)checkoutReference:(GTReference *)targetReference options:(nullable GTCheckoutOptions *)options error:(NSError **)error;
528528

529+
/// Checkout an index
530+
///
531+
/// index - The index to checkout. Must not be nil.
532+
/// options - The checkout options to use. Can be nil.
533+
/// error - The error if one occurred. Can be NULL.
534+
///
535+
/// Returns YES if operation was successful, NO otherwise
536+
- (BOOL)checkoutIndex:(GTIndex *)index options:(nullable GTCheckoutOptions *)options error:(NSError **)error;
537+
529538
/// Flush the gitattributes cache.
530539
- (void)flushAttributesCache;
531540

ObjectiveGit/GTRepository.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,15 @@ - (BOOL)checkoutReference:(GTReference *)targetReference options:(GTCheckoutOpti
831831
return [self moveHEADToReference:targetReference error:error];
832832
}
833833

834+
- (BOOL)checkoutIndex:(GTIndex *)index options:(GTCheckoutOptions *)options error:(NSError **)error {
835+
int gitError = git_checkout_index(self.git_repository, index.git_index, options.git_checkoutOptions);
836+
if (gitError < GIT_OK) {
837+
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to checkout index."];
838+
return NO;
839+
}
840+
return YES;
841+
}
842+
834843
- (void)flushAttributesCache {
835844
git_attr_cache_flush(self.git_repository);
836845
}

0 commit comments

Comments
 (0)