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