From 4bcbf43dc4dc10e7ccca3b2d2b2a3f3bd02212ed Mon Sep 17 00:00:00 2001 From: Nathan Kinsinger Date: Sun, 7 Feb 2010 17:35:48 -0700 Subject: [PATCH] Add convenience method for the repository's projectName Update the displayName method to use it --- PBGitRepository.h | 1 + PBGitRepository.m | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/PBGitRepository.h b/PBGitRepository.h index 166aaa0..4108749 100644 --- a/PBGitRepository.h +++ b/PBGitRepository.h @@ -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; diff --git a/PBGitRepository.m b/PBGitRepository.m index e5fd9a9..68b69cb 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -152,20 +152,22 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain"; // The fileURL the document keeps is to the .git dir, but that’s 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