Skip to content

Commit

Permalink
listAllRemoteBranchesInRepository:error: no longer returns HEAD and m…
Browse files Browse the repository at this point in the history
…aster
  • Loading branch information
joshaber committed Mar 24, 2011
1 parent e79ee42 commit 6d7b5a0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Classes/GTBranch.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@
// returns number of commits in the branch or NSNotFound if an error occurred
- (NSInteger)numberOfCommitsAndReturnError:(NSError **)error;

- (BOOL)isRemote;
- (BOOL)isLocal;

@end
23 changes: 22 additions & 1 deletion Classes/GTBranch.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,20 @@ + (NSArray *)listAllLocalBranchesInRepository:(GTRepository *)repo error:(NSErro

+ (NSArray *)listAllRemoteBranchesInRepository:(GTRepository *)repo error:(NSError **)error {

return [self listAllBranchesInRepository:repo withPrefix:[self remoteNamePrefix] error:error];
static NSArray *unwantedRemoteBranches = nil;
if(unwantedRemoteBranches == nil) {
unwantedRemoteBranches = [NSArray arrayWithObjects:@"HEAD", @"master", nil];
}

NSArray *remoteBranches =[self listAllBranchesInRepository:repo withPrefix:[self remoteNamePrefix] error:error];
NSMutableArray *filteredList = [NSMutableArray arrayWithCapacity:remoteBranches.count];
for(GTBranch *branch in remoteBranches) {
if(![unwantedRemoteBranches containsObject:branch.shortName]) {
[filteredList addObject:branch];
}
}

return filteredList;
}

+ (NSArray *)listAllBranchesInRepository:(GTRepository *)repo withPrefix:(NSString *)prefix error:(NSError **)error {
Expand All @@ -162,4 +175,12 @@ - (NSInteger)numberOfCommitsAndReturnError:(NSError **)error {
return [self.repository.walker countFromSha:self.sha error:error];
}

- (BOOL)isRemote {
return [self.name hasPrefix:[[self class] remoteNamePrefix]];
}

- (BOOL)isLocal {
return [self.name hasPrefix:[[self class] localNamePrefix]];
}

@end
12 changes: 11 additions & 1 deletion Tests/GTBranchTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ - (void)testCanOpenHeadInRepo {
GHAssertNotNil(current, nil);
}

- (void)testCanListBranchesInRepo {
- (void)testCanListLocalBranchesInRepo {

NSError *error = nil;
GTRepository *repo = [GTRepository repoByOpeningRepositoryInDirectory:[NSURL fileURLWithPath:TEST_REPO_PATH()] error:&error];
Expand All @@ -35,6 +35,16 @@ - (void)testCanListBranchesInRepo {
GHAssertEquals(2, (int)branches.count, nil);
}

- (void)testCanListRemoteBranchesInRepo {
NSError *error = nil;
GTRepository *repo = [GTRepository repoByOpeningRepositoryInDirectory:[NSURL fileURLWithPath:TEST_REPO_PATH()] error:&error];
GHAssertNil(error, [error localizedDescription]);

NSArray *branches = [GTBranch listAllRemoteBranchesInRepository:repo error:&error];
GHAssertNotNil(branches, [error localizedDescription], nil);
GHAssertEquals(0, (int)branches.count, nil);
}

- (void)testCanCountCommitsInBranch {

NSError *error = nil;
Expand Down

0 comments on commit 6d7b5a0

Please sign in to comment.