Skip to content

Commit

Permalink
Add checkout options support to stash API.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiennou committed Sep 8, 2015
1 parent cc41976 commit d4583ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions ObjectiveGit/GTRepository+Stashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,23 @@ NS_ASSUME_NONNULL_BEGIN
///
/// index - The index of the stash to apply. 0 is the latest one.
/// flags - The flags to use when applying the stash.
/// options - The options to use when checking out.
/// error - If not NULL, set to any error that occurred.
/// progressBlock - A block that will be executed on each step of the stash application.
///
/// Returns YES if the requested stash was successfully applied, NO otherwise.
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock;
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags checkoutOptions:(nullable GTCheckoutOptions *)options error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock;

/// Pop stashed changes.
///
/// index - The index of the stash to apply. 0 is the most recent stash.
/// flags - The flags to use when applying the stash.
/// options - The options to use when checking out.
/// error - If not NULL, set to any error that occurred.
/// progressBlock - A block that will be executed on each step of the stash application.
///
/// Returns YES if the requested stash was successfully applied, NO otherwise.
- (BOOL)popStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock;
- (BOOL)popStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags checkoutOptions:(nullable GTCheckoutOptions *)options error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock;

/// Drop a stash from the repository's list of stashes.
///
Expand Down
14 changes: 9 additions & 5 deletions ObjectiveGit/GTRepository+Stashing.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int stashApplyProgressCallback(git_stash_apply_progress_t progress, void
return (stop ? GIT_EUSER : 0);
}

- (BOOL)applyStashAtIndex:(NSUInteger)index popStash:(BOOL)pop flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress, BOOL * __nonnull))progressBlock {
- (BOOL)applyStashAtIndex:(NSUInteger)index popStash:(BOOL)pop flags:(GTRepositoryStashApplyFlag)flags checkoutOptions:(nullable GTCheckoutOptions *)options error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress, BOOL * __nonnull))progressBlock {
git_stash_apply_options stash_options = GIT_STASH_APPLY_OPTIONS_INIT;

stash_options.flags = (git_stash_apply_flags)flags;
Expand All @@ -68,6 +68,10 @@ - (BOOL)applyStashAtIndex:(NSUInteger)index popStash:(BOOL)pop flags:(GTReposito
stash_options.progress_payload = (__bridge void *)progressBlock;
}

if (options != nil) {
stash_options.checkout_options = *options.git_checkoutOptions;
}

if (pop == NO) {
int gitError = git_stash_apply(self.git_repository, index, &stash_options);
if (gitError != GIT_OK) {
Expand All @@ -84,12 +88,12 @@ - (BOOL)applyStashAtIndex:(NSUInteger)index popStash:(BOOL)pop flags:(GTReposito
return YES;
}

- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
return [self applyStashAtIndex:index popStash:NO flags:flags error:error progressBlock:progressBlock];
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags checkoutOptions:(nullable GTCheckoutOptions *)options error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
return [self applyStashAtIndex:index popStash:NO flags:flags checkoutOptions:options error:error progressBlock:progressBlock];
}

- (BOOL)popStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
return [self applyStashAtIndex:index popStash:YES flags:flags error:error progressBlock:progressBlock];
- (BOOL)popStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags checkoutOptions:(nullable GTCheckoutOptions *)options error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
return [self applyStashAtIndex:index popStash:YES flags:flags checkoutOptions:options error:error progressBlock:progressBlock];
}

- (BOOL)dropStashAtIndex:(NSUInteger)index error:(NSError **)error {
Expand Down

0 comments on commit d4583ba

Please sign in to comment.