From 3496bbfdd146bd9e8583ff042cd6a1e82e126e7c Mon Sep 17 00:00:00 2001 From: joshaber Date: Thu, 2 Oct 2014 15:08:21 -0400 Subject: [PATCH 1/2] Added -isMerge. --- Classes/GTCommit.h | 3 +++ Classes/GTCommit.m | 4 ++++ 2 files changed, 7 insertions(+) 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]; From cd4e10b6b192fa411fd51cb664ac0ed717b1c78a Mon Sep 17 00:00:00 2001 From: joshaber Date: Thu, 2 Oct 2014 15:08:24 -0400 Subject: [PATCH 2/2] Test. --- ObjectiveGitTests/GTCommitSpec.m | 9 +++++++++ 1 file changed, 9 insertions(+) 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]; });