Skip to content

Commit

Permalink
Make stash apply and pop separate again
Browse files Browse the repository at this point in the history
  • Loading branch information
tiennou committed Sep 10, 2015
1 parent a6ddb13 commit 460f397
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 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 checkoutOptions:(nullable GTCheckoutOptions *)options error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress, BOOL * __nonnull))progressBlock {
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags checkoutOptions:(GTCheckoutOptions *)options error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
git_stash_apply_options stash_options = GIT_STASH_APPLY_OPTIONS_INIT;

stash_options.flags = (git_stash_apply_flags)flags;
Expand All @@ -72,28 +72,33 @@ - (BOOL)applyStashAtIndex:(NSUInteger)index popStash:(BOOL)pop flags:(GTReposito
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) {
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];
return NO;
}
} else {
int gitError = git_stash_pop(self.git_repository, index, &stash_options);
if (gitError != GIT_OK) {
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];
return NO;
}
int gitError = git_stash_apply(self.git_repository, index, &stash_options);
if (gitError != GIT_OK) {
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];
return NO;
}
return YES;
}

- (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 checkoutOptions:(GTCheckoutOptions *)options error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock{
git_stash_apply_options stash_options = GIT_STASH_APPLY_OPTIONS_INIT;

stash_options.flags = (git_stash_apply_flags)flags;
if (progressBlock != nil) {
stash_options.progress_cb = stashApplyProgressCallback;
stash_options.progress_payload = (__bridge void *)progressBlock;
}

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

- (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];
int gitError = git_stash_pop(self.git_repository, index, &stash_options);
if (gitError != GIT_OK) {
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];
return NO;
}
return YES;
}

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

0 comments on commit 460f397

Please sign in to comment.