mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Read branches in a repository
This adds a -readBranches function which allows you to read in all branches in our repository. It is used in the branch display popup box.
This commit is contained in:
+910
-884
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,7 @@ extern NSString* PBGitRepositoryErrorDomain;
|
||||
|
||||
@interface PBGitRepository : NSDocument {
|
||||
PBGitRevList* revisionList;
|
||||
NSArray* branches;
|
||||
}
|
||||
|
||||
+ (PBGitRepository*) repositoryWithPath:(NSString*) path;
|
||||
@@ -21,6 +22,10 @@ extern NSString* PBGitRepositoryErrorDomain;
|
||||
- (NSFileHandle*) handleForCommand:(NSString*) cmd;
|
||||
- (NSFileHandle*) handleForArguments:(NSArray*) args;
|
||||
|
||||
- (void) readBranches;
|
||||
|
||||
+ (NSURL*)gitDirForURL:(NSURL*)repositoryURL;
|
||||
@property (readonly) PBGitRevList* revisionList;
|
||||
@property (assign) NSArray* branches;
|
||||
|
||||
@end
|
||||
|
||||
+18
-1
@@ -17,7 +17,7 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
|
||||
|
||||
@implementation PBGitRepository
|
||||
|
||||
@synthesize revisionList;
|
||||
@synthesize revisionList, branches;
|
||||
static NSString* gitPath;
|
||||
|
||||
+ (void) initialize
|
||||
@@ -143,9 +143,26 @@ static NSString* gitPath;
|
||||
|
||||
NSLog(@"Git path is: %@", self.fileURL);
|
||||
revisionList = [[PBGitRevList alloc] initWithRepository:self andRevListParameters:[NSArray array]];
|
||||
[self readBranches];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) readBranches
|
||||
{
|
||||
NSString* output = [PBEasyPipe outputForCommand:gitPath withArgs:[NSArray arrayWithObjects:@"for-each-ref", @"refs/heads", nil] inDir: self.fileURL.path];
|
||||
NSArray* lines = [output componentsSeparatedByString:@"\n"];
|
||||
NSMutableArray* newBranches = [NSMutableArray array];
|
||||
for (NSString* line in lines) {
|
||||
NSString* substr = [line substringWithRange: NSMakeRange(40,19)];
|
||||
if (![substr isEqualToString:@" commit\trefs/heads/"]) {
|
||||
NSLog(@"Cannot parse branch %@. (%@)", line, substr);
|
||||
continue;
|
||||
}
|
||||
NSString* branch = [line substringFromIndex:59];
|
||||
[newBranches addObject: branch];
|
||||
}
|
||||
self.branches = newBranches;
|
||||
}
|
||||
|
||||
- (NSFileHandle*) handleForArguments:(NSArray *)args
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user