Skip to content

Commit 4bcbf43

Browse files
committed
Add convenience method for the repository's projectName
Update the displayName method to use it
1 parent fe5dddc commit 4bcbf43

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

PBGitRepository.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern NSString* PBGitRepositoryErrorDomain;
6060
- (BOOL)executeHook:(NSString *)name withArgs:(NSArray*) arguments output:(NSString **)output;
6161

6262
- (NSString *)workingDirectory;
63+
- (NSString *) projectName;
6364
- (NSString *)gitIgnoreFilename;
6465
- (BOOL)isBareRepository;
6566

PBGitRepository.m

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,22 @@ - (id) initWithURL: (NSURL*) path
152152

153153
// The fileURL the document keeps is to the .git dir, but that’s pretty
154154
// useless for display in the window title bar, so we show the directory above
155-
- (NSString*)displayName
156-
{
157-
NSString* dirName = self.fileURL.path.lastPathComponent;
158-
if ([dirName isEqualToString:@".git"])
159-
dirName = [self.fileURL.path stringByDeletingLastPathComponent].lastPathComponent;
160-
NSString* displayName;
161-
if (![[PBGitRef refFromString:[[self headRef] simpleRef]] type]) {
162-
displayName = [NSString stringWithFormat:@"%@ (detached HEAD)", dirName];
163-
} else {
164-
displayName = [NSString stringWithFormat:@"%@ (branch: %@)", dirName,
165-
[[self headRef] description]];
166-
}
155+
- (NSString *) displayName
156+
{
157+
if (![[PBGitRef refFromString:[[self headRef] simpleRef]] type])
158+
return [NSString stringWithFormat:@"%@ (detached HEAD)", [self projectName]];
159+
160+
return [NSString stringWithFormat:@"%@ (branch: %@)", [self projectName], [[self headRef] description]];
161+
}
162+
163+
- (NSString *) projectName
164+
{
165+
NSString *projectPath = [[self fileURL] path];
166+
167+
if ([[projectPath lastPathComponent] isEqualToString:@".git"])
168+
projectPath = [projectPath stringByDeletingLastPathComponent];
167169

168-
return displayName;
170+
return [projectPath lastPathComponent];
169171
}
170172

171173
// Get the .gitignore file at the root of the repository

0 commit comments

Comments
 (0)