Permalink
Browse files

Avoid showing .git dirs in the recent documents menu.

Instead (for non-bare repos) add the directory above the .git dir.
  • Loading branch information...
1 parent d320a4b commit 12faa4a8f067ffdad0126888c808bf9b8a170a45 @ciaran ciaran committed with Aug 18, 2008
Showing with 21 additions and 0 deletions.
  1. +2 −0 PBGitRepository.h
  2. +14 −0 PBGitRepository.m
  3. +5 −0 PBRepositoryDocumentController.m
View
2 PBGitRepository.h
@@ -29,6 +29,8 @@ extern NSString* PBGitRepositoryErrorDomain;
- (NSString*) parseReference:(NSString*) ref;
+ (NSURL*)gitDirForURL:(NSURL*)repositoryURL;
++ (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
+
@property (readonly) PBGitRevList* revisionList;
@property (assign) NSArray* branches;
@property (assign) NSString* currentBranch;
View
14 PBGitRepository.m
@@ -76,6 +76,20 @@ + (NSURL*)gitDirForURL:(NSURL*)repositoryURL;
return gitDirURL;
}
+// For a given path inside a repository, return either the .git dir
+// (for a bare repo) or the directory above the .git dir otherwise
++ (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
+{
+ NSURL* gitDirURL = [self gitDirForURL:repositoryURL];
+ NSString* repositoryPath = [gitDirURL path];
+
+ if (![[PBEasyPipe outputForCommand:gitPath withArgs:[NSArray arrayWithObjects:@"rev-parse", @"--is-bare-repository", nil] inDir:repositoryPath] isEqualToString:@"true"]) {
+ repositoryURL = [NSURL fileURLWithPath:[[repositoryURL path] stringByDeletingLastPathComponent]];
+ }
+
+ return repositoryURL;
+}
+
- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError
{
BOOL success = NO;
View
5 PBRepositoryDocumentController.m
@@ -24,4 +24,9 @@ - (id)documentForURL:(NSURL *)URL
{
return [super documentForURL:[PBGitRepository gitDirForURL:URL]];
}
+
+- (void)noteNewRecentDocumentURL:(NSURL*)url
+{
+ [super noteNewRecentDocumentURL:[PBGitRepository baseDirForURL:url]];
+}
@end

0 comments on commit 12faa4a

Please sign in to comment.