mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Merge branch 'pu/pb/git_version'
* pu/pb/git_version: cli-tool: Hint at another error if there is a git binary Move CLI files to cli group GitBinary: Add git version information gitx-cli: add a --version option
This commit is contained in:
@@ -322,6 +322,8 @@
|
||||
913D5E420E5563FD00CECEA2 /* cli */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
913D5E5D0E556A9300CECEA2 /* PBCLIProxy.h */,
|
||||
913D5E5E0E556A9300CECEA2 /* PBCLIProxy.mm */,
|
||||
913D5E440E55640C00CECEA2 /* gitx.mm */,
|
||||
);
|
||||
name = cli;
|
||||
@@ -351,8 +353,6 @@
|
||||
F57CC4400E05E496000472E2 /* PBGitWindowController.m */,
|
||||
911111F60E594F3F00BF76B4 /* PBRepositoryDocumentController.h */,
|
||||
911111F70E594F3F00BF76B4 /* PBRepositoryDocumentController.m */,
|
||||
913D5E5D0E556A9300CECEA2 /* PBCLIProxy.h */,
|
||||
913D5E5E0E556A9300CECEA2 /* PBCLIProxy.mm */,
|
||||
F5E926040E8827D300056E75 /* PBViewController.h */,
|
||||
F5EF8C8C0E9D4A5D0050906B /* PBWebController.h */,
|
||||
F5E926050E8827D300056E75 /* PBViewController.m */,
|
||||
|
||||
+6
-1
@@ -11,6 +11,7 @@
|
||||
#import "PBGitRevSpecifier.h"
|
||||
#import "PBGitRepository.h"
|
||||
#import "PBGitWindowController.h"
|
||||
#import "PBGitBinary.h"
|
||||
|
||||
@implementation PBCLIProxy
|
||||
@synthesize connection;
|
||||
@@ -39,7 +40,11 @@
|
||||
PBGitRepository *document = [[PBRepositoryDocumentController sharedDocumentController] documentForLocation:url];
|
||||
if (!document) {
|
||||
if (error) {
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"Could not create document. Perhaps GitX can't find you git binary?" forKey:NSLocalizedFailureReasonErrorKey];
|
||||
NSString *suggestion = [PBGitBinary path] ? @"this isn't a git repository" : @"GitX can't find your git binary";
|
||||
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Could not create document. Perhaps %@", suggestion]
|
||||
forKey:NSLocalizedFailureReasonErrorKey];
|
||||
|
||||
*error = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:2 userInfo:userInfo];
|
||||
}
|
||||
return NO;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
}
|
||||
|
||||
+ (NSString *) path;
|
||||
+ (NSString *) version;
|
||||
+ (NSArray *) searchLocations;
|
||||
+ (NSString *) notFoundError;
|
||||
@end
|
||||
|
||||
+48
-13
@@ -11,33 +11,61 @@
|
||||
|
||||
@implementation PBGitBinary
|
||||
|
||||
static NSString* gitPath;
|
||||
static NSString* gitPath = nil;
|
||||
|
||||
+ (NSString *)versionForPath:(NSString *)path
|
||||
{
|
||||
if (!path)
|
||||
return nil;
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:path])
|
||||
return nil;
|
||||
|
||||
NSString *version = [PBEasyPipe outputForCommand:path withArgs:[NSArray arrayWithObject:@"--version"]];
|
||||
if ([version hasPrefix:@"git version "])
|
||||
return [version substringFromIndex:12];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (BOOL) acceptBinary:(NSString *)path
|
||||
{
|
||||
if (!path)
|
||||
return NO;
|
||||
|
||||
NSString *version = [self versionForPath:path];
|
||||
if (!version)
|
||||
return NO;
|
||||
|
||||
int c = [version compare:@"1.5.4"];
|
||||
if (c == NSOrderedSame || c == NSOrderedDescending) {
|
||||
gitPath = path;
|
||||
return YES;
|
||||
}
|
||||
|
||||
NSLog(@"Found a git binary at %@, but is only version %@", path, version);
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
gitPath = nil;
|
||||
|
||||
// Try to find the path of the Git binary
|
||||
char* path = getenv("GIT_PATH");
|
||||
if (path != nil) {
|
||||
gitPath = [NSString stringWithCString:path];
|
||||
if (path && [self acceptBinary:[NSString stringWithCString:path]])
|
||||
return;
|
||||
}
|
||||
|
||||
// No explicit path. Try it with "which"
|
||||
gitPath = [PBEasyPipe outputForCommand:@"/usr/bin/which" withArgs:[NSArray arrayWithObject:@"git"]];
|
||||
if (gitPath.length > 0)
|
||||
NSString *whichPath = [PBEasyPipe outputForCommand:@"/usr/bin/which" withArgs:[NSArray arrayWithObject:@"git"]];
|
||||
if ([self acceptBinary:whichPath])
|
||||
return;
|
||||
|
||||
// Still no path. Let's try some default locations.
|
||||
for (NSString* location in [PBGitBinary searchLocations]) {
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:location]) {
|
||||
gitPath = location;
|
||||
if ([self acceptBinary:location])
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
NSLog(@"Could not find a git binary!");
|
||||
NSLog(@"Could not find a git binary higher than version 1.5.4.");
|
||||
}
|
||||
|
||||
+ (NSString *) path;
|
||||
@@ -66,7 +94,7 @@ static NSMutableArray *locations = nil;
|
||||
+ (NSString *) notFoundError
|
||||
{
|
||||
NSMutableString *error = [NSMutableString stringWithString:
|
||||
@"Could not find a git binary\n"
|
||||
@"Could not find a git binary version 1.5.4 or higher.\n"
|
||||
"Please make sure there is a git binary in one of the following locations:\n\n"];
|
||||
for (NSString *location in [PBGitBinary searchLocations]) {
|
||||
[error appendFormat:@"\t%@\n", location];
|
||||
@@ -74,4 +102,11 @@ static NSMutableArray *locations = nil;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
+ (NSString *)version
|
||||
{
|
||||
return [self versionForPath:gitPath];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -19,7 +19,7 @@ NSDistantObject* connect()
|
||||
void usage(char const *programName)
|
||||
{
|
||||
|
||||
printf("Usage: %s --help\n", programName);
|
||||
printf("Usage: %s (--help|--version)\n", programName);
|
||||
printf(" or: %s (--commit|-h)\n", programName);
|
||||
printf(" or: %s <revlist options>\n", programName);
|
||||
printf("\n");
|
||||
@@ -35,10 +35,23 @@ void usage(char const *programName)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void version_info()
|
||||
{
|
||||
NSString *version = [[[NSBundle bundleForClass:[PBGitBinary class]] infoDictionary] valueForKey:@"CFBundleVersion"];
|
||||
printf("This is GitX version %s\n", [version UTF8String]);
|
||||
if ([PBGitBinary path])
|
||||
printf("Using git found at %s, version %s\n", [[PBGitBinary path] UTF8String], [[PBGitBinary version] UTF8String]);
|
||||
else
|
||||
printf("GitX cannot find a git binary\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
if (argc >= 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")))
|
||||
usage(argv[0]);
|
||||
if (argc >= 2 && (!strcmp(argv[1], "--version") || !strcmp(argv[1], "-v")))
|
||||
version_info();
|
||||
|
||||
if (![PBGitBinary path]) {
|
||||
printf("%s\n", [[PBGitBinary notFoundError] cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
|
||||
Reference in New Issue
Block a user