Skip to content

Commit 9eb3981

Browse files
committed
Added -[GTRepository enumerateLocalCommitsInBranch:trackingBranch:error:].
1 parent 753d2d4 commit 9eb3981

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

ObjectiveGit/GTRepository.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,20 @@ NS_ASSUME_NONNULL_BEGIN
565565
/// Returns whether `ahead` and `behind` were successfully calculated.
566566
- (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind ofOID:(GTOID *)headOID relativeToOID:(GTOID *)baseOID error:(NSError **)error;
567567

568+
/// Creates an enumerator for walking the local commits in relative to the
569+
/// tracking branch.
570+
///
571+
/// Note that this will only be accurate iff `trackingBranch` truly is
572+
/// `localBranch`s tracking branch. If you need more general functionality, see
573+
/// -[GTBranch uniqueCommitsRelativeToBranch:error:].
574+
///
575+
/// localBranch - The local branch.
576+
/// trackingBranch - `localBranch`s tracking branch.
577+
/// error - The error if one occurred.
578+
///
579+
/// Returns the enumerator or nil if an error occurred.
580+
- (nullable GTEnumerator *)enumerateLocalCommitsInBranch:(GTBranch *)localBranch trackingBranch:(GTBranch *)trackingBranch error:(NSError **)error;
581+
568582
@end
569583

570584
NS_ASSUME_NONNULL_END

ObjectiveGit/GTRepository.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,4 +912,20 @@ - (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind ofOID:(GTOID *)he
912912
return YES;
913913
}
914914

915+
- (GTEnumerator *)enumerateLocalCommitsInBranch:(GTBranch *)localBranch trackingBranch:(GTBranch *)trackingBranch error:(NSError **)error {
916+
NSParameterAssert(localBranch != nil);
917+
NSParameterAssert(trackingBranch != nil);
918+
919+
GTEnumerator *enumerator = [[GTEnumerator alloc] initWithRepository:self error:error];
920+
if (enumerator == nil) return nil;
921+
922+
BOOL success = [enumerator pushSHA:localBranch.OID.SHA error:error];
923+
if (!success) return nil;
924+
925+
success = [enumerator hideSHA:trackingBranch.OID.SHA error:error];
926+
if (!success) return nil;
927+
928+
return enumerator;
929+
}
930+
915931
@end

0 commit comments

Comments
 (0)