Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashes when opening Submodules. #209

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions PBGitRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just copypasted this from line 169 -readFromURL:ofType:error:

[self addWindowController:[[PBGitWindowController alloc] initWithRepository:self displayDefault:NO]];
#endif

Expand Down Expand Up @@ -926,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;
Expand Down