-
Notifications
You must be signed in to change notification settings - Fork 281
Wrap all the various way of doing checkouts in GTCheckoutOptions #459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
311ca45
Wrap all the various way of doing checkouts in GTCheckoutOptions
tiennou 3cb36a8
0xdeadbeef
tiennou f66d713
Missing documentation for parameter
tiennou 84fd119
Add checkout options support to stash API.
tiennou dea9507
Fix stash tests
tiennou e03bee9
Switch to the modern object-wrap syntax
tiennou af07357
Explicit comparison with `nil`
tiennou 7e6719f
Add pathspec support to GTCheckoutOptions
tiennou a5ed471
Fix a newly added checkout strategy call
tiennou 8841ce7
Remove deprecated method on GTRepository
tiennou 9d131a3
Ability to checkout from an index
tiennou 24fb88d
Missing newline at EOF
tiennou 261d619
Documentation
tiennou 4fe2e03
Add new checkout strategies
tiennou 3c515b0
Options has gone away
tiennou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// GTCheckoutOptions.h | ||
// ObjectiveGitFramework | ||
// | ||
// Created by Etienne on 10/04/2015. | ||
// Copyright (c) 2015 GitHub, Inc. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "git2/checkout.h" | ||
|
||
@class GTDiffFile; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/// Checkout strategies used by the various -checkout... methods | ||
/// See git_checkout_strategy_t | ||
typedef NS_OPTIONS(NSInteger, GTCheckoutStrategyType) { | ||
GTCheckoutStrategyNone = GIT_CHECKOUT_NONE, | ||
GTCheckoutStrategySafe = GIT_CHECKOUT_SAFE, | ||
GTCheckoutStrategyForce = GIT_CHECKOUT_FORCE, | ||
GTCheckoutStrategyRecreateMissing = GIT_CHECKOUT_RECREATE_MISSING, | ||
GTCheckoutStrategyAllowConflicts = GIT_CHECKOUT_ALLOW_CONFLICTS, | ||
GTCheckoutStrategyRemoveUntracked = GIT_CHECKOUT_REMOVE_UNTRACKED, | ||
GTCheckoutStrategyRemoveIgnored = GIT_CHECKOUT_REMOVE_IGNORED, | ||
GTCheckoutStrategyUpdateOnly = GIT_CHECKOUT_UPDATE_ONLY, | ||
GTCheckoutStrategyDontUpdateIndex = GIT_CHECKOUT_DONT_UPDATE_INDEX, | ||
GTCheckoutStrategyNoRefresh = GIT_CHECKOUT_NO_REFRESH, | ||
GTCheckoutStrategySkipUnmerged = GIT_CHECKOUT_SKIP_UNMERGED, | ||
GTCheckoutStrategyUseOurs = GIT_CHECKOUT_USE_OURS, | ||
GTCheckoutStrategyUseTheirs = GIT_CHECKOUT_USE_THEIRS, | ||
GTCheckoutStrategyDisablePathspecMatch = GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH, | ||
GTCheckoutStrategySkipLockedDirectories = GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES, | ||
GTCheckoutStrategyDoNotOverwriteIgnored = GIT_CHECKOUT_DONT_OVERWRITE_IGNORED, | ||
GTCheckoutStrategyConflictStyleMerge = GIT_CHECKOUT_CONFLICT_STYLE_MERGE, | ||
GTCheckoutStrategyCoflictStyleDiff3 = GIT_CHECKOUT_CONFLICT_STYLE_DIFF3, | ||
GTCheckoutStrategyDoNotRemoveExisting = GIT_CHECKOUT_DONT_REMOVE_EXISTING, | ||
GTCheckoutStrategyDoNotWriteIndex = GIT_CHECKOUT_DONT_WRITE_INDEX, | ||
}; | ||
|
||
/// Checkout notification flags used by the various -checkout... methods | ||
/// See git_checkout_notify_t | ||
typedef NS_OPTIONS(NSInteger, GTCheckoutNotifyFlags) { | ||
GTCheckoutNotifyNone = GIT_CHECKOUT_NOTIFY_NONE, | ||
GTCheckoutNotifyConflict = GIT_CHECKOUT_NOTIFY_CONFLICT, | ||
GTCheckoutNotifyDirty = GIT_CHECKOUT_NOTIFY_DIRTY, | ||
GTCheckoutNotifyUpdated = GIT_CHECKOUT_NOTIFY_UPDATED, | ||
GTCheckoutNotifyUntracked = GIT_CHECKOUT_NOTIFY_UNTRACKED, | ||
GTCheckoutNotifyIgnored = GIT_CHECKOUT_NOTIFY_IGNORED, | ||
|
||
GTCheckoutNotifyAll = GIT_CHECKOUT_NOTIFY_ALL, | ||
}; | ||
|
||
@interface GTCheckoutOptions : NSObject | ||
|
||
/// Create a checkout options object. | ||
/// | ||
/// Since there are many places where we can checkout data, this object allow us | ||
/// to centralize all the various behaviors that checkout allow. | ||
/// | ||
/// @param strategy The checkout strategy to use. | ||
/// @param notifyFlags The checkout events that will be notified via `notifyBlock`. | ||
/// @param progressBlock A block that will be called for each checkout step. | ||
/// @param notifyBlock A block that will be called for each event, @see `notifyFlags`. | ||
/// | ||
/// @return A newly-initialized GTCheckoutOptions object. | ||
+ (instancetype)checkoutOptionsWithStrategy:(GTCheckoutStrategyType)strategy notifyFlags:(GTCheckoutNotifyFlags)notifyFlags progressBlock:(nullable void (^)(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps))progressBlock notifyBlock:(nullable int (^)(GTCheckoutNotifyFlags why, NSString *path, GTDiffFile *baseline, GTDiffFile *target, GTDiffFile *workdir))notifyBlock; | ||
|
||
/// Create a checkout options object. | ||
/// @see +checkoutOptionsWithStrategy:notifyFlags:progressBlock:notifyBlock: | ||
+ (instancetype)checkoutOptionsWithStrategy:(GTCheckoutStrategyType)strategy notifyFlags:(GTCheckoutNotifyFlags)notifyFlags notifyBlock:(int (^)(GTCheckoutNotifyFlags why, NSString *path, GTDiffFile *baseline, GTDiffFile *target, GTDiffFile *workdir))notifyBlock; | ||
|
||
/// Create a checkout options object. | ||
/// @see +checkoutOptionsWithStrategy:notifyFlags:progressBlock:notifyBlock: | ||
+ (instancetype)checkoutOptionsWithStrategy:(GTCheckoutStrategyType)strategy progressBlock:(void (^)(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps))progressBlock; | ||
|
||
/// Create a checkout options object. | ||
/// @see +checkoutOptionsWithStrategy:notifyFlags:progressBlock:notifyBlock: | ||
+ (instancetype)checkoutOptionsWithStrategy:(GTCheckoutStrategyType)strategy; | ||
|
||
/// Get the underlying git_checkout_options struct. | ||
/// | ||
/// @return <#return value description#> | ||
- (git_checkout_options *)git_checkoutOptions NS_RETURNS_INNER_POINTER; | ||
|
||
/// The checkout strategy to use. | ||
@property (assign) GTCheckoutStrategyType strategy; | ||
|
||
/// The checkout progress block that was passed in. | ||
@property (copy) void (^progressBlock)(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps); | ||
|
||
/// The notification flags currently enabled. | ||
@property (assign) GTCheckoutNotifyFlags notifyFlags; | ||
|
||
/// The checkout notification block that was passed in. | ||
@property (copy) int (^notifyBlock)(GTCheckoutNotifyFlags why, NSString *path, GTDiffFile *baseline, GTDiffFile *target, GTDiffFile *workdir); | ||
|
||
/// An array of strings used to restrict what will be checked out. | ||
@property (copy) NSArray <NSString *> *pathSpecs; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// | ||
// GTCheckoutOptions.m | ||
// ObjectiveGitFramework | ||
// | ||
// Created by Etienne on 10/04/2015. | ||
// Copyright (c) 2015 GitHub, Inc. All rights reserved. | ||
// | ||
|
||
#import "GTCheckoutOptions.h" | ||
#import "GTDiffFile.h" | ||
#import "NSError+Git.h" | ||
#import "NSArray+StringArray.h" | ||
#import "git2.h" | ||
|
||
// The type of block set in progressBlock for progress reporting | ||
typedef void (^GTCheckoutProgressBlock)(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps); | ||
|
||
// The type of block set in notifyBlock for notification reporting | ||
typedef int (^GTCheckoutNotifyBlock)(GTCheckoutNotifyFlags why, NSString *path, GTDiffFile * __nullable baseline, GTDiffFile * __nullable target, GTDiffFile * __nullable workdir); | ||
|
||
|
||
@interface GTCheckoutOptions () { | ||
git_checkout_options _git_checkoutOptions; | ||
} | ||
@end | ||
|
||
@implementation GTCheckoutOptions | ||
|
||
+ (instancetype)checkoutOptionsWithStrategy:(GTCheckoutStrategyType)strategy notifyFlags:(GTCheckoutNotifyFlags)notifyFlags progressBlock:(nullable GTCheckoutProgressBlock)progressBlock notifyBlock:(nullable GTCheckoutNotifyBlock)notifyBlock { | ||
GTCheckoutOptions *options = [self checkoutOptionsWithStrategy:strategy]; | ||
options.notifyFlags = notifyFlags; | ||
options.notifyBlock = notifyBlock; | ||
options.progressBlock = progressBlock; | ||
return options; | ||
} | ||
|
||
+ (instancetype)checkoutOptionsWithStrategy:(GTCheckoutStrategyType)strategy progressBlock:(GTCheckoutProgressBlock)progressBlock { | ||
NSParameterAssert(progressBlock != nil); | ||
GTCheckoutOptions *options = [self checkoutOptionsWithStrategy:strategy]; | ||
options.progressBlock = progressBlock; | ||
return options; | ||
} | ||
|
||
+ (instancetype)checkoutOptionsWithStrategy:(GTCheckoutStrategyType)strategy notifyFlags:(GTCheckoutNotifyFlags)notifyFlags notifyBlock:(GTCheckoutNotifyBlock)notifyBlock { | ||
NSParameterAssert(notifyBlock != nil); | ||
return [self checkoutOptionsWithStrategy:strategy notifyFlags:notifyFlags progressBlock:nil notifyBlock:notifyBlock]; | ||
} | ||
|
||
+ (instancetype)checkoutOptionsWithStrategy:(GTCheckoutStrategyType)strategy { | ||
GTCheckoutOptions *options = [[self alloc] init]; | ||
options.strategy = strategy; | ||
return options; | ||
} | ||
|
||
- (instancetype)init { | ||
self = [super init]; | ||
if (self == nil) return nil; | ||
|
||
_git_checkoutOptions.version = GIT_CHECKOUT_OPTIONS_VERSION; | ||
|
||
return self; | ||
} | ||
|
||
static void GTCheckoutProgressCallback(const char *path, size_t completedSteps, size_t totalSteps, void *payload) { | ||
if (payload == NULL) return; | ||
void (^block)(NSString *, NSUInteger, NSUInteger) = (__bridge id)payload; | ||
NSString *nsPath = (path != NULL ? @(path) : nil); | ||
block(nsPath, completedSteps, totalSteps); | ||
} | ||
|
||
static int GTCheckoutNotifyCallback(git_checkout_notify_t why, const char *path, const git_diff_file *baseline, const git_diff_file *target, const git_diff_file *workdir, void *payload) { | ||
if (payload == NULL) return 0; | ||
GTCheckoutNotifyBlock block = (__bridge id)payload; | ||
NSString *nsPath = (path != NULL ? @(path) : nil); | ||
GTDiffFile *gtBaseline = (baseline != NULL ? [[GTDiffFile alloc] initWithGitDiffFile:*baseline] : nil); | ||
GTDiffFile *gtTarget = (target != NULL ? [[GTDiffFile alloc] initWithGitDiffFile:*target] : nil); | ||
GTDiffFile *gtWorkdir = (workdir != NULL ? [[GTDiffFile alloc] initWithGitDiffFile:*workdir] : nil); | ||
return block((GTCheckoutNotifyFlags)why, nsPath, gtBaseline, gtTarget, gtWorkdir); | ||
} | ||
|
||
- (git_checkout_options *)git_checkoutOptions { | ||
_git_checkoutOptions.checkout_strategy = self.strategy; | ||
|
||
if (self.progressBlock != nil) { | ||
_git_checkoutOptions.progress_cb = GTCheckoutProgressCallback; | ||
_git_checkoutOptions.progress_payload = (__bridge void *)self.progressBlock; | ||
} | ||
|
||
if (self.notifyBlock != nil) { | ||
_git_checkoutOptions.notify_cb = GTCheckoutNotifyCallback; | ||
_git_checkoutOptions.notify_flags = self.notifyFlags; | ||
_git_checkoutOptions.notify_payload = (__bridge void *)self.notifyBlock; | ||
} | ||
|
||
_git_checkoutOptions.paths = self.pathSpecs.git_strarray; | ||
|
||
return &_git_checkoutOptions; | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the copy-ness here makes me twitchy.