Add convenience method for the repository's projectName

Update the displayName method to use it
This commit is contained in:
Nathan Kinsinger
2010-02-07 17:35:48 -07:00
parent fe5dddc681
commit 4bcbf43dc4
2 changed files with 15 additions and 12 deletions
+1
View File
@@ -60,6 +60,7 @@ extern NSString* PBGitRepositoryErrorDomain;
- (BOOL)executeHook:(NSString *)name withArgs:(NSArray*) arguments output:(NSString **)output;
- (NSString *)workingDirectory;
- (NSString *) projectName;
- (NSString *)gitIgnoreFilename;
- (BOOL)isBareRepository;
+14 -12
View File
@@ -152,20 +152,22 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
// The fileURL the document keeps is to the .git dir, but thats pretty
// useless for display in the window title bar, so we show the directory above
- (NSString*)displayName
- (NSString *) displayName
{
NSString* dirName = self.fileURL.path.lastPathComponent;
if ([dirName isEqualToString:@".git"])
dirName = [self.fileURL.path stringByDeletingLastPathComponent].lastPathComponent;
NSString* displayName;
if (![[PBGitRef refFromString:[[self headRef] simpleRef]] type]) {
displayName = [NSString stringWithFormat:@"%@ (detached HEAD)", dirName];
} else {
displayName = [NSString stringWithFormat:@"%@ (branch: %@)", dirName,
[[self headRef] description]];
}
if (![[PBGitRef refFromString:[[self headRef] simpleRef]] type])
return [NSString stringWithFormat:@"%@ (detached HEAD)", [self projectName]];
return displayName;
return [NSString stringWithFormat:@"%@ (branch: %@)", [self projectName], [[self headRef] description]];
}
- (NSString *) projectName
{
NSString *projectPath = [[self fileURL] path];
if ([[projectPath lastPathComponent] isEqualToString:@".git"])
projectPath = [projectPath stringByDeletingLastPathComponent];
return [projectPath lastPathComponent];
}
// Get the .gitignore file at the root of the repository