Skip to content

Commit 3b00247

Browse files
committed
Add -OID and -parentOIDs to GTCommit
1 parent 08cda38 commit 3b00247

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

ObjectiveGit/GTCommit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ NS_ASSUME_NONNULL_BEGIN
3939

4040
@interface GTCommit : GTObject {}
4141

42+
@property (nonatomic, readonly, strong) GTOID *OID;
4243
@property (nonatomic, readonly, strong) GTSignature * _Nullable author;
4344
@property (nonatomic, readonly, strong) GTSignature * _Nullable committer;
4445
@property (nonatomic, readonly, copy) NSArray<GTCommit *> *parents;
46+
@property (nonatomic, readonly, copy) NSArray<GTOID *> *parentOIDs;
4547
@property (nonatomic, readonly) NSString * _Nullable message;
4648
@property (nonatomic, readonly) NSString *messageDetails;
4749
@property (nonatomic, readonly) NSString *messageSummary;

ObjectiveGit/GTCommit.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ - (git_commit *)git_commit {
5353

5454
#pragma mark API
5555

56+
- (GTOID *)OID {
57+
return [GTOID oidWithGitOid:git_commit_id(self.git_commit)];
58+
}
59+
5660
- (NSString *)message {
5761
const char *s = git_commit_message(self.git_commit);
5862
if(s == NULL) return nil;
@@ -117,6 +121,19 @@ - (BOOL)isMerge {
117121
return git_commit_parentcount(self.git_commit) > 1;
118122
}
119123

124+
- (NSArray <GTOID *> *)parentOIDs {
125+
unsigned numberOfParents = git_commit_parentcount(self.git_commit);
126+
NSMutableArray <GTOID *> *parents = [NSMutableArray arrayWithCapacity:numberOfParents];
127+
128+
for (unsigned i = 0; i < numberOfParents; i++) {
129+
const git_oid *parent = git_commit_parent_id(self.git_commit, i);
130+
131+
[parents addObject:[GTOID oidWithGitOid:parent]];
132+
}
133+
134+
return parents;
135+
}
136+
120137
- (NSArray *)parents {
121138
unsigned numberOfParents = git_commit_parentcount(self.git_commit);
122139
NSMutableArray *parents = [NSMutableArray arrayWithCapacity:numberOfParents];

ObjectiveGitTests/GTCommitSpec.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
expect(commit).to(beAnInstanceOf(GTCommit.class));
3232
expect(commit.type).to(equal(@"commit"));
3333
expect(commit.SHA).to(equal(commitSHA));
34+
expect(commit.OID).to(equal([GTOID oidWithSHA:commitSHA]));
3435

3536
expect(commit.message).to(equal(@"testing\n"));
3637
expect(commit.messageSummary).to(equal(@"testing"));
@@ -60,7 +61,14 @@
6061
expect(commit).notTo(beNil());
6162
expect(error).to(beNil());
6263

63-
expect(@(commit.parents.count)).to(equal(@2));
64+
NSArray *commitOIDs = @[@"c47800c7266a2be04c571c04d5a6614691ea99bd", @"9fd738e8f7967c078dceed8190330fc8648ee56a"];
65+
NSArray *commitParents = commit.parentOIDs;
66+
expect(@(commitParents.count)).to(equal(@(commitOIDs.count)));
67+
expect([commitParents valueForKey:@"SHA"]).to(equal(commitOIDs));
68+
69+
commitParents = commit.parents;
70+
expect(@(commitParents.count)).to(equal(@(commitOIDs.count)));
71+
expect([commitParents valueForKeyPath:@"OID.SHA"]).to(equal(commitOIDs));
6472
});
6573

6674
it(@"can identify merges", ^{

0 commit comments

Comments
 (0)