Permalink
Browse files

Making the path determination a bit more reliable.

  • Loading branch information...
1 parent b549b63 commit 5157b4a1ce2a3b3ebbe426d81b8f47e070986e4e @wooster committed Jul 9, 2011
Showing with 32 additions and 9 deletions.
  1. +3 −3 .git-gps
  2. +29 −6 git-gps/source/GGGitTool.m
View
@@ -1,7 +1,7 @@
{
- "latitude":45.782119,
- "longitude":-108.505189,
+ "latitude":45.782069,
+ "longitude":-108.505118,
"altitude":0.000000,
- "horizontalAccuracy":157.000000,
+ "horizontalAccuracy":167.000000,
"verticalAccuracy":-1.000000
}
View
@@ -61,6 +61,16 @@ - (NSString *)determineGitPath {
NSString *path = [self runTaskAndGatherOutput:task];
[task release], task = nil;
path = [path stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
+
+ NSFileManager *fm = [NSFileManager defaultManager];
+ NSArray *paths = [NSArray arrayWithObjects:path, @"/usr/bin/git", @"/usr/local/bin/git", nil];
+ for (NSString *tmpPath in paths) {
+ if ([fm isExecutableFileAtPath:tmpPath]) {
+ path = tmpPath;
+ break;
+ }
+ }
+
return path;
}
@@ -76,13 +86,26 @@ - (NSString *)runTaskAndGatherOutput:(NSTask *)task {
}
- (NSString *)runGitCommandAndGatherOutput:(NSArray *)arguments {
+ NSString *result = nil;
+
NSTask *task = [[NSTask alloc] init];
- [task setLaunchPath:gitPath];
- [task setArguments:arguments];
- NSString *result = [self runTaskAndGatherOutput:task];
- result = [result stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
- terminationStatus = [task terminationStatus];
- [task release], task = nil;
+
+ @try {
+ [task setLaunchPath:gitPath];
+ [task setArguments:arguments];
+ result = [self runTaskAndGatherOutput:task];
+ result = [result stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
+ terminationStatus = [task terminationStatus];
+ }
+ @catch (NSException * e) {
+ NSLog(@"Exception running task: %@", e);
+ NSLog(@"git path was: '%@'", gitPath);
+ NSLog(@"arguments were: %@", arguments);
+ @throw(e);
+ }
+ @finally {
+ [task release], task = nil;
+ }
return result;
}
@end

0 comments on commit 5157b4a

Please sign in to comment.