Skip to content

Commit 54b50cd

Browse files
committed
Add checkout strategy to stash apply/pop methods
For a finer control over the unstash process, propogate checkout strategy to Objective-Git from the underlying libgit2 stash methods.
1 parent d2bca2e commit 54b50cd

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

ObjectiveGit/GTRepository+Stashing.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ NS_ASSUME_NONNULL_BEGIN
6262
/// will cause enumeration to stop after the block returns. Must not be nil.
6363
- (void)enumerateStashesUsingBlock:(void (^)(NSUInteger index, NSString * __nullable message, GTOID * __nullable oid, BOOL *stop))block;
6464

65-
/// Apply stashed changes.
65+
/// Apply stashed changes (with a default checkout strategy).
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.
@@ -71,7 +71,17 @@ NS_ASSUME_NONNULL_BEGIN
7171
/// Returns YES if the requested stash was successfully applied, NO otherwise.
7272
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock;
7373

74-
/// Pop stashed changes.
74+
/// Apply stashed changes with a set checkout strategy.
75+
///
76+
/// index - The index of the stash to apply. 0 is the latest one.
77+
/// flags - The flags to use when applying the stash.
78+
/// strategy - The checkout strategy to use when applying the stash.
79+
/// error - If not NULL, set to any error that occurred.
80+
///
81+
/// Returns YES if the requested stash was successfully applied, NO otherwise.
82+
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags strategy:(GTCheckoutStrategyType)strategy error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock;
83+
84+
/// Pop stashed changes (with a default checkout strategy).
7585
///
7686
/// index - The index of the stash to apply. 0 is the most recent stash.
7787
/// flags - The flags to use when applying the stash.
@@ -80,6 +90,16 @@ NS_ASSUME_NONNULL_BEGIN
8090
/// Returns YES if the requested stash was successfully applied, NO otherwise.
8191
- (BOOL)popStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock;
8292

93+
/// Pop stashed changes with a set checkout strategy.
94+
///
95+
/// index - The index of the stash to apply. 0 is the most recent stash.
96+
/// flags - The flags to use when applying the stash.
97+
/// strategy - The checkout strategy to use when applying the stash.
98+
/// error - If not NULL, set to any error that occurred.
99+
///
100+
/// Returns YES if the requested stash was successfully applied, NO otherwise.
101+
- (BOOL)popStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags strategy:(GTCheckoutStrategyType)strategy error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock;
102+
83103
/// Drop a stash from the repository's list of stashes.
84104
///
85105
/// index - The index of the stash to drop, where 0 is the most recent stash.

ObjectiveGit/GTRepository+Stashing.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,16 @@ static int stashApplyProgressCallback(git_stash_apply_progress_t progress, void
6060
}
6161

6262
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
63+
// GTCheckoutStrategyNone may sound odd at first, but this is what was passed in before (de-facto), and libgit2 has a sanity check to set it to GIT_CHECKOUT_SAFE if it's 0.
64+
return [self applyStashAtIndex:index flags:flags strategy:GTCheckoutStrategyNone error:error progressBlock:progressBlock];
65+
}
66+
67+
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags strategy:(GTCheckoutStrategyType)strategy error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
6368
git_stash_apply_options stash_options = GIT_STASH_APPLY_OPTIONS_INIT;
6469

6570
stash_options.flags = (git_stash_apply_flags)flags;
71+
stash_options.checkout_options.checkout_strategy = strategy;
72+
6673
if (progressBlock != nil) {
6774
stash_options.progress_cb = stashApplyProgressCallback;
6875
stash_options.progress_payload = (__bridge void *)progressBlock;
@@ -77,9 +84,15 @@ - (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)fl
7784
}
7885

7986
- (BOOL)popStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
87+
// GTCheckoutStrategyNone may sound odd at first, but this is what was passed in before (de-facto), and libgit2 has a sanity check to set it to GIT_CHECKOUT_SAFE if it's 0.
88+
return [self popStashAtIndex:index flags:flags strategy:GTCheckoutStrategyNone error:error progressBlock:progressBlock];
89+
}
90+
91+
- (BOOL)popStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags strategy:(GTCheckoutStrategyType)strategy error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
8092
git_stash_apply_options stash_options = GIT_STASH_APPLY_OPTIONS_INIT;
8193

8294
stash_options.flags = (git_stash_apply_flags)flags;
95+
stash_options.checkout_options.checkout_strategy = strategy;
8396
if (progressBlock != nil) {
8497
stash_options.progress_cb = stashApplyProgressCallback;
8598
stash_options.progress_payload = (__bridge void *)progressBlock;

0 commit comments

Comments
 (0)