Moar wrapper functions by slavikus · Pull Request #549 · libgit2/objective-git · GitHub
Skip to content
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
12 changes: 12 additions & 0 deletions ObjectiveGit/GTCommit.h
18 changes: 18 additions & 0 deletions ObjectiveGit/GTCommit.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
#import "NSString+Git.h"
#import "NSDate+GTTimeAdditions.h"
#import "GTOID.h"
#import "GTIndex.h"

#import "git2/commit.h"
#import "git2/errors.h"
#import "git2/merge.h"

@implementation GTCommit

Expand Down Expand Up @@ -130,4 +132,20 @@ - (NSArray *)parents {
return parents;
}

#pragma mark Merging

- (GTIndex *)merge:(GTCommit *)otherCommit error:(NSError **)error {
NSParameterAssert(otherCommit != nil);

git_index *index;

int result = git_merge_commits(&index, self.repository.git_repository, self.git_commit, otherCommit.git_commit, NULL);
if (result != GIT_OK || index == NULL) {
if (error != NULL) *error = [NSError git_errorFor:result description:@"Failed to merge commit %@ with commit %@", self.SHA, otherCommit.SHA];
return nil;
}

return [[GTIndex alloc] initWithGitIndex:index repository:self.repository];
}

@end
17 changes: 17 additions & 0 deletions ObjectiveGit/GTDiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,23 @@ typedef NS_OPTIONS(NSInteger, GTDiffFindOptionsFlags) {
/// 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 two `GTIndex`es.
///
/// Both instances must be from the same repository, or an exception will be thrown.
///
/// oldIndex - The "left" side of the diff. May be nil to represent an empty
/// index.
/// 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)diffOldIndex:(nullable GTIndex *)oldIndex 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