Skip to content

Commit 52b587a

Browse files
committed
Merge pull request brotherbard#52 from darconeous/error-on-repo-open-fix
Error on repo open fix
2 parents f463153 + f2fc162 commit 52b587a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

PBGitRepository.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ + (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
118118
//this works much better.
119119
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
120120
{
121+
@try {
121122
if (![PBGitBinary path])
122123
{
123124
if (outError) {
@@ -153,6 +154,14 @@ - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSEr
153154
[self setFileURL:gitDirURL];
154155
[self setup];
155156
return YES;
157+
} @catch(id x) {
158+
if (outError) {
159+
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"An error occured while trying to open %@.\n%@", [self fileURL],x]
160+
forKey:NSLocalizedRecoverySuggestionErrorKey];
161+
*outError = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
162+
}
163+
return NO;
164+
}
156165
}
157166

158167
- (void) setup
@@ -271,6 +280,11 @@ - (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components
271280
else
272281
sha = [PBGitSHA shaWithString:[components objectAtIndex:2]];
273282

283+
if(!sha) {
284+
NSLog(@"sha was nil...? ref=%@, components=%@",ref,components);
285+
return;
286+
}
287+
274288
NSMutableArray* curRefs;
275289
if ( (curRefs = [refs objectForKey:sha]) != nil )
276290
[curRefs addObject:ref];
@@ -290,6 +304,13 @@ - (void) reloadRefs
290304
NSString *output = [self outputForArguments:arguments];
291305
NSArray *lines = [output componentsSeparatedByString:@"\n"];
292306

307+
if([output hasPrefix:@"fatal: "]) {
308+
NSLog(@"Unable to read refs!");
309+
NSLog(@"arguments=%@",arguments);
310+
NSLog(@"output=%@",output);
311+
@throw output;
312+
}
313+
293314
for (NSString *line in lines) {
294315
// If its an empty line, skip it (e.g. with empty repositories)
295316
if ([line length] == 0)

0 commit comments

Comments
 (0)