5 // Created by Pieter de Bie on 04-10-08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
9 #import "PBGitBinary.h"
10 #import "PBEasyPipe.h"
12 @implementation PBGitBinary
14 static NSString* gitPath;
20 // Try to find the path of the Git binary
21 char* path = getenv("GIT_PATH");
23 gitPath = [NSString stringWithCString:path];
27 // No explicit path. Try it with "which"
28 gitPath = [PBEasyPipe outputForCommand:@"/usr/bin/which" withArgs:[NSArray arrayWithObject:@"git"]];
29 if (gitPath.length > 0)
32 // Still no path. Let's try some default locations.
33 for (NSString* location in [PBGitBinary searchLocations]) {
34 if ([[NSFileManager defaultManager] fileExistsAtPath:location]) {
40 NSLog(@"Could not find a git binary!");
48 static NSMutableArray *locations = nil;
50 + (NSArray *) searchLocations
55 locations = [NSMutableArray arrayWithObjects:@"/opt/local/bin/git",
58 @"/usr/local/bin/git",
59 @"/usr/local/git/bin/git",
62 [locations addObject:[@"~/bin/git" stringByExpandingTildeInPath]];
66 + (NSString *) notFoundError
68 NSMutableString *error = [NSMutableString stringWithString:
69 @"Could not find a git binary\n"
70 "Please make sure there is a git binary in one of the following locations:\n\n"];
71 for (NSString *location in [PBGitBinary searchLocations]) {
72 [error appendFormat:@"\t%@\n", location];