Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 70 lines (57 sloc) 1.509 kb
8c96979 @pieter Better handle the cases when a Git binary can't be found
pieter authored
1 //
2 // PBGitBinary.m
3 // GitX
4 //
5 // Created by Pieter de Bie on 04-10-08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "PBGitBinary.h"
10 #import "PBEasyPipe.h"
11
12 @implementation PBGitBinary
13
14 static NSString* gitPath;
15
16 + (void) initialize
17 {
18 gitPath = nil;
19
20 // Try to find the path of the Git binary
21 char* path = getenv("GIT_PATH");
22 if (path != nil) {
23 gitPath = [NSString stringWithCString:path];
24 return;
25 }
26
27 // No explicit path. Try it with "which"
28 gitPath = [PBEasyPipe outputForCommand:@"/usr/bin/which" withArgs:[NSArray arrayWithObject:@"git"]];
29 if (gitPath.length > 0)
30 return;
31
32 // Still no path. Let's try some default locations.
33 for (NSString* location in [PBGitBinary searchLocations]) {
34 if ([[NSFileManager defaultManager] fileExistsAtPath:location]) {
35 gitPath = location;
36 return;
37 }
38 }
39
40 NSLog(@"Could not find a git binary!");
41 }
42
43 + (NSString *) path;
44 {
45 return gitPath;
46 }
47
48 + (NSArray *) searchLocations
49 {
50 NSArray* locations = [NSArray arrayWithObjects:@"/opt/local/bin/git",
51 @"/sw/bin/git",
52 @"/opt/git/bin/git",
53 @"/usr/local/bin/git",
54 nil];
55 return locations;
56 }
57
58 + (NSString *) notFoundError
59 {
60 NSMutableString *error = [NSMutableString stringWithString:
61 @"Could not find a git binary\n"
62 "Please make sure there is a git binary in one of the following locations:\n\n"];
63 for (NSString *location in [PBGitBinary searchLocations]) {
64 [error appendFormat:@"\t%@\n", location];
65 }
66 return error;
67 }
68
69 @end
Something went wrong with that request. Please try again.