From 12faa4a8f067ffdad0126888c808bf9b8a170a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20Walsh?= Date: Mon, 18 Aug 2008 22:13:51 +0100 Subject: [PATCH] Avoid showing .git dirs in the recent documents menu. Instead (for non-bare repos) add the directory above the .git dir. --- PBGitRepository.h | 2 ++ PBGitRepository.m | 14 ++++++++++++++ PBRepositoryDocumentController.m | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/PBGitRepository.h b/PBGitRepository.h index 2df0beb..22af9a5 100644 --- a/PBGitRepository.h +++ b/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; diff --git a/PBGitRepository.m b/PBGitRepository.m index bf73ad8..fc7b66f 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -76,6 +76,20 @@ static NSString* gitPath; 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; diff --git a/PBRepositoryDocumentController.m b/PBRepositoryDocumentController.m index b4d8a45..c29f37d 100644 --- a/PBRepositoryDocumentController.m +++ b/PBRepositoryDocumentController.m @@ -24,4 +24,9 @@ { return [super documentForURL:[PBGitRepository gitDirForURL:URL]]; } + +- (void)noteNewRecentDocumentURL:(NSURL*)url +{ + [super noteNewRecentDocumentURL:[PBGitRepository baseDirForURL:url]]; +} @end