Skip to content

Commit

Permalink
Ability to checkout from an index
Browse files Browse the repository at this point in the history
  • Loading branch information
tiennou committed Aug 15, 2016
1 parent 381eca8 commit f048118
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ObjectiveGit/GTRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,15 @@ typedef NS_ENUM(NSInteger, GTRepositoryStateType) {
/// Returns YES if operation was successful, NO otherwise
- (BOOL)checkoutReference:(GTReference *)targetReference options:(nullable GTCheckoutOptions *)options error:(NSError **)error;

/// Checkout an index
///
/// index - The index to checkout. Must not be nil.
/// options - The checkout options to use. Can be nil.
/// error - The error if one occurred. Can be NULL.
///
/// Returns YES if operation was successful, NO otherwise
- (BOOL)checkoutIndex:(GTIndex *)index options:(nullable GTCheckoutOptions *)options error:(NSError **)error;

/// Flush the gitattributes cache.
- (void)flushAttributesCache;

Expand Down
9 changes: 9 additions & 0 deletions ObjectiveGit/GTRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,15 @@ - (BOOL)checkoutReference:(GTReference *)targetReference options:(GTCheckoutOpti
return [self moveHEADToReference:targetReference error:error];
}

- (BOOL)checkoutIndex:(GTIndex *)index options:(GTCheckoutOptions *)options error:(NSError **)error {
int gitError = git_checkout_index(self.git_repository, index.git_index, options.git_checkoutOptions);
if (gitError < GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to checkout index."];
return NO;
}
return YES;
}

- (void)flushAttributesCache {
git_attr_cache_flush(self.git_repository);
}
Expand Down

0 comments on commit f048118

Please sign in to comment.