Skip to content

Commit d4583ba

Browse files
committed
Add checkout options support to stash API.
1 parent cc41976 commit d4583ba

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

ObjectiveGit/GTRepository+Stashing.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,23 @@ NS_ASSUME_NONNULL_BEGIN
6666
///
6767
/// index - The index of the stash to apply. 0 is the latest one.
6868
/// flags - The flags to use when applying the stash.
69+
/// options - The options to use when checking out.
6970
/// error - If not NULL, set to any error that occurred.
7071
/// progressBlock - A block that will be executed on each step of the stash application.
7172
///
7273
/// Returns YES if the requested stash was successfully applied, NO otherwise.
73-
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock;
74+
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags checkoutOptions:(nullable GTCheckoutOptions *)options error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock;
7475

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

8587
/// Drop a stash from the repository's list of stashes.
8688
///

ObjectiveGit/GTRepository+Stashing.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int stashApplyProgressCallback(git_stash_apply_progress_t progress, void
5959
return (stop ? GIT_EUSER : 0);
6060
}
6161

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

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

71+
if (options != nil) {
72+
stash_options.checkout_options = *options.git_checkoutOptions;
73+
}
74+
7175
if (pop == NO) {
7276
int gitError = git_stash_apply(self.git_repository, index, &stash_options);
7377
if (gitError != GIT_OK) {
@@ -84,12 +88,12 @@ - (BOOL)applyStashAtIndex:(NSUInteger)index popStash:(BOOL)pop flags:(GTReposito
8488
return YES;
8589
}
8690

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

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

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

0 commit comments

Comments
 (0)