Skip to content

+[GTDiff diffOldTree:withNewIndex:…] #539

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 1 commit into from
Jan 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ObjectiveGit/GTDiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@class GTDiffDelta;
@class GTRepository;
@class GTTree;
@class GTIndex;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -200,6 +201,23 @@ typedef NS_OPTIONS(NSInteger, GTDiffFindOptionsFlags) {
/// Returns a newly created `GTDiff` object or nil on error.
+ (nullable instancetype)diffOldTree:(nullable GTTree *)oldTree withNewTree:(nullable GTTree *)newTree inRepository:(GTRepository *)repository options:(nullable NSDictionary *)options error:(NSError **)error;

/// Create a diff between `GTTree` and `GTIndex`.
///
/// Both instances must be from the same repository, or an exception will be thrown.
///
/// oldTree - The "left" side of the diff. May be nil to represent an empty
/// tree.
/// newIndex - The "right" side of the diff. May be nil to represent an empty
/// index.
/// repository - The repository to be used for the diff. Cannot be nil.
/// options - A dictionary containing any of the above options key constants, or
/// nil to use the defaults.
/// error - Populated with an `NSError` object on error, if information is
/// available.
///
/// Returns a newly created `GTDiff` object or nil on error.
+ (nullable instancetype)diffOldTree:(nullable GTTree *)oldTree withNewIndex:(nullable GTIndex *)newIndex inRepository:(GTRepository *)repository options:(nullable NSDictionary *)options error:(NSError **)error;

/// Create a diff between a repository's current index.
///
/// This is equivalent to `git diff --cached <treeish>` or if you pass the HEAD
Expand Down
16 changes: 16 additions & 0 deletions ObjectiveGit/GTDiff.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "GTCommit.h"
#import "GTRepository.h"
#import "GTTree.h"
#import "GTIndex.h"
#import "NSArray+StringArray.h"
#import "NSError+Git.h"

Expand Down Expand Up @@ -94,6 +95,21 @@ + (instancetype)diffOldTree:(GTTree *)oldTree withNewTree:(GTTree *)newTree inRe
return [[self alloc] initWithGitDiff:diff repository:repository];
}

+ (instancetype)diffOldTree:(GTTree *)oldTree withNewIndex:(GTIndex *)newIndex inRepository:(GTRepository *)repository options:(NSDictionary *)options error:(NSError **)error {
NSParameterAssert(repository != nil);

__block git_diff *diff;
int status = [self handleParsedOptionsDictionary:options usingBlock:^(git_diff_options *optionsStruct) {
return git_diff_tree_to_index(&diff, repository.git_repository, oldTree.git_tree, newIndex.git_index, optionsStruct);
}];
if (status != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:status description:@"Failed to create diff between %@ and %@", oldTree.SHA, newIndex];
return nil;
}

return [[self alloc] initWithGitDiff:diff repository:repository];
}

+ (instancetype)diffIndexFromTree:(GTTree *)tree inRepository:(GTRepository *)repository options:(NSDictionary *)options error:(NSError **)error {
NSParameterAssert(repository != nil);
NSParameterAssert(tree == nil || [tree.repository isEqual:repository]);
Expand Down