diff --git a/Classes/GTCommit.h b/Classes/GTCommit.h index d0c1ff253..79b4fdc64 100644 --- a/Classes/GTCommit.h +++ b/Classes/GTCommit.h @@ -46,6 +46,9 @@ @property (nonatomic, readonly) NSTimeZone *commitTimeZone; @property (nonatomic, readonly) GTTree *tree; +/// Is this a merge commit? +@property (nonatomic, readonly, assign, getter = isMerge) BOOL merge; + /// The underlying `git_object` as a `git_commit` object. - (git_commit *)git_commit __attribute__((objc_returns_inner_pointer)); diff --git a/Classes/GTCommit.m b/Classes/GTCommit.m index 8e4b8cee4..1dadde88a 100644 --- a/Classes/GTCommit.m +++ b/Classes/GTCommit.m @@ -108,6 +108,10 @@ - (GTTree *)tree { return (GTTree *)[GTObject objectWithObj:(git_object *)tree inRepository:self.repository]; } +- (BOOL)isMerge { + return git_commit_parentcount(self.git_commit) > 1; +} + - (NSArray *)parents { unsigned numberOfParents = git_commit_parentcount(self.git_commit); NSMutableArray *parents = [NSMutableArray arrayWithCapacity:numberOfParents]; diff --git a/ObjectiveGitTests/GTCommitSpec.m b/ObjectiveGitTests/GTCommitSpec.m index 7104a1117..706dd077f 100644 --- a/ObjectiveGitTests/GTCommitSpec.m +++ b/ObjectiveGitTests/GTCommitSpec.m @@ -59,6 +59,15 @@ expect(commit.parents.count).to.equal(2); }); +it(@"can identify merges", ^{ + NSError *error; + NSString *commitSHA = @"a4a7dce85cf63874e984719f4fdd239f5145052f"; + GTCommit *commit = [repository lookUpObjectBySHA:commitSHA error:&error]; + expect(commit).notTo.beNil(); + + expect(commit.merge).to.beTruthy(); +}); + afterEach(^{ [self tearDown]; });