Skip to content

Commit 181bddb

Browse files
committed
A Nu Branches.
1 parent d9cdb5d commit 181bddb

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

ObjectiveGit/GTRepository.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ extern NSString * const GTRepositoryInitOptionsOriginURLString;
249249
- (NSArray *)remoteBranchesWithError:(NSError **)error;
250250
- (NSArray *)branchesWithPrefix:(NSString *)prefix error:(NSError **)error;
251251

252+
/// Get the local and remote branches and merge them together by combining local
253+
/// branches with their remote branch, if they have one.
254+
///
255+
/// error - The error if one occurs.
256+
///
257+
/// Returns the branches or nil if an error occurs.
258+
- (NSArray *)branches:(NSError **)error;
259+
252260
/// List all remotes in the repository
253261
///
254262
/// error - will be filled if an error occurs

ObjectiveGit/GTRepository.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,28 @@ - (NSArray *)allBranchesWithError:(NSError **)error {
425425
return allBranches;
426426
}
427427

428+
- (NSArray *)branches:(NSError **)error {
429+
NSArray *localBranches = [self localBranchesWithError:error];
430+
if (localBranches == nil) return nil;
431+
432+
NSMutableArray *remoteBranches = [[self remoteBranchesWithError:error] mutableCopy];
433+
if (remoteBranches == nil) return nil;
434+
435+
NSMutableArray *branches = [NSMutableArray array];
436+
for (GTBranch *branch in localBranches) {
437+
BOOL success = NO;
438+
GTBranch *trackingBranch = [branch trackingBranchWithError:error success:&success];
439+
if (!success) continue;
440+
441+
[remoteBranches removeObject:trackingBranch];
442+
[branches addObject:branch];
443+
}
444+
445+
[branches addObjectsFromArray:remoteBranches];
446+
447+
return branches;
448+
}
449+
428450
- (NSArray *)remoteNamesWithError:(NSError **)error {
429451
git_strarray array;
430452
int gitError = git_remote_list(&array, self.git_repository);

0 commit comments

Comments
 (0)