forked from libgit2/objective-git
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix conflicts with pull request libgit2#459
# Conflicts: # ObjectiveGit/GTRepository+Stashing.m
- Loading branch information
Showing
19 changed files
with
336 additions
and
180 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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.