From 0e9608dab17c49d43b9347c25bfd33230d63c1b5 Mon Sep 17 00:00:00 2001 From: Stepan Generalov Date: Sun, 30 Sep 2012 22:04:08 +0400 Subject: [PATCH 1/2] PBGitRepository: ensure to have workingDirectory in -initWithURL: to fix crashes in PBGitCommitController. I had these crashes only when opening Submodules, didn't try to find why though. --- PBGitRepository.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PBGitRepository.m b/PBGitRepository.m index 1738766ef..23d7b8d37 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -219,6 +219,9 @@ - (id) initWithURL: (NSURL*) path // We don't want the window controller to display anything yet.. // We'll leave that to the caller of this method. #ifndef CLI + if (![self workingDirectory]) { // If we couldn't find the working directory, assume it's the place we were opened from. + workingDirectory = [[path absoluteURL] path]; + } [self addWindowController:[[PBGitWindowController alloc] initWithRepository:self displayDefault:NO]]; #endif From e034e5a18780bfb10bcfe2c29012a24859ce2ccf Mon Sep 17 00:00:00 2001 From: Stepan Generalov Date: Sun, 30 Sep 2012 23:08:10 +0400 Subject: [PATCH 2/2] PBGitRepository: add explicit module detection in -workingDirectory. --- PBGitRepository.m | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/PBGitRepository.m b/PBGitRepository.m index 23d7b8d37..76512d9d5 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -929,8 +929,19 @@ - (NSString *) workingDirectory if(!workingDirectory) { if ([self.fileURL.path hasSuffix:@"/.git"]) workingDirectory = [self.fileURL.path substringToIndex:[self.fileURL.path length] - 5]; - else if ([[self outputForCommand:@"rev-parse --is-inside-work-tree"] isEqualToString:@"true"]) - workingDirectory = [PBGitBinary path]; + else { + NSRange range = [self.fileURL.path rangeOfString: @"/.git/modules/"]; + if (range.location != NSNotFound) { + NSString *relativeModulePath = [self.fileURL.path substringFromIndex: range.location + range.length ]; + NSString *supermodulePath = [self.fileURL.path substringToIndex: range.location]; + workingDirectory = [supermodulePath stringByAppendingPathComponent: relativeModulePath]; + } + else if ([[self outputForCommand:@"rev-parse --is-inside-work-tree"] isEqualToString:@"true"]) + workingDirectory = [PBGitBinary path]; + else + workingDirectory = self.fileURL.path; + } + } return workingDirectory;